Add heightmap and apply it in tessellation shader
This commit is contained in:
parent
41154580f2
commit
4cf0dc230b
@ -5,11 +5,11 @@ in PipelineData {
|
||||
vec2 texture_coordinate;
|
||||
} fs_in;
|
||||
|
||||
uniform sampler2D diffuse_texture;
|
||||
layout (binding = 0) uniform sampler2D heightmap;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
void main() {
|
||||
vec4 diffuse_texel = texture(diffuse_texture, fs_in.texture_coordinate);
|
||||
color = vec4(1.0); // color = vec4(diffuse_texel);
|
||||
vec4 diffuse_texel = texture(heightmap, fs_in.texture_coordinate);
|
||||
color = vec4(diffuse_texel);
|
||||
}
|
@ -16,8 +16,8 @@ void main() {
|
||||
tc_out[gl_InvocationID].texture_coordinate = tc_in[gl_InvocationID].texture_coordinate;
|
||||
tc_out[gl_InvocationID].position = tc_in[gl_InvocationID].position;
|
||||
|
||||
gl_TessLevelInner[0] = 12;
|
||||
gl_TessLevelOuter[0] = 12;
|
||||
gl_TessLevelOuter[1] = 12;
|
||||
gl_TessLevelOuter[2] = 12;
|
||||
gl_TessLevelInner[0] = 32;
|
||||
gl_TessLevelOuter[0] = 32;
|
||||
gl_TessLevelOuter[1] = 32;
|
||||
gl_TessLevelOuter[2] = 32;
|
||||
}
|
@ -2,6 +2,12 @@
|
||||
|
||||
layout(triangles) in;
|
||||
|
||||
layout (binding = 0) uniform sampler2D heightmap;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
|
||||
in PipelineData {
|
||||
vec4 position;
|
||||
vec2 texture_coordinate;
|
||||
@ -21,5 +27,8 @@ void main() {
|
||||
te_out.position += gl_TessCoord.y * te_in[1].position;
|
||||
te_out.position += gl_TessCoord.z * te_in[2].position;
|
||||
|
||||
gl_Position = te_out.position;
|
||||
te_out.position.y += texture(heightmap, te_out.texture_coordinate).r;
|
||||
|
||||
mat4 pvm = projection * view * model;
|
||||
gl_Position = pvm * te_out.position;
|
||||
}
|
@ -6,20 +6,15 @@ layout (location = 2) in vec2 texture_coordinate;
|
||||
layout (location = 3) in vec3 aTangent;
|
||||
layout (location = 4) in vec3 aBitangent;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
|
||||
out PipelineData {
|
||||
vec4 position;
|
||||
vec2 texture_coordinate;
|
||||
} vs_out;
|
||||
|
||||
void main() {
|
||||
mat4 pvm = projection * view * model;
|
||||
vs_out.texture_coordinate = texture_coordinate;
|
||||
vec4 homogenous_position = vec4(position, 1.0);
|
||||
vs_out.position = pvm * homogenous_position;
|
||||
vs_out.position = homogenous_position;
|
||||
|
||||
gl_Position = vs_out.position;
|
||||
}
|
@ -26,7 +26,8 @@ class FullDemo : public Gedeng::Application {
|
||||
particle_tex1("Resources/Textures/Particles/circle.png", Gedeng::Texture::Settings()),
|
||||
particle_tex2("Resources/Textures/Particles/magic.png", Gedeng::Texture::Settings()),
|
||||
particle_tex3("Resources/Textures/Particles/smoke.png", Gedeng::Texture::Settings()),
|
||||
quad_mesh(Gedeng::QuadMesh(10.0)), light(glm::vec3(0.57735, -0.57735, 0.57735)),
|
||||
heightmap("Resources/Textures/terrain.png", Gedeng::Texture::Settings()), quad_mesh(Gedeng::QuadMesh(10.0)),
|
||||
light(glm::vec3(0.57735, -0.57735, 0.57735)),
|
||||
mesh1("Resources/Meshes/Monkey.obj", Gedeng::ObjMesh::Settings()),
|
||||
mesh2("Resources/Meshes/bench.obj", Gedeng::ObjMesh::Settings()),
|
||||
mesh3("Resources/Meshes/ring.obj", Gedeng::ObjMesh::Settings()) {
|
||||
@ -126,6 +127,7 @@ class FullDemo : public Gedeng::Application {
|
||||
|
||||
// Terrain
|
||||
terrain_shader.use();
|
||||
heightmap.bind_to(0);
|
||||
terrain_shader.setMat4("projection", camera.get_projection());
|
||||
terrain_shader.setMat4("view", camera.get_view());
|
||||
terrain_mesh.render_patches(terrain_shader);
|
||||
@ -157,6 +159,8 @@ class FullDemo : public Gedeng::Application {
|
||||
Gedeng::Texture particle_tex2;
|
||||
Gedeng::Texture particle_tex3;
|
||||
|
||||
Gedeng::Texture heightmap;
|
||||
|
||||
Gedeng::QuadMesh quad_mesh;
|
||||
Gedeng::QuadMesh terrain_mesh;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user