xxxxxxxxxx
39
precision mediump float;
varying vec2 pos;
uniform sampler2D background;
uniform sampler2D foreground;
uniform sampler2D noiseTexture;
uniform float t; // transition value, between 0-1
const vec4 colourHigh = vec4(0., 0., 0., 1.);
const vec4 colourLow = vec4(1., 0., 0., 1.);
const float start = 0.05;
void main() {
vec2 newPos = pos;
// flip y axis
newPos.y = 1. - newPos.y;
// read colour from images
vec4 backgroundCol = texture2D(background, newPos);
vec4 foregroundCol = texture2D(foreground, newPos);
float noise = texture2D(noiseTexture, newPos/2.).r;
float height = (noise * (1. - start) + start) - t;
float useForeground = step(start, height); // 1 if height > burn cutoff
float useBackground = 1. - step(0., height); // 1 if height < burn cutoff
float colourT = smoothstep(0., start, height); // between 0 - 1 when between cuttoffs
float useTransition = (1. - useForeground) * (1. - useBackground);
gl_FragColor = useBackground * backgroundCol + useForeground * foregroundCol + useTransition * mix(colourLow, colourHigh, colourT);
}