xxxxxxxxxx
58
precision mediump float;
in vec2 pos;
out vec4 colour;
uniform sampler2D image;
uniform vec2 res;
vec4 packHeight(float value) {
int rgba = floatBitsToInt(value);
float a = float((rgba & 0xff000000) >> 24) / 255.0;
float b = float((rgba & 0x00ff0000) >> 16) / 255.0;
float g = float((rgba & 0x0000ff00) >> 8) / 255.0;
float r = float(rgba & 0x000000ff) / 255.0;
a = max(1./255., a);
// return vec4(r, g, b, a);
return vec4(vec3(value), 1.);
}
float unpackHeight(vec4 color) {
// int rgba = (int(color.a * 255.0) << 24) | (int(color.b * 255.0) << 16) | (int(color.g * 255.0) << 8) | int(color.r * 255.0);
// return intBitsToFloat(rgba);
return colour.r;
}
void main() {
vec2 bottomLeft = (floor(pos * res) - vec2(0.5))/res;
vec2 topRight = (floor(pos * res) + vec2(0.5))/res;
float t = topRight.y;
float b = bottomLeft.y;
float l = bottomLeft.x;
float r = topRight.x;
float tl = unpackHeight(texture(image, vec2(l, t)));
float tr = unpackHeight(texture(image, vec2(r, t)));
float bl = unpackHeight(texture(image, vec2(l, b)));
float br = unpackHeight(texture(image, vec2(r, b)));
float maxHeight = max(max(tl, tr), max(bl, br));
colour = packHeight(maxHeight);
}