From 9283aa4752f20951dbb82975d209ee147eea0ec1 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Mon, 24 Mar 2014 19:14:17 -0400 Subject: [PATCH] Compensate for z-flattening when zooming --- gl/mesh.frag | 6 ++++++ src/canvas.cpp | 3 +++ 2 files changed, 9 insertions(+) diff --git a/gl/mesh.frag b/gl/mesh.frag index 5949025..d7a54d5 100644 --- a/gl/mesh.frag +++ b/gl/mesh.frag @@ -1,12 +1,18 @@ #version 120 +uniform float zoom; + varying vec3 ec_pos; void main() { vec3 base3 = vec3(0.99, 0.96, 0.89); vec3 base2 = vec3(0.92, 0.91, 0.83); vec3 base00 = vec3(0.40, 0.48, 0.51); + vec3 ec_normal = normalize(cross(dFdx(ec_pos), dFdy(ec_pos))); + ec_normal.z *= zoom; + ec_normal = normalize(ec_normal); + float a = dot(ec_normal, vec3(0.0, 0.0, 1.0)); float b = dot(ec_normal, vec3(-0.57, -0.57, 0.57)); diff --git a/src/canvas.cpp b/src/canvas.cpp index 1539469..1a1e060 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -89,6 +89,9 @@ void Canvas::draw_mesh() mesh_shader.uniformLocation("view_matrix"), 1, GL_FALSE, view_matrix().data()); + // Compensate for z-flattening when zooming + glUniform1f(mesh_shader.uniformLocation("zoom"), 1/zoom); + // Find and enable the attribute location for vertex position const GLuint vp = mesh_shader.attributeLocation("vertex_position"); glEnableVertexAttribArray(vp); -- 2.39.5