InstancedColored.shader 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. Shader "Nreal/Instanced-Colored"
  2. {
  3. Properties
  4. {
  5. _Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
  6. _ZWrite("ZWrite", Int) = 1.0 // On
  7. [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest", Int) = 4.0 // LEqual
  8. [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull", Int) = 0.0 // Off
  9. }
  10. SubShader
  11. {
  12. Pass
  13. {
  14. Name "Main"
  15. Tags{ "RenderType" = "Opaque" }
  16. ZWrite[_ZWrite]
  17. ZTest[_ZTest]
  18. Cull[_Cull]
  19. CGPROGRAM
  20. //#if defined(SHADER_API_D3D11)
  21. // #pragma target 5.0
  22. //#endif
  23. #pragma vertex vert
  24. #pragma fragment frag
  25. #pragma multi_compile_instancing
  26. #include "UnityCG.cginc"
  27. struct appdata_t
  28. {
  29. fixed4 vertex : POSITION;
  30. UNITY_VERTEX_INPUT_INSTANCE_ID
  31. };
  32. struct v2f
  33. {
  34. fixed4 vertex : SV_POSITION;
  35. fixed4 color : COLOR0;
  36. UNITY_VERTEX_OUTPUT_STEREO
  37. };
  38. float4x4 _ParentLocalToWorldMatrix;
  39. UNITY_INSTANCING_BUFFER_START(Props)
  40. UNITY_DEFINE_INSTANCED_PROP(float4, _Color)
  41. UNITY_INSTANCING_BUFFER_END(Props)
  42. v2f vert(appdata_t v)
  43. {
  44. v2f o;
  45. UNITY_SETUP_INSTANCE_ID(v);
  46. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  47. o.vertex = mul(UNITY_MATRIX_VP, mul(_ParentLocalToWorldMatrix, mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1.0))));
  48. o.color = UNITY_ACCESS_INSTANCED_PROP(Props, _Color);
  49. return o;
  50. }
  51. fixed4 frag(v2f i) : SV_Target
  52. {
  53. return i.color;
  54. }
  55. ENDCG
  56. }
  57. }
  58. }