Skip to content

Instantly share code, notes, and snippets.

@companje
Created August 11, 2022 14:21
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/3c9f64ca8a763aeb4db774e479da2802 to your computer and use it in GitHub Desktop.
Save companje/3c9f64ca8a763aeb4db774e479da2802 to your computer and use it in GitHub Desktop.
Mercury Elevation map waterlevels /
//based on Mercury MESSENGER Global DEM 665m v2
//https://web.archive.org/web/20210903191157/https://astrogeology.usgs.gov/search/map/Mercury/Topography/MESSENGER/Mercury_Messenger_USGS_DEM_Global_665m_v2
PImage palette, heightmap, colormap, normalmap;
PShader shader;
float progress = 0;
void setup() {
size(2048, 1024, P3D);
shader = loadShader("shader.glsl");
palette = loadImage("palette.png");
heightmap = loadImage("16k-8bit-elevation-Mercury_Messenger_DEM_Global_665m.png");
colormap = loadImage("GlobalColor2017_equi_64ppd.1000.750.430.10percent.png");
}
void draw() {
background(0);
shader.set("colormap", colormap);
shader.set("heightmap", heightmap);
shader.set("palette", palette);
shader.set("progress", progress);
shader(shader);
image(heightmap, 0, 0, width, height);
}
void mouseWheel(MouseEvent event) {
progress += event.getCount() *.0001;
progress = constrain(progress, 0, 1);
}
uniform sampler2D colormap;
uniform sampler2D heightmap;
uniform sampler2D palette;
uniform sampler2D borders;
uniform float progress;
varying vec4 vertTexCoord;
const float fade = 0.0025;
float map(float value, float min1, float max1, float min2, float max2) {
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}
void main() {
vec4 terrainColor = texture2D(colormap, vertTexCoord.st);
vec4 heightColor = texture2D(heightmap, vertTexCoord.st);
float elevation = (heightColor.r*256 + heightColor.g) / 256; //0..1
vec4 waterColor = texture2D(palette, vec2(map(elevation,0,progress,0,1),0));
float d = smoothstep(progress-fade, progress+fade, elevation);
gl_FragColor = mix(waterColor, terrainColor, d);
}
@companje
Copy link
Author

palette

@companje
Copy link
Author

@companje
Copy link
Author

Mercury elevation map

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