Skip to content

Commit

Permalink
Make rain rate variable and remove randomness/dithering. GUI still ne…
Browse files Browse the repository at this point in the history
…eded

With the higher bit depth the rain dithering is not necessary anymore.
It did look cool, but for the cool looks it would be better to add an effect
in visualisation.

to set rain rate from console:
>> raining=x
with x = rain rate in m per simulation step. Default: 0.001, 1mm per simulation step
  • Loading branch information
pierstitus committed May 17, 2021
1 parent 67e4302 commit da1046a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
16 changes: 2 additions & 14 deletions glsl/automaton.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uniform float dv; // the height of the cells

const float outflowrange = 10.0; // defines the resolution of outflow as it is only 8bit

uniform int rain;
uniform float rain;
uniform float lastX;
uniform float lastY;
uniform float currX;
Expand Down Expand Up @@ -64,18 +64,6 @@ float waterlevel(int dir) {
return 255.0*texture2D(waterlevelMap, coord(dir)).r + texture2D(waterlevelMap, coord(dir)).g;
}

int rand(vec2 co, int max) {
float a = 12.9898;
float b = 78.233;
float c = 43758.5453;
float dt = dot(co.xy ,vec2(a,b));
float sn = mod(dt, 3.14);
int rnd = int(float(max)*fract(abs(sin(sn) * c)));
if (rnd<0) rnd = 0;
if (rnd>=max) rnd = max-1;
return rnd;
}

void main() {
if (pass == 0) {
float flowfactor = 0.0;
Expand Down Expand Up @@ -136,7 +124,7 @@ void main() {
}

// apply raining...
if ((rain==1) && (rand(coord(rseed), 8)==0)) level += 0.1;
level += rain;

// apply sources and sinks
vec2 scale = vec2(1, du/dv);
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
var zmin, zmax;
var nodata;
var dw = 0.1;
var raining = false;
var raining = 0.0;
var simulate = false;
var maxSources = 16;
var sourcesCoordList = new Float32Array(32);
Expand Down Expand Up @@ -561,8 +561,8 @@
}

function togglerain(obj) {
raining = !raining;
document.getElementById('rainicon').src = raining ? 'img/rainon.svg' : 'img/rainoff.svg';
raining = raining? 0.0 : 0.001;
document.getElementById('rainicon').src = raining > 0 ? 'img/rainon.svg' : 'img/rainoff.svg';
}

var simfunc;
Expand Down
2 changes: 1 addition & 1 deletion js/mapmind.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function ahnSimulate() {
gl.uniform1f(gl.getUniformLocation(shaderAutomaton, "dv"), 1.0/height); // pass in the height of the cells
gl.uniform1f(gl.getUniformLocation(shaderAutomaton, "dw"), dw); // pass water increment

gl.uniform1i(gl.getUniformLocation(shaderAutomaton, "rain"), raining ? 1 : 0);
gl.uniform1f(gl.getUniformLocation(shaderAutomaton, "rain"), raining);

gl.uniform1i(gl.getUniformLocation(shaderAutomaton, "nSources"), sourcesList.getFeatures().length);
gl.uniform2fv(gl.getUniformLocation(shaderAutomaton, "sourceCoords"), sourcesCoordList);
Expand Down

0 comments on commit da1046a

Please sign in to comment.