@@ -438,6 +438,36 @@ Shader "Crest/Ocean"
438
438
// We need this when sampling a screenspace texture.
439
439
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX (input);
440
440
441
+ #if _CLIPSURFACE_ON
442
+ {
443
+ // Clip surface
444
+ half clipValue = 0.0 ;
445
+
446
+ uint slice0; uint slice1; float alpha;
447
+ PosToSliceIndices (input.worldPos.xz, 0.0 , _CrestCascadeData[0 ]._scale, slice0, slice1, alpha);
448
+
449
+ const CascadeParams cascadeData0 = _CrestCascadeData[slice0];
450
+ const CascadeParams cascadeData1 = _CrestCascadeData[slice1];
451
+ const float weight0 = (1.0 - alpha) * cascadeData0._weight;
452
+ const float weight1 = (1.0 - weight0) * cascadeData1._weight;
453
+
454
+ if (weight0 > 0.001 )
455
+ {
456
+ const float3 uv = WorldToUV (input.worldPos.xz, cascadeData0, slice0);
457
+ SampleClip (_LD_TexArray_ClipSurface, uv, weight0, clipValue);
458
+ }
459
+ if (weight1 > 0.001 )
460
+ {
461
+ const float3 uv = WorldToUV (input.worldPos.xz, cascadeData1, slice1);
462
+ SampleClip (_LD_TexArray_ClipSurface, uv, weight1, clipValue);
463
+ }
464
+
465
+ clipValue = lerp (_CrestClipByDefault, clipValue, weight0 + weight1);
466
+ // Add 0.5 bias to tighten and smooth clipped edges.
467
+ clip (-clipValue + 0.5 );
468
+ }
469
+ #endif // _CLIPSURFACE_ON
470
+
441
471
const CascadeParams cascadeData0 = _CrestCascadeData[_LD_SliceIndex];
442
472
const CascadeParams cascadeData1 = _CrestCascadeData[_LD_SliceIndex + 1 ];
443
473
const PerCascadeInstanceData instanceData = _CrestPerCascadeInstanceData[_LD_SliceIndex];
@@ -453,24 +483,6 @@ Shader "Crest/Ocean"
453
483
const float wt_smallerLod = (1.0 - lodAlpha) * cascadeData0._weight;
454
484
const float wt_biggerLod = (1.0 - wt_smallerLod) * cascadeData1._weight;
455
485
456
- #if _CLIPSURFACE_ON
457
- // Clip surface
458
- half clipVal = 0.0 ;
459
- if (wt_smallerLod > 0.001 )
460
- {
461
- const float3 uv_slice_smallerLod = WorldToUV (input.worldPos.xz, cascadeData0, _LD_SliceIndex);
462
- SampleClip (_LD_TexArray_ClipSurface, uv_slice_smallerLod, wt_smallerLod, clipVal);
463
- }
464
- if (wt_biggerLod > 0.001 )
465
- {
466
- const float3 uv_slice_biggerLod = WorldToUV (input.worldPos.xz, cascadeData1, _LD_SliceIndex + 1 );
467
- SampleClip (_LD_TexArray_ClipSurface, uv_slice_biggerLod, wt_biggerLod, clipVal);
468
- }
469
- clipVal = lerp (_CrestClipByDefault, clipVal, wt_smallerLod + wt_biggerLod);
470
- // Add 0.5 bias for LOD blending and texel resolution correction. This will help to tighten and smooth clipped edges
471
- clip (-clipVal + 0.5 );
472
- #endif
473
-
474
486
#if _CLIPUNDERTERRAIN_ON
475
487
clip (input.lodAlpha_worldXZUndisplaced_oceanDepth.w + 2.0 );
476
488
#endif
0 commit comments