123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- Shader "Lux SRP Displacement/Simple Displacement Debug"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "bump" {}
- [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend mode", Float) = 5
- [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend mode", Float) = 10
- }
- SubShader
- {
- Tags { "RenderType"="Transparent" "Queue"="Transparent" "RenderPipeline" = "UniversalPipeline" }
- ZWrite Off
- Blend [_SrcBlend] [_DstBlend]
- LOD 100
- Pass
- {
- Name "LuxGrassDisplacementFX"
- Tags{"LightMode" = "LuxGrassDisplacementFX"}
-
- HLSLPROGRAM
- #pragma vertex SimpleDisplacementFXVertex
- #pragma fragment SimpleDisplacementFXFragment
- #pragma shader_feature_local _DYNAMICALPHA
- #pragma shader_feature_local _NORMAL
- //--------------------------------------
- // GPU Instancing
- #pragma multi_compile_instancing
-
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- struct Attributes
- {
- float3 positionOS : POSITION;
- #if defined _NORMAL
- float3 normalOS : NORMAL;
- float4 tangentOS : TANGENT;
- #endif
- half4 color : COLOR;
- float2 uv : TEXCOORD0;
- };
- struct Varyings
- {
- float2 uv : TEXCOORD0;
- #if defined _NORMAL
- half3 normalWS : TEXCOORD1;
- half3 tangentWS : TEXCOORD2;
- half3 bitangentWS : TEXCOORD3;
- #endif
- half4 color : TEXCOORD4;
- float4 vertex : SV_POSITION;
- };
- CBUFFER_START(UnityPerMaterial)
- //half _Alpha;
- CBUFFER_END
- #if defined (_DYNAMICALPHA)
- UNITY_INSTANCING_BUFFER_START(Props)
- UNITY_DEFINE_INSTANCED_PROP(half, _Alpha)
- UNITY_INSTANCING_BUFFER_END(Props)
- #endif
-
- sampler2D _MainTex;
-
-
- Varyings SimpleDisplacementFXVertex (Attributes input)
- {
- Varyings output = (Varyings)0;
-
- VertexPositionInputs vertexPosition = GetVertexPositionInputs(input.positionOS.xyz);
- output.vertex = vertexPosition.positionCS;
- output.uv = input.uv;
- output.color = input.color;
- #if defined _NORMAL
- VertexNormalInputs vertexTBN = GetVertexNormalInputs(input.normalOS, input.tangentOS);
- output.normalWS = vertexTBN.normalWS;
- output.tangentWS = vertexTBN.tangentWS;
- output.bitangentWS = vertexTBN.bitangentWS;
- #endif
- return output;
- }
-
- half4 SimpleDisplacementFXFragment (Varyings input) : SV_Target
- {
- half4 col = tex2D(_MainTex, input.uv);
- col.a *= input.color.a
- #if defined(_DYNAMICALPHA)
- * UNITY_ACCESS_INSTANCED_PROP(Props, _Alpha)
- #endif
- ;
- #if defined(_NORMAL)
- col.rgb = col.rgb * 2 - 1; // unpack
- col.rgb = TransformTangentToWorld(col.rgb, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
- col.rgb = col.rbg * 0.5 + 0.5; // swizzle to "tangent space" and repack
- #endif
- return col;
- }
- ENDHLSL
- }
- Pass
- {
- Tags{"LightMode" = "LightweightForward"}
-
- HLSLPROGRAM
- #pragma vertex SimpleDisplacementFXVertex
- #pragma fragment SimpleDisplacementFXFragment
- #pragma shader_feature_local _DYNAMICALPHA
- #pragma shader_feature_local _NORMAL
- //--------------------------------------
- // GPU Instancing
- #pragma multi_compile_instancing
-
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- struct Attributes
- {
- float3 positionOS : POSITION;
- #if defined _NORMAL
- float3 normalOS : NORMAL;
- float4 tangentOS : TANGENT;
- #endif
- half4 color : COLOR;
- float2 uv : TEXCOORD0;
- };
- struct Varyings
- {
- float2 uv : TEXCOORD0;
- #if defined _NORMAL
- half3 normalWS : TEXCOORD1;
- half3 tangentWS : TEXCOORD2;
- half3 bitangentWS : TEXCOORD3;
- #endif
- half4 color : TEXCOORD4;
- float4 vertex : SV_POSITION;
- };
- CBUFFER_START(UnityPerMaterial)
- //half _Alpha;
- CBUFFER_END
- #if defined (_DYNAMICALPHA)
- UNITY_INSTANCING_BUFFER_START(Props)
- UNITY_DEFINE_INSTANCED_PROP(half, _Alpha)
- UNITY_INSTANCING_BUFFER_END(Props)
- #endif
-
- sampler2D _MainTex;
-
-
- Varyings SimpleDisplacementFXVertex (Attributes input)
- {
- Varyings output = (Varyings)0;
-
- VertexPositionInputs vertexPosition = GetVertexPositionInputs(input.positionOS.xyz);
- output.vertex = vertexPosition.positionCS;
- output.uv = input.uv;
- output.color = input.color;
- #if defined _NORMAL
- VertexNormalInputs vertexTBN = GetVertexNormalInputs(input.normalOS, input.tangentOS);
- output.normalWS = vertexTBN.normalWS;
- output.tangentWS = vertexTBN.tangentWS;
- output.bitangentWS = vertexTBN.bitangentWS;
- #endif
- return output;
- }
-
- half4 SimpleDisplacementFXFragment (Varyings input) : SV_Target
- {
- half4 col = tex2D(_MainTex, input.uv);
- col.a *= input.color.a
- #if defined(_DYNAMICALPHA)
- * UNITY_ACCESS_INSTANCED_PROP(Props, _Alpha)
- #endif
- ;
- #if defined(_NORMAL)
- col.rgb = col.rgb * 2 - 1; // unpack
- col.rgb = TransformTangentToWorld(col.rgb, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
- col.rgb = col.rbg * 0.5 + 0.5; // swizzle to "tangent space" and repack
- #endif
- return col;
- }
- ENDHLSL
- }
- }
- }
|