Optimization of the OpenGL shaders for clipping with clipping planes.
This commit is contained in:
parent
112f218c03
commit
566bb7041a
@ -2,30 +2,21 @@
|
|||||||
|
|
||||||
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
|
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
varying vec3 clipping_planes_dots;
|
||||||
|
|
||||||
// x = tainted, y = specular;
|
// x = tainted, y = specular;
|
||||||
varying vec2 intensity;
|
varying vec2 intensity;
|
||||||
|
|
||||||
varying vec3 delta_box_min;
|
varying vec3 delta_box_min;
|
||||||
varying vec3 delta_box_max;
|
varying vec3 delta_box_max;
|
||||||
|
|
||||||
varying vec3 world_pos;
|
|
||||||
|
|
||||||
uniform vec4 uniform_color;
|
uniform vec4 uniform_color;
|
||||||
|
|
||||||
// x = min z, y = max z;
|
|
||||||
uniform vec2 z_range;
|
|
||||||
|
|
||||||
// clipping plane (general orientation):
|
|
||||||
uniform vec4 clipping_plane;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
if ((world_pos.z < z_range.x) || (z_range.y < world_pos.z))
|
if (any(lessThan(clipping_planes_dots, ZERO)))
|
||||||
discard;
|
discard;
|
||||||
|
|
||||||
if (world_pos.x*clipping_plane.x + world_pos.y*clipping_plane.y + world_pos.z*clipping_plane.z + clipping_plane.w < 0.0 )
|
|
||||||
discard;
|
|
||||||
|
|
||||||
// if the fragment is outside the print volume -> use darker color
|
// if the fragment is outside the print volume -> use darker color
|
||||||
vec3 color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(uniform_color.rgb, ZERO, 0.3333) : uniform_color.rgb;
|
vec3 color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(uniform_color.rgb, ZERO, 0.3333) : uniform_color.rgb;
|
||||||
gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + color * intensity.x, uniform_color.a);
|
gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + color * intensity.x, uniform_color.a);
|
||||||
|
@ -28,13 +28,18 @@ struct PrintBoxDetection
|
|||||||
|
|
||||||
uniform PrintBoxDetection print_box;
|
uniform PrintBoxDetection print_box;
|
||||||
|
|
||||||
|
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
|
||||||
|
uniform vec2 z_range;
|
||||||
|
// Clipping plane - general orientation. Used by the SLA gizmo.
|
||||||
|
uniform vec4 clipping_plane;
|
||||||
|
|
||||||
// x = tainted, y = specular;
|
// x = tainted, y = specular;
|
||||||
varying vec2 intensity;
|
varying vec2 intensity;
|
||||||
|
|
||||||
varying vec3 delta_box_min;
|
varying vec3 delta_box_min;
|
||||||
varying vec3 delta_box_max;
|
varying vec3 delta_box_max;
|
||||||
|
|
||||||
varying vec3 world_pos;
|
varying vec3 clipping_planes_dots;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@ -69,5 +74,8 @@ void main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
world_pos = vec3(print_box.volume_world_matrix * gl_Vertex);
|
// Point in homogenous coordinates.
|
||||||
|
vec4 world_pos = print_box.volume_world_matrix * gl_Vertex;
|
||||||
|
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
|
||||||
|
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user