Skip to content

Instantly share code, notes, and snippets.

@ogrew
Last active May 13, 2022 15:57
Show Gist options
  • Save ogrew/974db999eaab0440c32cc973b9842925 to your computer and use it in GitHub Desktop.
Save ogrew/974db999eaab0440c32cc973b9842925 to your computer and use it in GitHub Desktop.
DrawMeshInstancedを試す_Shader(その1)
Shader "Custom/InstancedColor"
{
SubShader
{
CGINCLUDE
#include "UnityCG.cginc"
ENDCG
Pass
{
Tags { "RenderType" = "Opaque"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
};
float4 _Colors[1023]; // Max instanced batch size.
v2f vert(appdata_full v, uint instanceID: SV_InstanceID) {
v2f o;
UNITY_SETUP_INSTANCE_ID(v)
o.pos = UnityObjectToClipPos(v.vertex);
o.color = _Colors[instanceID];
return o;
}
fixed4 frag(v2f i) : SV_Target {
return i.color;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment