Skip to content

Commit

Permalink
try fixing line AA scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Jul 12, 2023
1 parent ea78111 commit 9d34002
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion GLMakie/assets/shader/line_segment.vert
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ in float lastlen;
uniform mat4 projectionview, model;
uniform uint objectid;
uniform float depth_shift;
uniform float px_per_unit;

out uvec2 g_id;
out vec4 g_color;
Expand All @@ -42,7 +43,7 @@ void main()
int index = gl_VertexID;
g_id = uvec2(objectid, index+1);
g_color = to_color(color, color_map, color_norm, index);
g_thickness = thickness;
g_thickness = px_per_unit * thickness;
gl_Position = projectionview * model * to_vec4(vertex);
gl_Position.z += gl_Position.w * depth_shift;
}
3 changes: 2 additions & 1 deletion GLMakie/assets/shader/lines.vert
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ vec4 _color(Nothing color, sampler1D intensity, sampler1D color_map, vec2 color_
uniform mat4 projectionview, model;
uniform uint objectid;
uniform int total_length;
uniform float px_per_unit;

out uvec2 g_id;
out vec4 g_color;
Expand All @@ -50,7 +51,7 @@ void main()
int index = gl_VertexID;
g_id = uvec2(objectid, index+1);
g_valid_vertex = get_valid_vertex(valid_vertex);
g_thickness = thickness;
g_thickness = px_per_unit * thickness;

g_color = _color(color, intensity, color_map, color_norm, index, total_length);
#ifdef FAST_PATH
Expand Down
21 changes: 18 additions & 3 deletions GLMakie/src/drawing_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,25 @@ function draw_atomic(screen::Screen, scene::Scene, @nospecialize(x::Lines))
positions = handle_view(x[1], data)
space = get!(gl_attributes, :space, :data) # needs to happen before connect_camera! call
connect_camera!(x, data, scene.camera)
transform_func = transform_func_obs(x)

# Tweak things for px_per_unit
resolution = pop!(data, :resolution)
px_per_unit = data[:px_per_unit]
data[:resolution] = map((ppu, res) -> ppu .* res, px_per_unit, resolution)

transform_func = transform_func_obs(x)
ls = to_value(linestyle)

if isnothing(ls)
data[:pattern] = ls
data[:fast] = true

positions = apply_transform(transform_func, positions, space)
else
linewidth = gl_attributes[:thickness]
data[:pattern] = map((ls, lw) -> ls .* _mean(lw), linestyle, linewidth)
data[:pattern] = map(linestyle, linewidth, px_per_unit) do ls, lw, ppu
ppu * _mean(lw) .* ls
end
data[:fast] = false

pvm = map(*, data[:projectionview], data[:model])
Expand All @@ -311,13 +319,16 @@ function draw_atomic(screen::Screen, scene::Scene, @nospecialize(x::LineSegments
return cached_robj!(screen, scene, x) do gl_attributes
linestyle = pop!(gl_attributes, :linestyle)
data = Dict{Symbol, Any}(gl_attributes)
px_per_unit = data[:px_per_unit]
ls = to_value(linestyle)
if isnothing(ls)
data[:pattern] = nothing
data[:fast] = true
else
linewidth = gl_attributes[:thickness]
data[:pattern] = ls .* _mean(to_value(linewidth))
data[:pattern] = map(linestyle, linewidth, px_per_unit) do ls, lw, ppu
ppu * _mean(lw) .* ls
end
data[:fast] = false
end
space = get(gl_attributes, :space, :data) # needs to happen before connect_camera! call
Expand All @@ -332,6 +343,10 @@ function draw_atomic(screen::Screen, scene::Scene, @nospecialize(x::LineSegments
end
connect_camera!(x, data, scene.camera)

# Tweak things for px_per_unit
resolution = pop!(data, :resolution)
data[:resolution] = map((ppu, res) -> ppu .* res, px_per_unit, resolution)

return draw_linesegments(screen, positions, data)
end
end
Expand Down
10 changes: 5 additions & 5 deletions GLMakie/src/glshaders/lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ function draw_linesegments(screen, positions::VectorTypes{T}, data::Dict) where
gl_primitive = GL_LINES
pattern_length = 1f0
end
if !isa(pattern, Texture) && pattern !== nothing
if !isa(pattern, Vector)
error("Pattern needs to be a Vector of floats")
if !isa(pattern, Texture) && to_value(pattern) !== nothing
if !isa(to_value(pattern), Vector)
error("Pattern needs to be a Vector of floats. Found: $(typeof(pattern))")
end
tex = GLAbstraction.Texture(ticks(pattern, 100), x_repeat = :repeat)
tex = GLAbstraction.Texture(map(pt -> ticks(pt, 100), pattern), x_repeat = :repeat)
data[:pattern] = tex
data[:pattern_length] = Float32((last(pattern) - first(pattern)))
data[:pattern_length] = map(pt -> Float32(last(pt) - first(pt)), pattern)
end
return assemble_shader(data)
end
Expand Down

0 comments on commit 9d34002

Please sign in to comment.