From 025f442686f5b5f6999e9b749801956010406e08 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 17 Aug 2024 19:05:05 -0400 Subject: [PATCH] Add slider for tessellation factor --- imgui.ini | 10 +++++----- shaders/tessellation_ctrl.glsl | 2 +- source/scene.cpp | 7 +++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/imgui.ini b/imgui.ini index 34d592c..4146e1a 100644 --- a/imgui.ini +++ b/imgui.ini @@ -4,8 +4,8 @@ Size=400,400 Collapsed=0 [Window][Terrain Controls] -Pos=933,19 -Size=347,701 +Pos=856,19 +Size=424,701 Collapsed=0 DockId=0x00000002,0 @@ -24,12 +24,12 @@ Collapsed=0 [Window][Scene Window] Pos=0,19 -Size=931,701 +Size=854,701 Collapsed=0 DockId=0x00000001,0 [Docking][Data] DockSpace ID=0x6F42A598 Window=0xE80F322C Pos=0,19 Size=1280,701 Split=X Selected=0x9F2D9299 - DockNode ID=0x00000001 Parent=0x6F42A598 SizeRef=931,701 CentralNode=1 Selected=0x9F2D9299 - DockNode ID=0x00000002 Parent=0x6F42A598 SizeRef=347,701 Selected=0xF69494A7 + DockNode ID=0x00000001 Parent=0x6F42A598 SizeRef=854,701 CentralNode=1 Selected=0x9F2D9299 + DockNode ID=0x00000002 Parent=0x6F42A598 SizeRef=424,701 Selected=0xF69494A7 diff --git a/shaders/tessellation_ctrl.glsl b/shaders/tessellation_ctrl.glsl index 9401092..7539dd8 100644 --- a/shaders/tessellation_ctrl.glsl +++ b/shaders/tessellation_ctrl.glsl @@ -12,7 +12,7 @@ out TC_OUT { vec2 texCoord; } tc_out[]; -uniform float tessellationFactor = 64.0f; +uniform float tessellationFactor; void main() { // Pass through position and texture coordinates to the tessellation evaluation shader diff --git a/source/scene.cpp b/source/scene.cpp index 1bb6a15..93ce056 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -39,6 +39,8 @@ const std::string kHGTPath = "hgt/N02E016.hgt"; GLuint tex_id = -1; +float tessellationFactor = 1.0f; + std::vector vertices; std::vector indices; @@ -222,6 +224,9 @@ void Scene::Display(GLFWwindow* window) { GLint heightTextureLoc = glGetUniformLocation(shader_program_, "heightTexture"); glUniform1i(heightTextureLoc, 0); + GLint tessFactorLoc = glGetUniformLocation(shader_program_, "tessellationFactor"); + glUniform1f(tessFactorLoc, tessellationFactor); + glBindVertexArray(vao_); glPatchParameteri(GL_PATCH_VERTICES, 4); glDrawElements(GL_PATCHES, indices.size(), GL_UNSIGNED_INT, 0); @@ -308,6 +313,8 @@ void Scene::DrawGui(GLFWwindow* window) { } ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + + ImGui::SliderFloat("Tessellation Level", &tessellationFactor, 1.0f, 64.0f); ImGui::End(); // Draw FBO to ImGui window