Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Unlit/Water"
- {
- Properties
- {
- _Smoothness ("Smoothness", Range(0.5, 1.5)) = 1
- _ShallowColor ("ShallowColor", Color) = (1, 1, 1, 1)
- _DeepColor ("DeepColor", Color) = (1, 1, 1, 1)
- _BlendStrength ("BlendStrength", Range(0, 1)) = 0.5
- _MaxDepth ("MaxDepth", Float) = 1
- _WaveNormal ("WaveNormal", 2D) = "bump"{}
- _WaveNormalScale ("WaveNormalScale", Range(0, 1)) = 0.5
- _WaveNormalSpeed ("WaveNormalSpeed", Range(0, 2)) = 1
- _WaveVertexFlow ("WaveVertexFlow", Vector) = (1, 1, 1, 1)
- _WaveVertexScale ("WaveVertexScale", Range(0, 1)) = 0.5
- _WaveVertexFrequency ("WaveVertexFrequency", Float) = 1
- }
- SubShader
- {
- Tags
- {
- "RenderPipeline"="UniversalPipeline"
- "Queue"="Transparent"
- "RenderType"="Transparent"
- }
- LOD 100
- Pass
- {
- Blend SrcAlpha OneMinusSrcAlpha
- HLSLPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
- #include "Assets/Shaders/Lib/FastNoiseLite.hlsl"
- CBUFFER_START(UnityPerMaterial)
- float _Smoothness;
- float4 _ShallowColor;
- float4 _DeepColor;
- float _BlendStrength;
- float _MaxDepth;
- float4 _WaveNormal_ST;
- float _WaveNormalScale;
- float _WaveNormalSpeed;
- float4 _WaveVertexFlow;
- float _WaveVertexScale;
- float _WaveVertexFrequency;
- CBUFFER_END
- TEXTURE2D(_WaveNormal);
- SAMPLER(sampler_WaveNormal);
- struct Attributes
- {
- float4 positionOS : POSITION;
- float3 normalOS : NORMAL;
- float2 uv : TEXCOORD0;
- };
- struct Varyings
- {
- float4 positionHCS : SV_POSITION;
- float3 normalWS : TEXCOORD0;
- float4 uvNormal : TEXCOORD1;
- float3 positionWS : TEXCOORD2;
- float4 positionNDC : TEXCOORD3;
- };
- Varyings vert(Attributes IN)
- {
- Varyings OUT;
- float2 noisePos = float2(IN.positionOS.x + _Time.y * _WaveVertexFlow.x,
- IN.positionOS.z + _Time.y * _WaveVertexFlow.y) * _WaveVertexFrequency;
- float noise = (fnlGetNoise2D(fnlCreateState(), noisePos.x, noisePos.y) * _WaveVertexScale + 1) / 2;
- float4 positionOS = IN.positionOS + float4(IN.normalOS * noise, 0);
- VertexPositionInputs vpi = GetVertexPositionInputs(positionOS);
- OUT.positionHCS = vpi.positionCS;
- OUT.positionNDC = vpi.positionNDC;
- VertexNormalInputs vni = GetVertexNormalInputs(IN.normalOS);
- OUT.normalWS = vni.normalWS;
- float2 uv = TRANSFORM_TEX(IN.uv, _WaveNormal);
- OUT.uvNormal.xy = uv + float2(-1, 1) * _Time.x * _WaveNormalSpeed;
- OUT.uvNormal.zw = uv + float2(1, 1) * _Time.x * _WaveNormalSpeed;
- OUT.positionWS = TransformObjectToWorld(IN.positionOS);
- return OUT;
- }
- float4 frag(Varyings IN) : SV_Target
- {
- float3 normal1 = UnpackNormalScale(
- SAMPLE_TEXTURE2D(_WaveNormal, sampler_WaveNormal, IN.uvNormal.xy), _WaveNormalScale);
- float3 normal2 = UnpackNormalScale(
- SAMPLE_TEXTURE2D(_WaveNormal, sampler_WaveNormal, IN.uvNormal.zw), _WaveNormalScale);
- float3 normalWS = normalize(lerp(normal1, normal2, 0.5));
- float3 viewWS = GetWorldSpaceNormalizeViewDir(IN.positionWS);
- Light mainLight = GetMainLight();
- float depth = LinearEyeDepth(SampleSceneDepth(IN.positionNDC.xy / IN.positionNDC.w), _ZBufferParams) - IN.positionNDC.w;
- float4 albedo = lerp(_ShallowColor, _DeepColor, saturate(pow(depth, _MaxDepth)));
- BRDFData data;
- InitializeBRDFData(albedo.xyz, 0, 1, _Smoothness, albedo.a, data);
- float3 color = LightingPhysicallyBased(data, mainLight, normalWS, viewWS);
- return float4(color, albedo.a);
- }
- ENDHLSL
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement