From 95e636e19d29e7a61e388291dfcd6bb6453fc595 Mon Sep 17 00:00:00 2001 From: Dale Eidd Date: Wed, 15 Mar 2023 23:38:31 +0800 Subject: [PATCH] Add matrix parameter to SnapAndTransitionVertLayout Also brings up-to-date with downstream. --- .../Crest/Crest/Shaders/OceanVertHelpers.hlsl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crest/Assets/Crest/Crest/Shaders/OceanVertHelpers.hlsl b/crest/Assets/Crest/Crest/Shaders/OceanVertHelpers.hlsl index c9b6dd3a6..caf7b2062 100644 --- a/crest/Assets/Crest/Crest/Shaders/OceanVertHelpers.hlsl +++ b/crest/Assets/Crest/Crest/Shaders/OceanVertHelpers.hlsl @@ -31,13 +31,20 @@ float ComputeLodAlpha(float3 i_worldPos, float i_meshScaleAlpha, in const Cascad return lodAlpha; } -void SnapAndTransitionVertLayout(in const float i_meshScaleAlpha, in const CascadeParams i_cascadeData0, in const float i_geometryGridSize, inout float3 io_worldPos, out float o_lodAlpha) +void SnapAndTransitionVertLayout(in const float4x4 i_objectMatrix, in const float i_meshScaleAlpha, in const CascadeParams i_cascadeData0, in const float i_geometryGridSize, inout float3 io_worldPos, out float o_lodAlpha) { const float GRID_SIZE_2 = 2.0 * i_geometryGridSize, GRID_SIZE_4 = 4.0 * i_geometryGridSize; // snap the verts to the grid // The snap size should be twice the original size to keep the shape of the eight triangles (otherwise the edge layout changes). - io_worldPos.xz -= frac(UNITY_MATRIX_M._m03_m23 / GRID_SIZE_2) * GRID_SIZE_2; // caution - sign of frac might change in non-hlsl shaders + float2 objectPosXZWS = i_objectMatrix._m03_m23; + + // Relative world space - add camera pos to get back out to world. Would be nice if we could operate in RWS.. +#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0) + objectPosXZWS += _WorldSpaceCameraPos.xz; +#endif + + io_worldPos.xz -= frac(objectPosXZWS / GRID_SIZE_2) * GRID_SIZE_2; // caution - sign of frac might change in non-hlsl shaders // compute lod transition alpha o_lodAlpha = ComputeLodAlpha(io_worldPos, i_meshScaleAlpha, i_cascadeData0); @@ -53,4 +60,9 @@ void SnapAndTransitionVertLayout(in const float i_meshScaleAlpha, in const Casca if (abs(offset.y) < minRadius) io_worldPos.z += offset.y * o_lodAlpha * GRID_SIZE_4; } +void SnapAndTransitionVertLayout(in const float i_meshScaleAlpha, in const CascadeParams i_cascadeData0, in const float i_geometryGridSize, inout float3 io_worldPos, out float o_lodAlpha) +{ + SnapAndTransitionVertLayout(UNITY_MATRIX_M, i_meshScaleAlpha, i_cascadeData0, i_geometryGridSize, io_worldPos, o_lodAlpha); +} + #endif // CREST_OCEAN_VERT_HELPERS_H