shader_type spatial; render_mode unshaded, depth_draw_never, cull_disabled; // Uniforms that define the bounding box in world space. uniform vec3 bbox_min; uniform vec3 bbox_max; void vertex() { // Compute the particle’s center in world space. // (This assumes that your particle’s mesh is centered at the local origin.) vec3 particle_center = (MODEL_MATRIX * vec4(0.0, 0.0, 0.0, 1.0)).xyz; // Check if the particle’s center is within the provided bounding box. bool inside = (particle_center.x >= bbox_min.x && particle_center.x <= bbox_max.x && particle_center.y >= bbox_min.y && particle_center.y <= bbox_max.y && particle_center.z >= bbox_min.z && particle_center.z <= bbox_max.z); if (inside) { // If the particle qualifies, we override its vertex positions so that // regardless of its original quad, it covers the full clip space (i.e. the whole screen). // This assumes exactly 4 vertices per instance. if (VERTEX_ID == 0) { POSITION = vec4(-1.0, -1.0, 0.0, 1.0); } else if (VERTEX_ID == 1) { POSITION = vec4( 1.0, -1.0, 0.0, 1.0); } else if (VERTEX_ID == 2) { POSITION = vec4(-1.0, 1.0, 0.0, 1.0); } else { POSITION = vec4( 1.0, 1.0, 0.0, 1.0); } } else { // Otherwise, move the geometry far off clip space so it isn’t rendered. POSITION = vec4(2.0, 2.0, 2.0, 1.0); } } void fragment() { // Output pure red color. ALBEDO = vec3(1.0, 0.0, 0.0); }