drawProbabilityAmplitude = regl({
uniforms: {
texture: kCombined,
},
vert: `
uniform float WORLD_SIZE;
uniform float WORLD_HEIGHT;
uniform sampler2D texture;
float getHeight(vec2 xz) {
vec2 uv = vec2(0.5, 0.5) + xz.yx;
float h = texture2D(texture, uv).r * 1.5;
return WORLD_HEIGHT*(-1.0 + 2.0 * h) / 2. - .5;
}
vec3 getPosition(vec2 xz) {
return vec3(WORLD_SIZE*xz.x, getHeight(xz), WORLD_SIZE*xz.y);
}
precision mediump float;
attribute vec2 xzPosition;
varying vec3 vPosition;
varying vec2 vUv;
varying vec3 vNormal;
varying vec2 pos;
uniform mat4 projection, view;
void main() {
pos = xzPosition;
vec3 xyzPosition = getPosition(xzPosition);
vec2 uv = vec2(0.5, 0.5) + xzPosition.yx;
vUv = uv;
float eps = 1.0/16.0;
// approximate the normal with central differences.
vec3 va = vec3(2.0*eps,
getHeight(xzPosition + vec2(eps,0.0)) - getHeight(xzPosition - vec2(eps,0.0)) , 0.0 );
vec3 vb = vec3(0.0,
getHeight(xzPosition + vec2(0.0, eps)) - getHeight(xzPosition - vec2(0.0, eps)), 2.0*eps );
vNormal = normalize(cross(normalize(vb), normalize(va) ));
vPosition = xyzPosition;
gl_Position = projection * view * vec4(xyzPosition, 1);
}`,
frag: `
precision mediump float;
varying vec2 vUv;
varying vec3 vNormal;
varying vec2 pos;
uniform sampler2D texture;
${color_map}
float nudge_intensity(float x) {
return 1. - pow((1. - x), 2.);
}
void main () {
vec2 tex = texture2D(texture, vUv).rg;
float h = pow(abs(tex.r), 0.9); // (tex.r + 1.) / 2.;
gl_FragColor = vec4(color_map(nudge_intensity(clamp(h, 0., 1.))), 1.);
}`
})