'push'
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Hidden/Crest/Debug/Shallow Water Visualizer"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariables.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
|
||||
CBUFFER_START(CrestBuffer)
|
||||
half _Crest_DomainWidth;
|
||||
float3 _Crest_DomainOrigin;
|
||||
bool _Crest_RenderFinalHeight;
|
||||
CBUFFER_END
|
||||
|
||||
Texture2D<float> _Crest_Height;
|
||||
Texture2D<float> _Crest_GroundHeight;
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 normalWS : TEXCOORD0;
|
||||
};
|
||||
|
||||
float CalculatePositionY(float2 worldXZ)
|
||||
{
|
||||
float2 uv = (worldXZ - _Crest_DomainOrigin.xz) / _Crest_DomainWidth + 0.5;
|
||||
|
||||
float h = _Crest_Height.SampleLevel(LODData_linear_clamp_sampler, uv, 0.0).x;
|
||||
float g = _Crest_GroundHeight.SampleLevel(LODData_linear_clamp_sampler, uv, 0.0).x;
|
||||
|
||||
float y = g + _Crest_DomainOrigin.y;
|
||||
|
||||
if (_Crest_RenderFinalHeight)
|
||||
{
|
||||
y += h;
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS);
|
||||
float3 positionWS = mul(UNITY_MATRIX_M, float4(input.positionOS, 1.0)).xyz;
|
||||
|
||||
float y = CalculatePositionY(positionWS.xz);
|
||||
positionWS.y = y;
|
||||
|
||||
float dx = 0.01;
|
||||
float ydx = CalculatePositionY(positionWS.xz + float2(dx, 0.0));
|
||||
float ydz = CalculatePositionY(positionWS.xz + float2(0.0, dx));
|
||||
|
||||
output.positionCS = mul(UNITY_MATRIX_VP, float4(positionWS, 1.0));
|
||||
|
||||
output.normalWS = float3((y - ydx) / dx, 1.0, (y - ydz) / dx);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 Fragment(Varyings input) : SV_Target
|
||||
{
|
||||
input.normalWS = normalize(input.normalWS);
|
||||
return half4(input.normalWS, 1.0);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user