Add interactive setting of tessellation factor

This commit is contained in:
karl 2021-05-30 20:42:45 +02:00
parent 4cf0dc230b
commit 332d1952e0
2 changed files with 13 additions and 5 deletions

View File

@ -2,6 +2,8 @@
layout(vertices = 3) out; layout(vertices = 3) out;
uniform int tessellation_factor;
in PipelineData { in PipelineData {
vec4 position; vec4 position;
vec2 texture_coordinate; vec2 texture_coordinate;
@ -16,8 +18,8 @@ void main() {
tc_out[gl_InvocationID].texture_coordinate = tc_in[gl_InvocationID].texture_coordinate; tc_out[gl_InvocationID].texture_coordinate = tc_in[gl_InvocationID].texture_coordinate;
tc_out[gl_InvocationID].position = tc_in[gl_InvocationID].position; tc_out[gl_InvocationID].position = tc_in[gl_InvocationID].position;
gl_TessLevelInner[0] = 32; gl_TessLevelInner[0] = tessellation_factor;
gl_TessLevelOuter[0] = 32; gl_TessLevelOuter[0] = tessellation_factor;
gl_TessLevelOuter[1] = 32; gl_TessLevelOuter[1] = tessellation_factor;
gl_TessLevelOuter[2] = 32; gl_TessLevelOuter[2] = tessellation_factor;
} }

View File

@ -16,7 +16,7 @@ class FullDemo : public Gedeng::Application {
FullDemo(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y, FullDemo(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y,
Gedeng::String window_name) Gedeng::String window_name)
: Application(ms_per_update, window_size_x, window_size_y, window_name), particle_interval(0.2), : Application(ms_per_update, window_size_x, window_size_y, window_name), particle_interval(0.2),
number_of_steps(10.0), number_of_refinement_steps(10.0), bump_depth(0.1), number_of_steps(10.0), number_of_refinement_steps(10.0), bump_depth(0.1), tessellation_factor(16.0),
render_shader(Gedeng::Shader("Shader/bump.vs", "Shader/bump.fs")), render_shader(Gedeng::Shader("Shader/bump.vs", "Shader/bump.fs")),
debug_shader(Gedeng::Shader("Shader/depth-debug.vs", "Shader/depth-debug.fs")), debug_shader(Gedeng::Shader("Shader/depth-debug.vs", "Shader/depth-debug.fs")),
camera(Gedeng::FPSCamera(90, 1920, 1080, 0.1, 1000.0)), camera(Gedeng::FPSCamera(90, 1920, 1080, 0.1, 1000.0)),
@ -69,6 +69,9 @@ class FullDemo : public Gedeng::Application {
if (Gedeng::Input::is_key_down(GLFW_KEY_2)) particle_interval = fmax(particle_interval + 0.1 * delta, 0.02); if (Gedeng::Input::is_key_down(GLFW_KEY_2)) particle_interval = fmax(particle_interval + 0.1 * delta, 0.02);
if (Gedeng::Input::is_key_down(GLFW_KEY_1)) particle_interval = fmax(particle_interval - 0.1 * delta, 0.02); if (Gedeng::Input::is_key_down(GLFW_KEY_1)) particle_interval = fmax(particle_interval - 0.1 * delta, 0.02);
if (Gedeng::Input::is_key_down(GLFW_KEY_4)) tessellation_factor += delta * 8.0;
if (Gedeng::Input::is_key_down(GLFW_KEY_3)) tessellation_factor -= delta * 8.0;
particles.set_interval(particle_interval); particles.set_interval(particle_interval);
} }
@ -130,6 +133,7 @@ class FullDemo : public Gedeng::Application {
heightmap.bind_to(0); heightmap.bind_to(0);
terrain_shader.setMat4("projection", camera.get_projection()); terrain_shader.setMat4("projection", camera.get_projection());
terrain_shader.setMat4("view", camera.get_view()); terrain_shader.setMat4("view", camera.get_view());
terrain_shader.setInt("tessellation_factor", static_cast<int>(tessellation_factor));
terrain_mesh.render_patches(terrain_shader); terrain_mesh.render_patches(terrain_shader);
// Log framerate // Log framerate
@ -143,6 +147,8 @@ class FullDemo : public Gedeng::Application {
float number_of_refinement_steps; float number_of_refinement_steps;
float bump_depth; float bump_depth;
float tessellation_factor;
Gedeng::Shader render_shader; Gedeng::Shader render_shader;
Gedeng::Shader debug_shader; Gedeng::Shader debug_shader;
Gedeng::Shader terrain_shader; Gedeng::Shader terrain_shader;