mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	GCodeViewer -> Improved depth detection in shader for options
This commit is contained in:
		
							parent
							
								
									0e018e6690
								
							
						
					
					
						commit
						0cb4a5ce56
					
				
					 1 changed files with 13 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -21,7 +21,9 @@ uniform float percent_center_radius;
 | 
			
		|||
 | 
			
		||||
// x = width, y = height
 | 
			
		||||
uniform ivec2 viewport_sizes;
 | 
			
		||||
uniform vec2 z_range;
 | 
			
		||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 | 
			
		||||
//uniform vec2 z_range;
 | 
			
		||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 | 
			
		||||
uniform mat4 inv_proj_matrix;
 | 
			
		||||
 | 
			
		||||
varying vec3 eye_center;
 | 
			
		||||
| 
						 | 
				
			
			@ -73,6 +75,15 @@ vec4 on_sphere_color(vec3 eye_on_sphere_position)
 | 
			
		|||
    return vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, 1.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float fragment_depth(vec3 eye_pos)
 | 
			
		||||
{
 | 
			
		||||
    // see: https://stackoverflow.com/questions/10264949/glsl-gl-fragcoord-z-calculation-and-setting-gl-fragdepth
 | 
			
		||||
    vec4 clip_pos = gl_ProjectionMatrix * vec4(eye_pos, 1.0);
 | 
			
		||||
    float ndc_depth = clip_pos.z / clip_pos.w;
 | 
			
		||||
 | 
			
		||||
    return (((gl_DepthRange.far - gl_DepthRange.near) * ndc_depth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
    vec2 pos = gl_PointCoord - vec2(0.5, 0.5);
 | 
			
		||||
| 
						 | 
				
			
			@ -82,6 +93,7 @@ void main()
 | 
			
		|||
     
 | 
			
		||||
    vec3 eye_on_sphere_position = eye_position_on_sphere(eye_position_from_fragment());
 | 
			
		||||
 | 
			
		||||
    gl_FragDepth = fragment_depth(eye_on_sphere_position);
 | 
			
		||||
//    gl_FragDepth = eye_on_sphere_position.z;
 | 
			
		||||
//    gl_FragDepth = (eye_on_sphere_position.z - z_range.x) / (z_range.y - z_range.x);
 | 
			
		||||
    gl_FragColor = on_sphere_color(eye_on_sphere_position);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue