Skip to content

Commit

Permalink
replace gl_PerVertex
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Jun 13, 2024
1 parent ccae5ed commit 011ad81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
10 changes: 2 additions & 8 deletions GLMakie/assets/shader/sprites.geom
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
19 changes: 17 additions & 2 deletions GLMakie/assets/shader/sprites.vert
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,33 @@ 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;
g_primitive_index = index;
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;
Expand Down

0 comments on commit 011ad81

Please sign in to comment.