Compare commits
No commits in common. "main" and "feature/1-camera-controls" have entirely different histories.
main
...
feature/1-
|
@ -7,7 +7,6 @@ stages:
|
|||
|
||||
variables:
|
||||
VCPKG_ROOT: "/vcpkg"
|
||||
CMAKE_BUILD_TYPE: "Release"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -33,4 +32,4 @@ run_tests:
|
|||
- export DISPLAY=:99
|
||||
- export TEST_MODE=1
|
||||
- cd build
|
||||
- ./TerraVisor
|
||||
- ./TerraVisor
|
||||
|
|
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -1,11 +1,3 @@
|
|||
## [v0.0.2] - 2024-08-25
|
||||
### Changed
|
||||
- Refactored uniform handling in the initial geometry pass to improve maintainability.
|
||||
|
||||
## [v0.0.3] - 2024-08-28
|
||||
### Changed
|
||||
- Correctly manage window resizing for camera aspect ratio
|
||||
|
||||
## [v0.0.4] - 2024-08-28
|
||||
### Changed
|
||||
- Added dynamic tessellation determined by the slope of the terrain
|
||||
- Refactored uniform handling in the initial geometry pass to improve maintainability.
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
project(TerraVisor VERSION 0.0.4)
|
||||
project(TerraVisor VERSION 0.0.2)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
|
16
imgui.ini
16
imgui.ini
|
@ -19,7 +19,7 @@ Collapsed=0
|
|||
|
||||
[Window][TerraVisor]
|
||||
Pos=0,0
|
||||
Size=2880,1676
|
||||
Size=1676,1017
|
||||
Collapsed=0
|
||||
|
||||
[Window][Scene Window]
|
||||
|
@ -29,21 +29,21 @@ Collapsed=0
|
|||
DockId=0x00000003,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=0,34
|
||||
Size=2178,1641
|
||||
Pos=0,19
|
||||
Size=1224,998
|
||||
Collapsed=0
|
||||
DockId=0x00000003,0
|
||||
|
||||
[Window][Scene Settings]
|
||||
Pos=2181,34
|
||||
Size=699,1641
|
||||
Pos=1226,19
|
||||
Size=450,998
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x6F42A598 Window=0xE80F322C Pos=0,34 Size=2880,1641 Split=X Selected=0x9F2D9299
|
||||
DockSpace ID=0x6F42A598 Window=0xE80F322C Pos=0,19 Size=1676,998 Split=X Selected=0x9F2D9299
|
||||
DockNode ID=0x00000001 Parent=0x6F42A598 SizeRef=0,0 Split=X Selected=0x13926F0B
|
||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=578,701 CentralNode=1 Selected=0x13926F0B
|
||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=699,701 Selected=0x413E6147
|
||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=2107,701 CentralNode=1 Selected=0x13926F0B
|
||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=450,701 Selected=0x413E6147
|
||||
DockNode ID=0x00000002 Parent=0x6F42A598 SizeRef=419,701 Selected=0xF69494A7
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,6 @@
|
|||
#ifndef INTERFACE_H_
|
||||
#define INTERFACE_H_
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <imgui.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -20,7 +19,6 @@ struct Window {
|
|||
};
|
||||
|
||||
namespace Interface {
|
||||
void ApplyUIScaling(GLFWwindow* window);
|
||||
void AddWindow(std::vector<Window>& windows, const std::string& name, std::function<void()> renderFunc);
|
||||
Window* GetWindowByName(std::vector<Window>& windows, const std::string& name);
|
||||
void RenderWindows(std::vector<Window>& windows);
|
||||
|
|
|
@ -24,48 +24,21 @@ in VS_OUT {
|
|||
out TC_OUT {
|
||||
vec3 position;
|
||||
vec2 texCoord;
|
||||
float tessLevel;
|
||||
} tc_out[];
|
||||
|
||||
float getHeight(vec2 uv) {
|
||||
return texture(heightTexture, uv).r * displacementScale;
|
||||
}
|
||||
|
||||
float calculateSlope() {
|
||||
float step = 1.0f / (float(gridDensity) * maxTessellation + 1.0f);
|
||||
|
||||
// Find surrounding heights
|
||||
float hLeft = getHeight(tc_in[gl_InvocationID].texCoord + vec2(-step, 0.0f));
|
||||
float hRight = getHeight(tc_in[gl_InvocationID].texCoord + vec2(step, 0.0f));
|
||||
float hUp = getHeight(tc_in[gl_InvocationID].texCoord + vec2(0.0f, step));
|
||||
float hDown = getHeight(tc_in[gl_InvocationID].texCoord + vec2(0.0f, -step));
|
||||
|
||||
float slopeX = abs(hLeft - hRight) * displacementScale;
|
||||
float slopeY = abs(hUp - hDown) * displacementScale;
|
||||
|
||||
float maxSlope = max(slopeX, slopeY);
|
||||
|
||||
return maxSlope;
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Pass through position and texture coordinates to the tessellation evaluation shader
|
||||
tc_out[gl_InvocationID].position = tc_in[gl_InvocationID].position;
|
||||
tc_out[gl_InvocationID].texCoord = tc_in[gl_InvocationID].texCoord;
|
||||
|
||||
float slope = calculateSlope();
|
||||
float tessLevel = tessellationFactor * (1.0f + slope * 10.0f);
|
||||
tessLevel = max(tessLevel, maxTessellation);
|
||||
tc_out[gl_InvocationID].tessLevel = tessLevel;
|
||||
|
||||
// Set tessellation levels
|
||||
if (gl_InvocationID == 0) {
|
||||
gl_TessLevelOuter[0] = tessLevel;
|
||||
gl_TessLevelOuter[1] = tessLevel;
|
||||
gl_TessLevelOuter[2] = tessLevel;
|
||||
gl_TessLevelOuter[3] = tessLevel;
|
||||
gl_TessLevelOuter[0] = maxTessellation;
|
||||
gl_TessLevelOuter[1] = maxTessellation;
|
||||
gl_TessLevelOuter[2] = maxTessellation;
|
||||
gl_TessLevelOuter[3] = maxTessellation;
|
||||
|
||||
gl_TessLevelInner[0] = tessLevel;
|
||||
gl_TessLevelInner[1] = tessLevel;
|
||||
gl_TessLevelInner[0] = maxTessellation;
|
||||
gl_TessLevelInner[1] = maxTessellation;
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ layout(std140, binding = 4) uniform GeoUniforms
|
|||
in TC_OUT {
|
||||
vec3 position;
|
||||
vec2 texCoord;
|
||||
float tessLevel;
|
||||
} te_in[];
|
||||
|
||||
out TE_OUT {
|
||||
|
@ -31,25 +30,19 @@ float getHeight(vec2 uv) {
|
|||
return texture(heightTexture, uv).r * displacementScale;
|
||||
}
|
||||
|
||||
float getNeighbor(float tessFactor) {
|
||||
return (float(gridDensity) * tessFactor + 1.0f);
|
||||
}
|
||||
|
||||
vec3 calculateSmoothNormal(vec3 pos, vec2 coord) {
|
||||
// Currently hardcoded to match patch density
|
||||
//float step = 1.0f / (float(gridDensity) * tessLevel + 1.0f);
|
||||
float stepU = 1.0f / (float(gridDensity) * gl_TessLevelInner[0]);
|
||||
float stepV = 1.0f / (float(gridDensity) * gl_TessLevelInner[1]);
|
||||
float step = 1.0f / (float(gridDensity) * maxTessellation + 1.0f);
|
||||
|
||||
// Find surrounding heights
|
||||
float hLeft = getHeight(coord + vec2(-stepU, 0.0f));
|
||||
float hRight = getHeight(coord + vec2(stepU, 0.0f));
|
||||
float hUp = getHeight(coord + vec2(0.0f, stepV));
|
||||
float hDown = getHeight(coord + vec2(0.0f, -stepV));
|
||||
float hLeft = getHeight(coord + vec2(-step, 0.0f));
|
||||
float hRight = getHeight(coord + vec2(step, 0.0f));
|
||||
float hUp = getHeight(coord + vec2(0.0f, step));
|
||||
float hDown = getHeight(coord + vec2(0.0f, -step));
|
||||
|
||||
// Calculate tangents
|
||||
vec3 tangentX = normalize(vec3(stepU, hRight - hLeft, 0.0));
|
||||
vec3 tangentY = normalize(vec3(0.0, hUp - hDown, stepV));
|
||||
vec3 tangentX = normalize(vec3(step, hRight - hLeft, 0.0));
|
||||
vec3 tangentY = normalize(vec3(0.0, hUp - hDown, step));
|
||||
|
||||
return normalize(cross(tangentY, tangentX));
|
||||
}
|
||||
|
|
|
@ -4,31 +4,9 @@
|
|||
#include <imgui_impl_opengl3.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
namespace Interface {
|
||||
|
||||
void ApplyUIScaling(GLFWwindow* window) {
|
||||
float xScale, yScale;
|
||||
glfwGetWindowContentScale(window, &xScale, &yScale);
|
||||
|
||||
float scale = (xScale + yScale) * 0.5f;
|
||||
|
||||
ImGui::GetIO().FontGlobalScale = scale;
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.ScaleAllSizes(scale);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->Clear();
|
||||
|
||||
#ifdef _WIN32
|
||||
io.Fonts->AddFontFromFileTTF("imgui/misc/fonts/JetBrainsMono/JetBrainsMono-Medium.ttf", 8.0f * scale);
|
||||
#else
|
||||
io.Fonts->AddFontFromFileTTF("../imgui/misc/fonts/JetBrainsMono/JetBrainsMono-Medium.ttf", 8.0f * scale);
|
||||
#endif
|
||||
io.Fonts->Build();
|
||||
}
|
||||
|
||||
void AddWindow(std::vector<Window>& windows, const std::string& name, std::function<void()> renderFunc) {
|
||||
windows.emplace_back(name, renderFunc);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#include "config.h"
|
||||
#include "callbacks.h"
|
||||
#include "scene.h"
|
||||
#include "interface.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -157,7 +156,6 @@ int main() {
|
|||
scene.Init();
|
||||
InitializeImGui(window);
|
||||
FreeImage_Initialise();
|
||||
Interface::ApplyUIScaling(window);
|
||||
|
||||
// Check if we're in test mode
|
||||
const char* testEnv = std::getenv("TEST_MODE");
|
||||
|
|
|
@ -240,7 +240,8 @@ void Scene::Display(GLFWwindow* window) {
|
|||
|
||||
glUseProgram(shader_program_);
|
||||
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
|
||||
Window* viewport = Interface::GetWindowByName(windows_, "Viewport");
|
||||
if (viewport && viewport->size.x > 0 && viewport->size.y > 0) {
|
||||
|
@ -269,9 +270,7 @@ void Scene::Display(GLFWwindow* window) {
|
|||
glPatchParameteri(GL_PATCH_VERTICES, 4);
|
||||
glDrawElements(GL_PATCHES, indices.size(), GL_UNSIGNED_INT, 0);
|
||||
|
||||
FBO::Unbind();
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
FBO::Bind(lht_fbo_);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
|
Loading…
Reference in New Issue