From 8ae83ad7cd0645b9a280c1954a41cbe1084a959f Mon Sep 17 00:00:00 2001 From: Amy Retzerau Date: Wed, 27 Aug 2025 16:55:51 +0200 Subject: [PATCH] feat: aspect ration correction --- main.cpp | 9 ++++++--- sdf.fs | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 499a577..4a4b430 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,7 @@ const char *fragmentShaderSource = { glViewport(0, 0, wdth, height); }*/ +float aspect = 1.0; void processInput(GLFWwindow *window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) @@ -70,6 +71,7 @@ unsigned int compShader() { void framebuffer_size_callback(GLFWwindow *window, int width, int height) { glViewport(0, 0, width, height); + aspect = float(width) / height; } int main(int argc, char **argv) { @@ -98,7 +100,7 @@ int main(int argc, char **argv) { glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); - unsigned int shaderProgramm = compShader(); + unsigned int shaderProgram = compShader(); FullScreenQuad fsq{}; @@ -109,8 +111,9 @@ int main(int argc, char **argv) { glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - glUseProgram(shaderProgramm); - + glUseProgram(shaderProgram); + int aspectLocation = glGetUniformLocation(shaderProgram, "aspect"); + glUniform1f(aspectLocation, aspect); glBindVertexArray(fsq.getVAO()); glDrawArrays(GL_TRIANGLES, 0, 6); diff --git a/sdf.fs b/sdf.fs index f15ca98..6d707df 100644 --- a/sdf.fs +++ b/sdf.fs @@ -4,6 +4,8 @@ R"###( out vec4 FragColor; in vec2 texCoords; +uniform float aspect; + vec3 center = vec3(0.0,0.0,20.0); float radius = 5.0; @@ -89,6 +91,7 @@ vec3 calcNormal(Ray ray){ void main() { vec3 dir = vec3((texCoords - 0.5)*2,1.0); + dir.x *= aspect; vec3 pos = dir; Ray ray = Ray(normalize(dir),pos,.0,.0,vec3(.0)); @@ -97,7 +100,7 @@ void main() vec3 normal = calcNormal(ray); vec3 lighDir = normalize(vec3(.5,-1.0,0.5)); - float light = (- min(dot(normal,lighDir),0.0))*0.7+0.3; + float light = (- min(dot(normal,lighDir),0.0))*0.85+0.3; Ray shRay = Ray(lighDir * (-1.0), ray.pos + 0.5*normal , .0,.0, vec3(.0)); shRay = march(shRay);