diff --git a/GLMakie/assets/shader/sprites.geom b/GLMakie/assets/shader/sprites.geom index 38bdd57a9de..46fa96b32a7 100644 --- a/GLMakie/assets/shader/sprites.geom +++ b/GLMakie/assets/shader/sprites.geom @@ -7,13 +7,6 @@ struct Nothing{ bool _; }; layout(points) in; -// Need to set size of ClipDistance -in gl_PerVertex { - vec4 gl_Position; - float gl_PointSize; - float gl_ClipDistance[8]; -} gl_in[]; - layout(triangle_strip, max_vertices = 4) out; mat4 qmat(vec4 quat){ @@ -56,6 +49,7 @@ in vec3 g_position[]; in vec4 g_rotation[]; in vec4 g_offset_width[]; in uvec2 g_id[]; +in float g_clip_distance[][8]; flat out int f_primitive_index; flat out float f_viewport_from_u_scale; @@ -98,7 +92,7 @@ void emit_vertex(vec4 vertex, vec2 uv) f_id = g_id[0]; f_sprite_scale = g_offset_width[0].zw; for (int i = 0; i < 8; i++) - gl_ClipDistance[i] = gl_in[0].gl_ClipDistance[i]; + gl_ClipDistance[i] = g_clip_distance[0][i]; EmitVertex(); } diff --git a/GLMakie/assets/shader/sprites.vert b/GLMakie/assets/shader/sprites.vert index 3c1b5a84c07..63a4b3651ef 100644 --- a/GLMakie/assets/shader/sprites.vert +++ b/GLMakie/assets/shader/sprites.vert @@ -87,10 +87,25 @@ out vec4 g_rotation; out vec4 g_color; out vec4 g_stroke_color; out vec4 g_glow_color; +out float g_clip_distance[8]; vec4 to_vec4(vec3 x){return vec4(x, 1.0);} vec4 to_vec4(vec4 x){return x;} -void process_clip_planes(vec3 world_pos); + +uniform int num_clip_planes; +uniform vec4 clip_planes[8]; + +void process_clip_planes_alt(vec3 world_pos) +{ + // distance = dot(world_pos - plane.point, plane.normal) + // precalculated: dot(plane.point, plane.normal) -> plane.w + for (int i = 0; i < num_clip_planes; i++) + g_clip_distance[i] = dot(world_pos, clip_planes[i].xyz) - clip_planes[i].w; + + // TODO: can be skipped? + for (int i = num_clip_planes; i < 8; i++) + g_clip_distance[i] = 1.0; +} void main(){ int index = gl_VertexID; @@ -98,7 +113,7 @@ void main(){ vec3 pos; {{position_calc}} vec4 world_pos = model * vec4(pos, 1); - process_clip_planes(world_pos.xyz); + process_clip_planes_alt(world_pos.xyz); vec4 p = preprojection * world_pos; if (scale_primitive) g_position = p.xyz / p.w + mat3(model) * marker_offset;