Skip to content

Commit

Permalink
add naive depth sorting for scatter & text
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Nov 29, 2023
1 parent 5c35f22 commit 1271a27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions GLMakie/src/drawing_primitives.jl
Expand Up @@ -571,6 +571,7 @@ function draw_atomic(screen::Screen, scene::Scene,
gl_attributes[:uv_offset_width] = uv_offset_width
gl_attributes[:distancefield] = get_texture!(atlas)
gl_attributes[:visible] = plot.visible
gl_attributes[:depthsorting] = get(plot, :depthsorting, false)
cam = scene.camera
# gl_attributes[:preprojection] = Observable(Mat4f(I))
gl_attributes[:preprojection] = lift(plot, space, markerspace, cam.projectionview, cam.resolution) do s, ms, pv, res
Expand Down
16 changes: 16 additions & 0 deletions GLMakie/src/glshaders/particles.jl
Expand Up @@ -176,6 +176,20 @@ function draw_scatter(screen, (marker, position), data)
rot = vec2quaternion(rot)
delete!(data, :rotation)

if to_value(pop!(data, :depthsorting, false))
data[:indices] = map(
data[:projectionview], data[:preprojection], data[:model],
position
) do pv, pp, m, pos
T = pv * pp * m
depth_vals = map(pos) do p
p4d = T * to_ndim(Point4f, to_ndim(Point3f, p, 0f0), 1f0)
p4d[3] / p4d[4]
end
UInt32.(sortperm(depth_vals, rev = true) .- 1)
end |> indexbuffer
end

@gen_defaults! data begin
shape = Cint(0)
position = position => GLBuffer
Expand All @@ -194,6 +208,7 @@ function draw_scatter(screen, (marker, position), data)
return shape
end
end

@gen_defaults! data begin
quad_offset = Vec2f(0) => GLBuffer
intensity = nothing => GLBuffer
Expand Down Expand Up @@ -226,6 +241,7 @@ function draw_scatter(screen, (marker, position), data)
scale_primitive = true
gl_primitive = GL_POINTS
end

# Exception for intensity, to make it possible to handle intensity with a
# different length compared to position. Intensities will be interpolated in that case
data[:intensity] = intensity_convert(intensity, position)
Expand Down

0 comments on commit 1271a27

Please sign in to comment.