Simple Displacement FX Debug.shader 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Shader "Lux SRP Displacement/Simple Displacement Debug"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "bump" {}
  6. [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend mode", Float) = 5
  7. [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend mode", Float) = 10
  8. }
  9. SubShader
  10. {
  11. Tags { "RenderType"="Transparent" "Queue"="Transparent" "RenderPipeline" = "UniversalPipeline" }
  12. ZWrite Off
  13. Blend [_SrcBlend] [_DstBlend]
  14. LOD 100
  15. Pass
  16. {
  17. Name "LuxGrassDisplacementFX"
  18. Tags{"LightMode" = "LuxGrassDisplacementFX"}
  19. HLSLPROGRAM
  20. #pragma vertex SimpleDisplacementFXVertex
  21. #pragma fragment SimpleDisplacementFXFragment
  22. #pragma shader_feature_local _DYNAMICALPHA
  23. #pragma shader_feature_local _NORMAL
  24. //--------------------------------------
  25. // GPU Instancing
  26. #pragma multi_compile_instancing
  27. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  28. struct Attributes
  29. {
  30. float3 positionOS : POSITION;
  31. #if defined _NORMAL
  32. float3 normalOS : NORMAL;
  33. float4 tangentOS : TANGENT;
  34. #endif
  35. half4 color : COLOR;
  36. float2 uv : TEXCOORD0;
  37. };
  38. struct Varyings
  39. {
  40. float2 uv : TEXCOORD0;
  41. #if defined _NORMAL
  42. half3 normalWS : TEXCOORD1;
  43. half3 tangentWS : TEXCOORD2;
  44. half3 bitangentWS : TEXCOORD3;
  45. #endif
  46. half4 color : TEXCOORD4;
  47. float4 vertex : SV_POSITION;
  48. };
  49. CBUFFER_START(UnityPerMaterial)
  50. //half _Alpha;
  51. CBUFFER_END
  52. #if defined (_DYNAMICALPHA)
  53. UNITY_INSTANCING_BUFFER_START(Props)
  54. UNITY_DEFINE_INSTANCED_PROP(half, _Alpha)
  55. UNITY_INSTANCING_BUFFER_END(Props)
  56. #endif
  57. sampler2D _MainTex;
  58. Varyings SimpleDisplacementFXVertex (Attributes input)
  59. {
  60. Varyings output = (Varyings)0;
  61. VertexPositionInputs vertexPosition = GetVertexPositionInputs(input.positionOS.xyz);
  62. output.vertex = vertexPosition.positionCS;
  63. output.uv = input.uv;
  64. output.color = input.color;
  65. #if defined _NORMAL
  66. VertexNormalInputs vertexTBN = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  67. output.normalWS = vertexTBN.normalWS;
  68. output.tangentWS = vertexTBN.tangentWS;
  69. output.bitangentWS = vertexTBN.bitangentWS;
  70. #endif
  71. return output;
  72. }
  73. half4 SimpleDisplacementFXFragment (Varyings input) : SV_Target
  74. {
  75. half4 col = tex2D(_MainTex, input.uv);
  76. col.a *= input.color.a
  77. #if defined(_DYNAMICALPHA)
  78. * UNITY_ACCESS_INSTANCED_PROP(Props, _Alpha)
  79. #endif
  80. ;
  81. #if defined(_NORMAL)
  82. col.rgb = col.rgb * 2 - 1; // unpack
  83. col.rgb = TransformTangentToWorld(col.rgb, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
  84. col.rgb = col.rbg * 0.5 + 0.5; // swizzle to "tangent space" and repack
  85. #endif
  86. return col;
  87. }
  88. ENDHLSL
  89. }
  90. Pass
  91. {
  92. Tags{"LightMode" = "LightweightForward"}
  93. HLSLPROGRAM
  94. #pragma vertex SimpleDisplacementFXVertex
  95. #pragma fragment SimpleDisplacementFXFragment
  96. #pragma shader_feature_local _DYNAMICALPHA
  97. #pragma shader_feature_local _NORMAL
  98. //--------------------------------------
  99. // GPU Instancing
  100. #pragma multi_compile_instancing
  101. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  102. struct Attributes
  103. {
  104. float3 positionOS : POSITION;
  105. #if defined _NORMAL
  106. float3 normalOS : NORMAL;
  107. float4 tangentOS : TANGENT;
  108. #endif
  109. half4 color : COLOR;
  110. float2 uv : TEXCOORD0;
  111. };
  112. struct Varyings
  113. {
  114. float2 uv : TEXCOORD0;
  115. #if defined _NORMAL
  116. half3 normalWS : TEXCOORD1;
  117. half3 tangentWS : TEXCOORD2;
  118. half3 bitangentWS : TEXCOORD3;
  119. #endif
  120. half4 color : TEXCOORD4;
  121. float4 vertex : SV_POSITION;
  122. };
  123. CBUFFER_START(UnityPerMaterial)
  124. //half _Alpha;
  125. CBUFFER_END
  126. #if defined (_DYNAMICALPHA)
  127. UNITY_INSTANCING_BUFFER_START(Props)
  128. UNITY_DEFINE_INSTANCED_PROP(half, _Alpha)
  129. UNITY_INSTANCING_BUFFER_END(Props)
  130. #endif
  131. sampler2D _MainTex;
  132. Varyings SimpleDisplacementFXVertex (Attributes input)
  133. {
  134. Varyings output = (Varyings)0;
  135. VertexPositionInputs vertexPosition = GetVertexPositionInputs(input.positionOS.xyz);
  136. output.vertex = vertexPosition.positionCS;
  137. output.uv = input.uv;
  138. output.color = input.color;
  139. #if defined _NORMAL
  140. VertexNormalInputs vertexTBN = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  141. output.normalWS = vertexTBN.normalWS;
  142. output.tangentWS = vertexTBN.tangentWS;
  143. output.bitangentWS = vertexTBN.bitangentWS;
  144. #endif
  145. return output;
  146. }
  147. half4 SimpleDisplacementFXFragment (Varyings input) : SV_Target
  148. {
  149. half4 col = tex2D(_MainTex, input.uv);
  150. col.a *= input.color.a
  151. #if defined(_DYNAMICALPHA)
  152. * UNITY_ACCESS_INSTANCED_PROP(Props, _Alpha)
  153. #endif
  154. ;
  155. #if defined(_NORMAL)
  156. col.rgb = col.rgb * 2 - 1; // unpack
  157. col.rgb = TransformTangentToWorld(col.rgb, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
  158. col.rgb = col.rbg * 0.5 + 0.5; // swizzle to "tangent space" and repack
  159. #endif
  160. return col;
  161. }
  162. ENDHLSL
  163. }
  164. }
  165. }