Skip to content

Instantly share code, notes, and snippets.

@companje
Last active March 14, 2019 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/b1c391563227afe3dbee8892f3bc55d4 to your computer and use it in GitHub Desktop.
Save companje/b1c391563227afe3dbee8892f3bc55d4 to your computer and use it in GitHub Desktop.
Water vs Land on Earth
uniform sampler2D heightmap;
uniform sampler2D palette;
uniform sampler2D bordermap;
varying vec4 vertTexCoord;
uniform float progress;
void main() {
//color
vec4 heightColor = texture2D(heightmap, vertTexCoord.st);
float elevation = (heightColor.r * 255. + heightColor.a) / 255.; //0..1?
float zerolevel = 0.49659944;
float correction = -0.0018;
float f = elevation + correction - (progress-zerolevel)/2;
vec4 color = texture2D(palette, vec2(f,0));
//borders
vec4 borderColor = texture2D(bordermap, vertTexCoord.st);
color += borderColor * borderColor.a;
gl_FragColor = color;
}
uniform sampler2D heightmap;
uniform sampler2D heightmap2;
uniform sampler2D palette;
uniform sampler2D bordermap;
varying vec4 vertTexCoord;
uniform float progress;
float map(float value, float min1, float max1, float min2, float max2) {
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}
void main() {
vec4 borderColor = texture2D(bordermap, vertTexCoord.st);
vec4 heightColor = texture2D(heightmap, vertTexCoord.st);
vec4 heightColor2 = texture2D(heightmap2, vertTexCoord.st);
float elevation = (heightColor.r * 256. + heightColor2.r) / 256.; //0..1?
float f = elevation<progress ?
map(elevation, 0,progress, 0,.5) :
map(elevation, progress,1, .5,1); []
gl_FragColor = texture2D(palette, vec2(f,0)) + borderColor * borderColor.a;
}
import viewport.*;
float lowest = -11000; //meters
float highest = 8848; //meters
float progress = .5589; //.5543 voor 4k plaatjes
PImage heightmap, heightmap2, earth_palette, water_palette, palette, bordermap;
PShader shader;
Viewport view;
void setup() {
size(1024, 512, P2D);
bordermap = loadImage("borders8k.png");
heightmap = loadImage("8k-lo.png"); //zit verschil in niveau tussen 4k en 8k
heightmap2 = loadImage("8k-hi.png");
palette = loadImage("colors4k copy 9.png");
view = new Viewport(this, 0, 0, 1024, 512, 1024, 512);
}
void draw() {
view.mouseEnabled = keyPressed;
background(0);
try {
shader = loadShader("waterworld.glsl");
shader.set("palette", palette);
shader.set("heightmap", heightmap);
shader.set("heightmap2", heightmap2);
shader.set("bordermap", bordermap);
shader.set("progress", progress);
shader(shader);
}
catch (Exception e) {
println(e);
}
view.begin();
image(heightmap, 0, 0, width, height);
view.end();
resetShader();
//loadPixels();
//float waterArea = 0;
//for (int i=0; i<width*height; i++) {
// if (blue(pixels[i])>100) waterArea++;
//}
//waterArea /= width*height;
//text("fps: " + int(frameRate), 50, 35);
text("progress: " + nf(progress*100, 0, 2) + "%", 50, 50);
//text("area: " + nf(waterArea*100, 0, 2) + "%", 50, 65);
//float zero = .502;
//float meters = progress < zero ? map(progress, 0, zero, lowest, 0) : map(progress, zero, 1, 0, highest);
//23% progress geen water
//49.71% progress 0 niveau
//70% progress alles onder water
//text("meters: " + int(meters) + "m", 50, 80);
}
void mouseWheel(MouseEvent e) {
if (!keyPressed) progress += e.getCount()*.00001;
}
void mouseMoved() {
//progress = map(mouseX,0,width,0,1);
}
void keyPressed() {
if (key=='[') progress=0;
if (key==']') progress=1;
if (key=='/') progress=.5543;
}
@companje
Copy link
Author

colors4k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment