Skip to content

Commit

Permalink
Better (basic) heightmap
Browse files Browse the repository at this point in the history
  • Loading branch information
douze committed Dec 8, 2020
1 parent 15e0443 commit ce64ca7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion renderer/src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Camera::Camera(const glm::vec3& position, float aspect) noexcept
right{glm::vec3{1.0f, 0.0f, 0.0f}},
yaw{-90.0f},
pitch{0.0f},
projection_matrix{glm::perspective(45.0f, aspect, 1.0f, 500.0f)},
projection_matrix{glm::perspective(45.0f, aspect, 0.1f, 500.0f)},
dirty{true} {}

glm::mat4 Camera::get_view_matrix() {
Expand Down
3 changes: 2 additions & 1 deletion resources/shaders/noise-terrain.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ vec2 st = fs_in.uv;
color = vec4(c,1.0);

// noise
float v = fbm(fs_in.uv);
float v = fbm(3.0*fs_in.uv);
v = v*0.5+0.5;
color = vec4(v,v,v,1.0);
};
6 changes: 3 additions & 3 deletions resources/shaders/terrain.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ out vec4 color;
void main() {
vec3 d = fwidth(fs_in.wireframeDist);

vec3 a3 = smoothstep(vec3(0.0), d * 1.5, fs_in.wireframeDist);
vec3 a3 = smoothstep(vec3(0.0), d * 1.0, fs_in.wireframeDist);
float edgeFactor = min(min(a3.x, a3.y), a3.z);

// color = vec4(fs_in.color, 1.0);
color = texture(ourTexture, fs_in.uv);

bool wireframe = false;
if (wireframe) color = vec4(mix(vec3(1.0,0.0,0.0), color.rgb, edgeFactor), color.a);
bool wireframe = true;
if (wireframe) color = vec4(mix(vec3(1.0), color.rgb, edgeFactor), color.a);
}
12 changes: 7 additions & 5 deletions resources/shaders/terrain.tcs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ out TC_OUT {
} tcs_out[];

void main(void) {
float level = 32.0;

gl_TessLevelOuter[0] = 2.0;
gl_TessLevelOuter[1] = 4.0;
gl_TessLevelOuter[2] = 6.0;
gl_TessLevelOuter[3] = 8.0;
gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = gl_TessLevelOuter[3] = 32.0;

gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = gl_TessLevelOuter[3] = level;

gl_TessLevelInner[0] = 8.0;
gl_TessLevelInner[1] = 8.0;
gl_TessLevelInner[0] = gl_TessLevelInner[1] = 32.0;

gl_TessLevelInner[0] = gl_TessLevelInner[1] = level;

gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;

tcs_out[gl_InvocationID].uv = tcs_in[gl_InvocationID].uv;
tcs_out[gl_InvocationID].color = tcs_in[gl_InvocationID].color;
}

0 comments on commit ce64ca7

Please sign in to comment.