diff --git a/resources/shaders/gouraud.fs b/resources/shaders/gouraud.fs index b2bc915ab..09003f407 100644 --- a/resources/shaders/gouraud.fs +++ b/resources/shaders/gouraud.fs @@ -2,30 +2,21 @@ const vec3 ZERO = vec3(0.0, 0.0, 0.0); +varying vec3 clipping_planes_dots; + // x = tainted, y = specular; varying vec2 intensity; varying vec3 delta_box_min; varying vec3 delta_box_max; -varying vec3 world_pos; - uniform vec4 uniform_color; -// x = min z, y = max z; -uniform vec2 z_range; - -// clipping plane (general orientation): -uniform vec4 clipping_plane; void main() { - if ((world_pos.z < z_range.x) || (z_range.y < world_pos.z)) + if (any(lessThan(clipping_planes_dots, ZERO))) 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 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); diff --git a/resources/shaders/gouraud.vs b/resources/shaders/gouraud.vs index a226cf312..cc54c1c44 100644 --- a/resources/shaders/gouraud.vs +++ b/resources/shaders/gouraud.vs @@ -28,13 +28,18 @@ struct PrintBoxDetection 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; varying vec2 intensity; varying vec3 delta_box_min; varying vec3 delta_box_max; -varying vec3 world_pos; +varying vec3 clipping_planes_dots; void main() { @@ -66,8 +71,11 @@ void main() { delta_box_min = ZERO; delta_box_max = ZERO; - } + } 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); +}