Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
1.1.0:water [2023/10/25 08:15] – [Displacement] admin1.1.0:water [2024/01/23 08:23] (current) – [Example] admin
Line 166: Line 166:
 end; end;
 </file> </file>
 +
 +Ripple computation in the vertex shader is embedded inside our water shader program.
 +In case you'll need additional handling in the fragment shader, you could a code snippet like that.
 +
 +<file Pascal>
 +var LStr := TStringList.Create();
 +try
 +  LStr.Text := 
 + '''
 +   void SurfaceShader(inout TLocals DATA){
 + float l_TotalRippleEffect = 0.0;
 + float l_Time = abs(_TimeInfo.w);
 + vec3 l_TransfVertexPos = DATA.TransfVertPos.xyz;
 +
 + for(int i = 0; i < int(_RippleCount); i++){
 +   float l_RippleDist = distance(l_TransfVertexPos.xz, _Ripples[i].xz);
 +   float l_RippleTime = abs((_TimeInfo.x + l_Time) - _Ripples[i].w);
 +   float l_TimeLimit = clamp(1.0 / (l_RippleTime / (_RippleProximity * _RippleDecay)), 0.0, 1.0);
 +
 +   float l_RippleEffect = (-_RippleAmplification * exp(_RippleDecay * - l_RippleDist));
 +   l_RippleEffect *= cos(_RippleProximity * (l_RippleDist - l_RippleTime));
 +   l_RippleEffect *= l_TimeLimit;
 +
 +   l_TotalRippleEffect += exp(-l_RippleDist) * sin(0.5 * l_RippleDist) * l_RippleEffect;
 + }
 +
 + if(l_TotalRippleEffect > 0.01){
 +   vec4 l_BoatTrail = tex2D(_WaterShore, DATA.TexCoord0.xy);
 +   DATA.BaseColor.rgb += vec3(l_BoatTrail.rgb * l_TotalRippleEffect);
 +   DATA.SumColor.rgb += vec3(l_BoatTrail.rgb * l_TotalRippleEffect);
 + }
 +   }
 + ''';
 +
 +  FWaterMat.SurfaceShader := LStr;
 +finally
 +  LStr.Free;
 +end;
 +</file>
 +
 +This snippet will render the water shore texture onto the ripples if they have a minimum size of 0.01.
 +===== Tutorial =====
 +
 +{{youtube>bIXeUcTrd58}}
 +
 ===== Example ===== ===== Example =====