Skip to content

Commit

Permalink
Revert including scaling factors in line rendering
Browse files Browse the repository at this point in the history
After identifying failing tests, closer reading suggests the line
rendering shaders all work in normalized units that arise naturally
from comparing the framebuffer size to resolution factor. This means
adding additional scaling is unnecessary since the framebuffer size
is already scaled.
  • Loading branch information
jmert committed Jan 7, 2023
1 parent 20ca7a0 commit 04bdd91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
15 changes: 7 additions & 8 deletions GLMakie/assets/shader/line_segment.geom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ layout(lines) in;
layout(triangle_strip, max_vertices = 4) out;

uniform vec2 resolution;
uniform float px_per_unit;
uniform float maxlength;
uniform float thickness;
uniform float pattern_length;
Expand All @@ -23,17 +22,17 @@ flat out uvec2 f_id;

vec2 screen_space(vec4 vertex)
{
return vec2(vertex.xy / vertex.w) * resolution*px_per_unit;
return vec2(vertex.xy / vertex.w)*resolution;
}

void emit_vertex(vec2 position, vec2 uv, int index)
{
vec4 inpos = gl_in[index].gl_Position;
f_uv = uv;
f_color = g_color[index];
gl_Position = vec4((position / (resolution*px_per_unit)) * inpos.w, inpos.z, inpos.w);
gl_Position = vec4((position / resolution) * inpos.w, inpos.z, inpos.w);
f_id = g_id[index];
f_thickness = px_per_unit * g_thickness[index] + AA_THICKNESS;
f_thickness = g_thickness[index] + AA_THICKNESS;
EmitVertex();
}

Expand All @@ -50,8 +49,8 @@ void main(void)
vec2 p0 = screen_space(gl_in[0].gl_Position); // start of previous segment
vec2 p1 = screen_space(gl_in[1].gl_Position); // end of previous segment, start of current segment

float thickness_aa0 = px_per_unit * g_thickness[0] + AA_THICKNESS;
float thickness_aa1 = px_per_unit * g_thickness[1] + AA_THICKNESS;
float thickness_aa0 = g_thickness[0]+AA_THICKNESS;
float thickness_aa1 = g_thickness[1]+AA_THICKNESS;
// determine the direction of each of the 3 segments (previous, current, next)
vec2 vun0 = p1 - p0;
vec2 v0 = normalize(vun0);
Expand All @@ -60,8 +59,8 @@ void main(void)
float l = length(p1-p0);
l /= (pattern_length*10);

float uv0 = thickness_aa0 / px_per_unit*g_thickness[0];
float uv1 = thickness_aa1 / px_per_unit*g_thickness[1];
float uv0 = thickness_aa0/g_thickness[0];
float uv1 = thickness_aa1/g_thickness[1];
emit_vertex(p0 + thickness_aa0 * n0, vec2(0, -uv0), 0);
emit_vertex(p0 - thickness_aa0 * n0, vec2(0, uv0), 0);
emit_vertex(p1 + thickness_aa1 * n0, vec2(l, -uv1), 1);
Expand Down
11 changes: 5 additions & 6 deletions GLMakie/assets/shader/lines.geom
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ out float f_thickness;
flat out uvec2 f_id;

uniform vec2 resolution;
uniform float px_per_unit;
uniform float maxlength;
uniform float thickness;
uniform float pattern_length;
Expand All @@ -29,16 +28,16 @@ uniform float pattern_length;

vec2 screen_space(vec4 vertex)
{
return vec2(vertex.xy / vertex.w) * resolution*px_per_unit;
return vec2(vertex.xy / vertex.w) * resolution;
}
void emit_vertex(vec2 position, vec2 uv, int index, float ratio)
{
vec4 inpos = gl_in[index].gl_Position;
f_uv = vec2((g_lastlen[index] * ratio) / pattern_length / (thickness+4) / 2.0, uv.y);
f_color = g_color[index];
gl_Position = vec4((position / (resolution*px_per_unit)) * inpos.w, inpos.z, inpos.w);
gl_Position = vec4((position/resolution)*inpos.w, inpos.z, inpos.w);
f_id = g_id[index];
f_thickness = px_per_unit * thickness;
f_thickness = thickness;
EmitVertex();
}

Expand Down Expand Up @@ -76,7 +75,7 @@ void main(void)
vec2 p2 = screen_space(gl_in[2].gl_Position); // end of current segment, start of next segment
vec2 p3 = screen_space(gl_in[3].gl_Position); // end of next segment

float thickness_aa = px_per_unit * thickness + 4;
float thickness_aa = thickness+4;

// determine the direction of each of the 3 segments (previous, current, next)
vec2 v1 = normalize(p2 - p1);
Expand Down Expand Up @@ -127,7 +126,7 @@ void main(void)
float xend = g_lastlen[2];
float ratio = length(p2 - p1) / (xend - xstart);

float uvy = thickness_aa / (px_per_unit * thickness);
float uvy = thickness_aa/thickness;

if( dot( v0, v1 ) < MITER_LIMIT ){
/*
Expand Down

0 comments on commit 04bdd91

Please sign in to comment.