diff options
| author | Adrian Kummerlaender | 2018-05-24 22:29:59 +0200 | 
|---|---|---|
| committer | Adrian Kummerlaender | 2018-05-24 22:29:59 +0200 | 
| commit | 727645613619e366ae51a2eaad69793c9e225b05 (patch) | |
| tree | f539335275db32345701fc414b9240dd6855f62f | |
| parent | 05b7e6975e12587164e94cc4d8792571f8acb31a (diff) | |
| download | computicle-727645613619e366ae51a2eaad69793c9e225b05.tar computicle-727645613619e366ae51a2eaad69793c9e225b05.tar.gz computicle-727645613619e366ae51a2eaad69793c9e225b05.tar.bz2 computicle-727645613619e366ae51a2eaad69793c9e225b05.tar.lz computicle-727645613619e366ae51a2eaad69793c9e225b05.tar.xz computicle-727645613619e366ae51a2eaad69793c9e225b05.tar.zst computicle-727645613619e366ae51a2eaad69793c9e225b05.zip | |
Implement classical Runge-Kutta method as Euler alternative
| -rw-r--r-- | src/shader/compute.glsl | 11 | 
1 files changed, 10 insertions, 1 deletions
| diff --git a/src/shader/compute.glsl b/src/shader/compute.glsl index d8714b6..148157b 100644 --- a/src/shader/compute.glsl +++ b/src/shader/compute.glsl @@ -21,6 +21,15 @@ vec2 explicitEuler(float h, vec2 v) {  	return v + h * f(v);  } +vec2 classicalRungeKutta(float h, vec2 v) { +	const vec2 k1 = f(v); +	const vec2 k2 = f(v + h/2. * k1); +	const vec2 k3 = f(v + h/2. * k2); +	const vec2 k4 = f(v + h    * k3); + +	return v + h * (1./6.*k1 + 1./3.*k2 + 1./3.*k3 + 1./6.*k4); +} +  // pseudo random numbers for particle placement  float rand(vec2 v){ @@ -45,7 +54,7 @@ bool insideWorld(vec2 v) {  void main() {  	const uint i = 3*gl_GlobalInvocationID.x;  	const vec2 v = vec2(data[i+0], data[i+1]); -	const vec2 w = explicitEuler(0.01, v); +	const vec2 w = classicalRungeKutta(0.01, v);  	if ( data[i+2] < 5. && insideWorld(v) ) {  		data[i+0]  = w.x; | 
