Skip to content

Commit

Permalink
increase height map resolution from 8 bit to 16 bit
Browse files Browse the repository at this point in the history
  • Loading branch information
pierstitus committed Feb 10, 2021
1 parent 2a3882f commit 48df931
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion glsl/automaton.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ vec2 coord(int dir) {
}

float elevation(int dir) {
return (zmax-zmin)*texture2D(elevationMap, coord(dir)).r/dw;
return (zmax-zmin)*(texture2D(elevationMap, coord(dir)).r + texture2D(elevationMap, coord(dir)).g/255.0)/dw;
}

float waterlevel(int dir) {
Expand Down
2 changes: 1 addition & 1 deletion glsl/colormap.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ vec4 col(float h) {
}

void main() {
float elevation = texture2D(elevationMap, v_texCoord).r;
float elevation = texture2D(elevationMap, v_texCoord).r + texture2D(elevationMap, v_texCoord).g/255.0;
float waterlayer = texture2D(waterlevelMap, v_texCoord).r + texture2D(waterlevelMap, v_texCoord).g/255.0;

if (elevation==0.0) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
Expand Down
13 changes: 10 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,16 @@
// write elevation data into texture data
var pixels = new Float32Array(width*height*4);
for (var i=0;i<data.length;i++) {
if (data[i]!=nodata) pixels[4*i] = (data[i]-zmin)/(zmax-zmin);
else pixels[4*i] = 0;
pixels[4*i+1] = 0;
if (data[i]!=nodata) {
var scaled = (data[i]-zmin)/(zmax-zmin) * 255.0;
var msb = Math.floor(scaled);
pixels[4*i] = msb / 255.0;
pixels[4*i+1] = scaled - msb;
}
else {
pixels[4*i] = 0;
pixels[4*i+1] = 0;
}
pixels[4*i+2] = 0;
pixels[4*i+3] = 0;
}
Expand Down

0 comments on commit 48df931

Please sign in to comment.