Skip to content

Commit

Permalink
Add matrix parameter to SnapAndTransitionVertLayout
Browse files Browse the repository at this point in the history
Also brings up-to-date with downstream.
  • Loading branch information
daleeidd committed Mar 15, 2023
1 parent 75bd693 commit 95e636e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions crest/Assets/Crest/Crest/Shaders/OceanVertHelpers.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

0 comments on commit 95e636e

Please sign in to comment.