diff --git a/Shader/terrain.tcs b/Shader/terrain.tcs index f1a8659..61c53bf 100644 --- a/Shader/terrain.tcs +++ b/Shader/terrain.tcs @@ -2,6 +2,8 @@ layout(vertices = 3) out; +uniform int tessellation_factor; + in PipelineData { vec4 position; 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].position = tc_in[gl_InvocationID].position; - gl_TessLevelInner[0] = 32; - gl_TessLevelOuter[0] = 32; - gl_TessLevelOuter[1] = 32; - gl_TessLevelOuter[2] = 32; + gl_TessLevelInner[0] = tessellation_factor; + gl_TessLevelOuter[0] = tessellation_factor; + gl_TessLevelOuter[1] = tessellation_factor; + gl_TessLevelOuter[2] = tessellation_factor; } \ No newline at end of file diff --git a/test/full-demo/main.cpp b/test/full-demo/main.cpp index 09f2980..6b4da05 100644 --- a/test/full-demo/main.cpp +++ b/test/full-demo/main.cpp @@ -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, Gedeng::String window_name) : 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")), debug_shader(Gedeng::Shader("Shader/depth-debug.vs", "Shader/depth-debug.fs")), 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_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); } @@ -130,6 +133,7 @@ class FullDemo : public Gedeng::Application { heightmap.bind_to(0); terrain_shader.setMat4("projection", camera.get_projection()); terrain_shader.setMat4("view", camera.get_view()); + terrain_shader.setInt("tessellation_factor", static_cast(tessellation_factor)); terrain_mesh.render_patches(terrain_shader); // Log framerate @@ -143,6 +147,8 @@ class FullDemo : public Gedeng::Application { float number_of_refinement_steps; float bump_depth; + float tessellation_factor; + Gedeng::Shader render_shader; Gedeng::Shader debug_shader; Gedeng::Shader terrain_shader;