mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Optimization of the OpenGL shaders for clipping with clipping planes.
This commit is contained in:
		
							parent
							
								
									112f218c03
								
							
						
					
					
						commit
						566bb7041a
					
				
					 2 changed files with 15 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -69,5 +74,8 @@ void main()
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    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…
	
	Add table
		Add a link
		
	
		Reference in a new issue