Skip to content

Commit

Permalink
Add GPU instancing support on HAP shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Mar 1, 2019
1 parent edda793 commit 5e70d3a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 36 deletions.
35 changes: 23 additions & 12 deletions Assets/Klak/Hap/Resources/Hap1.shader
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,35 @@ Shader "Klak/HAP"

#include "UnityCG.cginc"

struct Attributes
{
float4 position : POSITION;
float2 texcoord : TEXCOORD;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct Varyings
{
float4 position : SV_Position;
float2 texcoord : TEXCOORD;
};

sampler2D _MainTex;
float4 _MainTex_ST;

float4 Vertex(
float4 position : POSITION,
inout float2 texcoord : TEXCOORD
) : SV_Position
Varyings Vertex(Attributes input)
{
texcoord = TRANSFORM_TEX(texcoord, _MainTex);
texcoord.y = 1 - texcoord.y;
return UnityObjectToClipPos(position);
UNITY_SETUP_INSTANCE_ID(input);
Varyings output;
output.position = UnityObjectToClipPos(input.position);
output.texcoord = TRANSFORM_TEX(input.texcoord, _MainTex);
output.texcoord.y = 1 - output.texcoord.y;
return output;
}

fixed4 Fragment(
float4 position : POSITION,
float2 texcoord : TEXCOORD
) : SV_Target
fixed4 Fragment(Varyings input) : SV_Target
{
return tex2D(_MainTex, texcoord);
return tex2D(_MainTex, input.texcoord);
}

ENDCG
Expand All @@ -40,6 +50,7 @@ Shader "Klak/HAP"
CGPROGRAM
#pragma vertex Vertex
#pragma fragment Fragment
#pragma multi_compile_instancing
ENDCG
}
}
Expand Down
35 changes: 23 additions & 12 deletions Assets/Klak/Hap/Resources/Hap5.shader
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,35 @@ Shader "Klak/HAP Alpha"

#include "UnityCG.cginc"

struct Attributes
{
float4 position : POSITION;
float2 texcoord : TEXCOORD;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct Varyings
{
float4 position : SV_Position;
float2 texcoord : TEXCOORD;
};

sampler2D _MainTex;
float4 _MainTex_ST;

float4 Vertex(
float4 position : POSITION,
inout float2 texcoord : TEXCOORD
) : SV_Position
Varyings Vertex(Attributes input)
{
texcoord = TRANSFORM_TEX(texcoord, _MainTex);
texcoord.y = 1 - texcoord.y;
return UnityObjectToClipPos(position);
UNITY_SETUP_INSTANCE_ID(input);
Varyings output;
output.position = UnityObjectToClipPos(input.position);
output.texcoord = TRANSFORM_TEX(input.texcoord, _MainTex);
output.texcoord.y = 1 - output.texcoord.y;
return output;
}

fixed4 Fragment(
float4 position : POSITION,
float2 texcoord : TEXCOORD
) : SV_Target
fixed4 Fragment(Varyings input) : SV_Target
{
return tex2D(_MainTex, texcoord);
return tex2D(_MainTex, input.texcoord);
}

ENDCG
Expand All @@ -42,6 +52,7 @@ Shader "Klak/HAP Alpha"
CGPROGRAM
#pragma vertex Vertex
#pragma fragment Fragment
#pragma multi_compile_instancing
ENDCG
}
}
Expand Down
35 changes: 23 additions & 12 deletions Assets/Klak/Hap/Resources/HapY.shader
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ Shader "Klak/HAP Q"

#include "UnityCG.cginc"

struct Attributes
{
float4 position : POSITION;
float2 texcoord : TEXCOORD;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct Varyings
{
float4 position : SV_Position;
float2 texcoord : TEXCOORD;
};

sampler2D _MainTex;
float4 _MainTex_ST;

Expand All @@ -26,22 +39,19 @@ Shader "Klak/HAP Q"
return rgb;
}

float4 Vertex(
float4 position : POSITION,
inout float2 texcoord : TEXCOORD
) : SV_Position
Varyings Vertex(Attributes input)
{
texcoord = TRANSFORM_TEX(texcoord, _MainTex);
texcoord.y = 1 - texcoord.y;
return UnityObjectToClipPos(position);
UNITY_SETUP_INSTANCE_ID(input);
Varyings output;
output.position = UnityObjectToClipPos(input.position);
output.texcoord = TRANSFORM_TEX(input.texcoord, _MainTex);
output.texcoord.y = 1 - output.texcoord.y;
return output;
}

fixed4 Fragment(
float4 position : POSITION,
float2 texcoord : TEXCOORD
) : SV_Target
fixed4 Fragment(Varyings input) : SV_Target
{
return fixed4(CoCgSY2RGB(tex2D(_MainTex, texcoord)), 1);
return fixed4(CoCgSY2RGB(tex2D(_MainTex, input.texcoord)), 1);
}

ENDCG
Expand All @@ -55,6 +65,7 @@ Shader "Klak/HAP Q"
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
#pragma vertex Vertex
#pragma fragment Fragment
#pragma multi_compile_instancing
ENDCG
}
}
Expand Down

0 comments on commit 5e70d3a

Please sign in to comment.