Skip to content

Commit

Permalink
Fixed #38 - works for small dts
Browse files Browse the repository at this point in the history
There is still an issue though when going from small dt back to normal dt, its probably deltatimeprev is wrong but i could not get to the bottom of it so far from debug prints..
  • Loading branch information
huwb committed Aug 9, 2018
1 parent 56987c8 commit 94bf221
Showing 1 changed file with 6 additions and 4 deletions.
Expand Up @@ -51,12 +51,13 @@ Shader "Ocean/Shape/Sim/2D Wave Equation"
uniform half _Damping;
uniform float2 _LaplacianAxisX;

#define MIN_DT 0.00001

float4 frag(v2f i) : SV_Target
{
float4 uv_lastframe = float4(i.uv_lastframe.xy, 0., 0.);

float4 ft_ftm_faccum_foam = tex2Dlod(_SimDataLastFrame, uv_lastframe);
if (_SimDeltaTime == 0.0) return ft_ftm_faccum_foam;

float ft = ft_ftm_faccum_foam.x; // t - current value before update
float ftm = ft_ftm_faccum_foam.y; // t minus - previous value
Expand All @@ -78,11 +79,12 @@ Shader "Ocean/Shape/Sim/2D Wave Equation"
//float h = max(waterSignedDepth + ft, 0.);
float c = ComputeWaveSpeed(wavelength /*, h*/);

const float dt = max(_SimDeltaTime, 0.001);
const float dt = _SimDeltaTime;
const float dtp = _SimDeltaTimePrev;

// wave propagation
// velocity is implicit
float v = _SimDeltaTimePrev < 0.0001 ? 0. : (ft - ftm) / _SimDeltaTimePrev;
float v = dtp > MIN_DT ? (ft - ftm) / dtp : 0.0;
float ftp = ft + dt*v + dt*dt*c*c*(fxm + fxp + fym + fyp - 4.*ft) / (texelSize*texelSize);

// open boundary condition, from: http://hplgit.github.io/wavebc/doc/pub/._wavebc_cyborg002.html .
Expand All @@ -103,7 +105,7 @@ Shader "Ocean/Shape/Sim/2D Wave Equation"
//ftp *= lerp( 0.996, 1., clamp(waterSignedDepth, 0., 1.) );

// Foam
float accel = ((ftp - ft)/dt - v);
float accel = dt > MIN_DT ? ((ftp - ft)/dt - v) : 0.0;
float foam = -accel * dt;
foam = max(foam, 0.);

Expand Down

0 comments on commit 94bf221

Please sign in to comment.