|
| 1 | +Shader "Instanced/#NAME#" |
| 2 | +{ |
| 3 | + Properties |
| 4 | + { |
| 5 | + _Color ("Color", Color) = (1,1,1,1) |
| 6 | + _MainTex ("Albedo (RGB)", 2D) = "white" {} |
| 7 | + _Glossiness ("Smoothness", Range(0,1)) = 0.5 |
| 8 | + _Metallic ("Metallic", Range(0,1)) = 0.0 |
| 9 | + } |
| 10 | + SubShader |
| 11 | + { |
| 12 | + Tags |
| 13 | + { |
| 14 | + "RenderType"="Opaque" |
| 15 | + } |
| 16 | + LOD 200 |
| 17 | + |
| 18 | + CGPROGRAM |
| 19 | + #pragma surface surf Standard fullforwardshadows addshadow |
| 20 | + #pragma target 3.0 |
| 21 | + |
| 22 | + // Enable instancing for this shader |
| 23 | + #pragma multi_compile_instancing |
| 24 | + |
| 25 | + // Config maxcount. See manual page. |
| 26 | + // #pragma instancing_options |
| 27 | + |
| 28 | + struct Input |
| 29 | + { |
| 30 | + float2 uv_MainTex; |
| 31 | + }; |
| 32 | + |
| 33 | + sampler2D _MainTex; |
| 34 | + half _Glossiness; |
| 35 | + half _Metallic; |
| 36 | + |
| 37 | + // Declare instanced properties inside a cbuffer. |
| 38 | + // Each instanced property is an array of by default 500(D3D)/128(GL) elements. Since D3D and GL imposes a certain limitation |
| 39 | + // of 64KB and 16KB respectively on the size of a cubffer, the default array size thus allows two matrix arrays in one cbuffer. |
| 40 | + // Use maxcount option on #pragma instancing_options directive to specify array size other than default (divided by 4 when used |
| 41 | + // for GL). |
| 42 | + UNITY_INSTANCING_CBUFFER_START(Props) |
| 43 | + UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color) // Make _Color an instanced property (i.e. an array) |
| 44 | + UNITY_INSTANCING_CBUFFER_END |
| 45 | + |
| 46 | + void surf (Input IN, inout SurfaceOutputStandard o) |
| 47 | + { |
| 48 | + o.Metallic = _Metallic; |
| 49 | + o.Smoothness = _Glossiness; |
| 50 | + |
| 51 | + fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * UNITY_ACCESS_INSTANCED_PROP(_Color); |
| 52 | + o.Albedo = c.rgb; |
| 53 | + o.Alpha = c.a; |
| 54 | + } |
| 55 | + ENDCG |
| 56 | + } |
| 57 | + FallBack "Diffuse" |
| 58 | +} |
0 commit comments