Skip to content

Commit

Permalink
#21 - Push underwater bubbles to a subsurface layer.
Browse files Browse the repository at this point in the history
Featuring more refraction, less movement with waves, and some parallax!
  • Loading branch information
huwb committed Jun 2, 2018
1 parent ebe5ede commit ed6c4f1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/unity/Assets/Crest/Shaders/Ocean.shader
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,15 @@ Shader "Ocean/Ocean"
// feather foam very close to shore
foamAmount *= saturate((i_sceneZ - i_pixelZ) / _FoamFeatherDepth);

float2 foamUV = (i_worldXZUndisplaced + 0.5 * _MyTime * _WindDirXZ) / _FoamScale;

// Additive underwater foam
half bubbleFoamTexValue = texture(_FoamTexture, .37 * foamUV).r;
half bubbleFoam = smoothstep( 0.0, 0.5, foamAmount * bubbleFoamTexValue);
float2 foamUVBubbles = (lerp(i_worldXZUndisplaced, i_worldXZ, 0.5) + 0.5 * _MyTime * _WindDirXZ) / _FoamScale;
foamUVBubbles += 0.25 * i_n.xz;
half bubbleFoamTexValue = texture(_FoamTexture, .37 * foamUVBubbles - .2*view.xz / view.y).r;
half bubbleFoam = smoothstep(0.0, 0.5, foamAmount * bubbleFoamTexValue);
o_bubbleCol = bubbleFoam * _FoamBubbleColor.rgb * _FoamBubbleColor.a * foamL;

// White foam on top, with black-point fading
float2 foamUV = (i_worldXZUndisplaced + 0.5 * _MyTime * _WindDirXZ) / _FoamScale;
foamUV += 0.02 * i_n.xz;
half foamTexValue = texture(_FoamTexture, foamUV).r;
o_whiteFoam = foamTexValue * (smoothstep(0.9 - foamAmount, 1.4 - foamAmount, foamTexValue)) * _FoamWhiteColor.a;
Expand Down

0 comments on commit ed6c4f1

Please sign in to comment.