feat: aspect ration correction

This commit is contained in:
2025-08-27 16:55:51 +02:00
parent 83fb5cd587
commit 8ae83ad7cd
2 changed files with 10 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ const char *fragmentShaderSource =
{ {
glViewport(0, 0, wdth, height); glViewport(0, 0, wdth, height);
}*/ }*/
float aspect = 1.0;
void processInput(GLFWwindow *window) { void processInput(GLFWwindow *window) {
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) 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) { void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
aspect = float(width) / height;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
@@ -98,7 +100,7 @@ int main(int argc, char **argv) {
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
unsigned int shaderProgramm = compShader(); unsigned int shaderProgram = compShader();
FullScreenQuad fsq{}; FullScreenQuad fsq{};
@@ -109,8 +111,9 @@ int main(int argc, char **argv) {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shaderProgramm); glUseProgram(shaderProgram);
int aspectLocation = glGetUniformLocation(shaderProgram, "aspect");
glUniform1f(aspectLocation, aspect);
glBindVertexArray(fsq.getVAO()); glBindVertexArray(fsq.getVAO());
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);

5
sdf.fs
View File

@@ -4,6 +4,8 @@ R"###(
out vec4 FragColor; out vec4 FragColor;
in vec2 texCoords; in vec2 texCoords;
uniform float aspect;
vec3 center = vec3(0.0,0.0,20.0); vec3 center = vec3(0.0,0.0,20.0);
float radius = 5.0; float radius = 5.0;
@@ -89,6 +91,7 @@ vec3 calcNormal(Ray ray){
void main() void main()
{ {
vec3 dir = vec3((texCoords - 0.5)*2,1.0); vec3 dir = vec3((texCoords - 0.5)*2,1.0);
dir.x *= aspect;
vec3 pos = dir; vec3 pos = dir;
Ray ray = Ray(normalize(dir),pos,.0,.0,vec3(.0)); Ray ray = Ray(normalize(dir),pos,.0,.0,vec3(.0));
@@ -97,7 +100,7 @@ void main()
vec3 normal = calcNormal(ray); vec3 normal = calcNormal(ray);
vec3 lighDir = normalize(vec3(.5,-1.0,0.5)); 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)); Ray shRay = Ray(lighDir * (-1.0), ray.pos + 0.5*normal , .0,.0, vec3(.0));
shRay = march(shRay); shRay = march(shRay);