mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 20:51:12 -06:00 
			
		
		
		
	Tech ENABLE_GL_SHADERS_ATTRIBUTES - Added shaders for glsl version 140
(cherry picked from commit prusa3d/PrusaSlicer@76d1d4949b)
This commit is contained in:
		
							parent
							
								
									bb044754af
								
							
						
					
					
						commit
						1e4f16bd39
					
				
					 76 changed files with 1145 additions and 143 deletions
				
			
		
							
								
								
									
										11
									
								
								resources/shaders/110/background.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								resources/shaders/110/background.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform vec4 top_color; | ||||
| uniform vec4 bottom_color; | ||||
| 
 | ||||
| varying vec2 tex_coord; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_FragColor = mix(bottom_color, top_color, tex_coord.y); | ||||
| } | ||||
							
								
								
									
										12
									
								
								resources/shaders/110/background.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								resources/shaders/110/background.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | |||
| #version 110 | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| attribute vec2 v_tex_coord; | ||||
| 
 | ||||
| varying vec2 tex_coord; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
| 	tex_coord = v_tex_coord; | ||||
|     gl_Position = vec4(v_position, 1.0); | ||||
| } | ||||
							
								
								
									
										8
									
								
								resources/shaders/110/flat.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								resources/shaders/110/flat.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform vec4 uniform_color; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_FragColor = uniform_color; | ||||
| } | ||||
							
								
								
									
										11
									
								
								resources/shaders/110/flat.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								resources/shaders/110/flat.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0); | ||||
| } | ||||
							
								
								
									
										10
									
								
								resources/shaders/110/flat_texture.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								resources/shaders/110/flat_texture.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform sampler2D uniform_texture; | ||||
| 
 | ||||
| varying vec2 tex_coord; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_FragColor = texture2D(uniform_texture, tex_coord); | ||||
| } | ||||
							
								
								
									
										15
									
								
								resources/shaders/110/flat_texture.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								resources/shaders/110/flat_texture.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| attribute vec2 v_tex_coord; | ||||
| 
 | ||||
| varying vec2 tex_coord; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
| 	tex_coord = v_tex_coord; | ||||
|     gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0); | ||||
| } | ||||
							
								
								
									
										105
									
								
								resources/shaders/110/gouraud.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								resources/shaders/110/gouraud.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,105 @@ | |||
| #version 110 | ||||
| 
 | ||||
| const vec3 ZERO = vec3(0.0, 0.0, 0.0); | ||||
| //BBS: add grey and orange | ||||
| //const vec3 GREY = vec3(0.9, 0.9, 0.9); | ||||
| const vec3 ORANGE = vec3(0.8, 0.4, 0.0); | ||||
| const vec3 LightRed = vec3(0.78, 0.0, 0.0); | ||||
| const vec3 LightBlue = vec3(0.73, 1.0, 1.0); | ||||
| const float EPSILON = 0.0001; | ||||
| 
 | ||||
| struct PrintVolumeDetection | ||||
| { | ||||
| 	// 0 = rectangle, 1 = circle, 2 = custom, 3 = invalid | ||||
| 	int type; | ||||
|     // type = 0 (rectangle): | ||||
|     // x = min.x, y = min.y, z = max.x, w = max.y | ||||
|     // type = 1 (circle): | ||||
|     // x = center.x, y = center.y, z = radius | ||||
| 	vec4 xy_data; | ||||
|     // x = min z, y = max z | ||||
| 	vec2 z_data; | ||||
| }; | ||||
| 
 | ||||
| struct SlopeDetection | ||||
| { | ||||
|     bool actived; | ||||
| 	float normal_z; | ||||
|     mat3 volume_world_normal_matrix; | ||||
| }; | ||||
| 
 | ||||
| uniform vec4 uniform_color; | ||||
| uniform SlopeDetection slope; | ||||
| 
 | ||||
| //BBS: add outline_color | ||||
| uniform bool is_outline; | ||||
| 
 | ||||
| uniform bool offset_depth_buffer; | ||||
| 
 | ||||
| #ifdef ENABLE_ENVIRONMENT_MAP | ||||
|     uniform sampler2D environment_tex; | ||||
|     uniform bool use_environment_tex; | ||||
| #endif // ENABLE_ENVIRONMENT_MAP | ||||
| 
 | ||||
| uniform PrintVolumeDetection print_volume; | ||||
| 
 | ||||
| varying vec3 clipping_planes_dots; | ||||
| 
 | ||||
| // x = diffuse, y = specular; | ||||
| varying vec2 intensity; | ||||
| 
 | ||||
| varying vec4 world_pos; | ||||
| varying float world_normal_z; | ||||
| varying vec3 eye_normal; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     if (any(lessThan(clipping_planes_dots, ZERO))) | ||||
|         discard; | ||||
|     vec3  color = uniform_color.rgb; | ||||
|     float alpha = uniform_color.a; | ||||
| 
 | ||||
|     if (slope.actived) { | ||||
|          if(world_pos.z<0.1&&world_pos.z>-0.1) | ||||
|          { | ||||
|                 color = LightBlue; | ||||
|                 alpha = 0.8; | ||||
|          } | ||||
|          else if( world_normal_z < slope.normal_z - EPSILON) | ||||
|          { | ||||
|                 color = color * 0.5 + LightRed * 0.5; | ||||
|                 alpha = 0.8; | ||||
|          } | ||||
|     } | ||||
| 	// if the fragment is outside the print volume -> use darker color | ||||
|     vec3 pv_check_min = ZERO; | ||||
|     vec3 pv_check_max = ZERO; | ||||
|     if (print_volume.type == 0) { | ||||
|         // rectangle | ||||
|         pv_check_min = world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, print_volume.z_data.x); | ||||
|         pv_check_max = world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, print_volume.z_data.y); | ||||
|         color = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color, ZERO, 0.3333) : color; | ||||
|     } | ||||
|     else if (print_volume.type == 1) { | ||||
|         // circle | ||||
|         float delta_radius = print_volume.xy_data.z - distance(world_pos.xy, print_volume.xy_data.xy); | ||||
|         pv_check_min = vec3(delta_radius, 0.0, world_pos.z - print_volume.z_data.x); | ||||
|         pv_check_max = vec3(0.0, 0.0, world_pos.z - print_volume.z_data.y); | ||||
|         color = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color, ZERO, 0.3333) : color; | ||||
|     } | ||||
| 
 | ||||
| 	//BBS: add outline_color | ||||
| 	if (is_outline) | ||||
| 		gl_FragColor = uniform_color; | ||||
| #ifdef ENABLE_ENVIRONMENT_MAP | ||||
|     else if (use_environment_tex) | ||||
|         gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, alpha); | ||||
| #endif | ||||
| 	else | ||||
|         gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); | ||||
| 		 | ||||
|     // In the support painting gizmo and the seam painting gizmo are painted triangles rendered over the already | ||||
|     // rendered object. To resolved z-fighting between previously rendered object and painted triangles, values | ||||
|     // inside the depth buffer are offset by small epsilon for painted triangles inside those gizmos. | ||||
|     gl_FragDepth = gl_FragCoord.z - (offset_depth_buffer ? EPSILON : 0.0); | ||||
| } | ||||
							
								
								
									
										77
									
								
								resources/shaders/110/gouraud.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								resources/shaders/110/gouraud.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,77 @@ | |||
| #version 110 | ||||
| 
 | ||||
| #define INTENSITY_CORRECTION 0.6 | ||||
| 
 | ||||
| // normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) | ||||
| const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); | ||||
| #define LIGHT_TOP_DIFFUSE    (0.8 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SPECULAR   (0.125 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SHININESS  20.0 | ||||
| 
 | ||||
| // normalized values for (1./1.43, 0.2/1.43, 1./1.43) | ||||
| const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); | ||||
| #define LIGHT_FRONT_DIFFUSE  (0.3 * INTENSITY_CORRECTION) | ||||
| //#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION) | ||||
| //#define LIGHT_FRONT_SHININESS 5.0 | ||||
| 
 | ||||
| #define INTENSITY_AMBIENT    0.3 | ||||
| 
 | ||||
| const vec3 ZERO = vec3(0.0, 0.0, 0.0); | ||||
| 
 | ||||
| struct SlopeDetection | ||||
| { | ||||
|     bool actived; | ||||
| 	float normal_z; | ||||
|     mat3 volume_world_normal_matrix; | ||||
| }; | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| uniform mat3 normal_matrix; | ||||
| uniform mat4 volume_world_matrix; | ||||
| uniform SlopeDetection slope; | ||||
| 
 | ||||
| // 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; | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| attribute vec3 v_normal; | ||||
| 
 | ||||
| // x = diffuse, y = specular; | ||||
| varying vec2 intensity; | ||||
| 
 | ||||
| varying vec3 clipping_planes_dots; | ||||
| 
 | ||||
| varying vec4 world_pos; | ||||
| varying float world_normal_z; | ||||
| varying vec3 eye_normal; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
| 	// First transform the normal into camera space and normalize the result. | ||||
|     eye_normal = normalize(normal_matrix * v_normal); | ||||
| 
 | ||||
| 	// Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. | ||||
| 	// Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. | ||||
| 	float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); | ||||
| 
 | ||||
| 	intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; | ||||
|     vec4 position = view_model_matrix * vec4(v_position, 1.0); | ||||
|     intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); | ||||
| 
 | ||||
| 	// Perform the same lighting calculation for the 2nd light source (no specular applied). | ||||
| 	NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); | ||||
| 	intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; | ||||
| 
 | ||||
|     // Point in homogenous coordinates. | ||||
|     world_pos = volume_world_matrix * vec4(v_position, 1.0); | ||||
| 
 | ||||
|     // z component of normal vector in world coordinate used for slope shading | ||||
|     world_normal_z = slope.actived ? (normalize(slope.volume_world_normal_matrix * v_normal)).z : 0.0; | ||||
| 
 | ||||
|     gl_Position = projection_matrix * position; | ||||
|     // 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); | ||||
| } | ||||
							
								
								
									
										12
									
								
								resources/shaders/110/gouraud_light.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								resources/shaders/110/gouraud_light.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform vec4 uniform_color; | ||||
| uniform float emission_factor; | ||||
| 
 | ||||
| // x = tainted, y = specular; | ||||
| varying vec2 intensity; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a); | ||||
| } | ||||
							
								
								
									
										45
									
								
								resources/shaders/110/gouraud_light.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								resources/shaders/110/gouraud_light.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,45 @@ | |||
| #version 110 | ||||
| 
 | ||||
| #define INTENSITY_CORRECTION 0.6 | ||||
| 
 | ||||
| // normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) | ||||
| const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); | ||||
| #define LIGHT_TOP_DIFFUSE    (0.8 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SPECULAR   (0.125 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SHININESS  20.0 | ||||
| 
 | ||||
| // normalized values for (1./1.43, 0.2/1.43, 1./1.43) | ||||
| const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); | ||||
| #define LIGHT_FRONT_DIFFUSE  (0.3 * INTENSITY_CORRECTION) | ||||
| 
 | ||||
| #define INTENSITY_AMBIENT    0.3 | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| uniform mat3 normal_matrix; | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| attribute vec3 v_normal; | ||||
| 
 | ||||
| // x = tainted, y = specular; | ||||
| varying vec2 intensity; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     // First transform the normal into camera space and normalize the result. | ||||
|     vec3 normal = normalize(normal_matrix * v_normal); | ||||
|      | ||||
|     // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. | ||||
|     // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. | ||||
|     float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); | ||||
| 
 | ||||
|     intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; | ||||
|     vec4 position = view_model_matrix * vec4(v_position, 1.0); | ||||
|     intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); | ||||
| 
 | ||||
|     // Perform the same lighting calculation for the 2nd light source (no specular applied). | ||||
|     NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); | ||||
|     intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; | ||||
| 
 | ||||
|     gl_Position = projection_matrix * position; | ||||
| } | ||||
							
								
								
									
										12
									
								
								resources/shaders/110/gouraud_light_instanced.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								resources/shaders/110/gouraud_light_instanced.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform vec4 uniform_color; | ||||
| uniform float emission_factor; | ||||
| 
 | ||||
| // x = tainted, y = specular; | ||||
| varying vec2 intensity; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a); | ||||
| } | ||||
							
								
								
									
										50
									
								
								resources/shaders/110/gouraud_light_instanced.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								resources/shaders/110/gouraud_light_instanced.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,50 @@ | |||
| #version 110 | ||||
| 
 | ||||
| #define INTENSITY_CORRECTION 0.6 | ||||
| 
 | ||||
| // normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) | ||||
| const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); | ||||
| #define LIGHT_TOP_DIFFUSE    (0.8 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SPECULAR   (0.125 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SHININESS  20.0 | ||||
| 
 | ||||
| // normalized values for (1./1.43, 0.2/1.43, 1./1.43) | ||||
| const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); | ||||
| #define LIGHT_FRONT_DIFFUSE  (0.3 * INTENSITY_CORRECTION) | ||||
| 
 | ||||
| #define INTENSITY_AMBIENT    0.3 | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| uniform mat3 normal_matrix; | ||||
| 
 | ||||
| // vertex attributes | ||||
| attribute vec3 v_position; | ||||
| attribute vec3 v_normal; | ||||
| // instance attributes | ||||
| attribute vec3 i_offset; | ||||
| attribute vec2 i_scales; | ||||
| 
 | ||||
| // x = tainted, y = specular; | ||||
| varying vec2 intensity; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     // First transform the normal into camera space and normalize the result. | ||||
|     vec3 eye_normal = normalize(normal_matrix * v_normal); | ||||
|      | ||||
|     // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. | ||||
|     // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. | ||||
|     float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); | ||||
| 
 | ||||
|     intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; | ||||
|     vec4 world_position = vec4(v_position * vec3(vec2(1.5 * i_scales.x), 1.5 * i_scales.y) + i_offset - vec3(0.0, 0.0, 0.5 * i_scales.y), 1.0); | ||||
|     vec4 eye_position = view_model_matrix * world_position; | ||||
|     intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_position.xyz), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); | ||||
| 
 | ||||
|     // Perform the same lighting calculation for the 2nd light source (no specular applied). | ||||
|     NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); | ||||
|     intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; | ||||
| 
 | ||||
|     gl_Position = projection_matrix * eye_position; | ||||
| } | ||||
							
								
								
									
										11
									
								
								resources/shaders/110/imgui.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								resources/shaders/110/imgui.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform sampler2D Texture; | ||||
| 
 | ||||
| varying vec2 Frag_UV; | ||||
| varying vec4 Frag_Color; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
| 	gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st); | ||||
| } | ||||
							
								
								
									
										17
									
								
								resources/shaders/110/imgui.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								resources/shaders/110/imgui.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform mat4 ProjMtx; | ||||
| 
 | ||||
| attribute vec2 Position; | ||||
| attribute vec2 UV; | ||||
| attribute vec4 Color; | ||||
| 
 | ||||
| varying vec2 Frag_UV; | ||||
| varying vec4 Frag_Color; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
| 	Frag_UV = UV; | ||||
| 	Frag_Color = Color; | ||||
|     gl_Position = ProjMtx * vec4(Position.xy, 0.0, 1.0); | ||||
| } | ||||
							
								
								
									
										13
									
								
								resources/shaders/110/mm_contour.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								resources/shaders/110/mm_contour.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| #version 110 | ||||
| 
 | ||||
| const float EPSILON = 0.0001; | ||||
| 
 | ||||
| uniform vec4 uniform_color; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_FragColor = uniform_color; | ||||
|     // Values inside depth buffer for fragments of the contour of a selected area are offset | ||||
|     // by small epsilon to solve z-fighting between painted triangles and contour lines. | ||||
|     gl_FragDepth = gl_FragCoord.z - EPSILON; | ||||
| } | ||||
							
								
								
									
										11
									
								
								resources/shaders/110/mm_contour.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								resources/shaders/110/mm_contour.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0); | ||||
| } | ||||
							
								
								
									
										90
									
								
								resources/shaders/110/mm_gouraud.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								resources/shaders/110/mm_gouraud.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,90 @@ | |||
| #version 110 | ||||
| 
 | ||||
| #define INTENSITY_CORRECTION 0.6 | ||||
| 
 | ||||
| // normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) | ||||
| const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); | ||||
| #define LIGHT_TOP_DIFFUSE    (0.8 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SPECULAR   (0.125 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SHININESS  20.0 | ||||
| 
 | ||||
| // normalized values for (1./1.43, 0.2/1.43, 1./1.43) | ||||
| const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); | ||||
| #define LIGHT_FRONT_DIFFUSE  (0.3 * INTENSITY_CORRECTION) | ||||
| 
 | ||||
| #define INTENSITY_AMBIENT    0.3 | ||||
| 
 | ||||
| const vec3  ZERO    = vec3(0.0, 0.0, 0.0); | ||||
| const float EPSILON = 0.0001; | ||||
| //BBS: add grey and orange | ||||
| //const vec3 GREY = vec3(0.9, 0.9, 0.9); | ||||
| const vec3 ORANGE = vec3(0.8, 0.4, 0.0); | ||||
| const vec3 LightRed = vec3(0.78, 0.0, 0.0); | ||||
| const vec3 LightBlue = vec3(0.73, 1.0, 1.0); | ||||
| uniform vec4 uniform_color; | ||||
| 
 | ||||
| uniform bool volume_mirrored; | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat3 normal_matrix; | ||||
| 
 | ||||
| varying vec3 clipping_planes_dots; | ||||
| varying vec4 model_pos; | ||||
| varying vec4 world_pos; | ||||
| 
 | ||||
| struct SlopeDetection | ||||
| { | ||||
|     bool actived; | ||||
| 	 float normal_z; | ||||
|     mat3 volume_world_normal_matrix; | ||||
| }; | ||||
| uniform SlopeDetection slope; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     if (any(lessThan(clipping_planes_dots, ZERO))) | ||||
|         discard; | ||||
|     vec3  color = uniform_color.rgb; | ||||
|     float alpha = uniform_color.a; | ||||
| 
 | ||||
|     vec3 triangle_normal = normalize(cross(dFdx(model_pos.xyz), dFdy(model_pos.xyz))); | ||||
| #ifdef FLIP_TRIANGLE_NORMALS | ||||
|     triangle_normal = -triangle_normal; | ||||
| #endif | ||||
| 
 | ||||
|     if (volume_mirrored) | ||||
|         triangle_normal = -triangle_normal; | ||||
| 
 | ||||
|     vec3 transformed_normal = normalize(slope.volume_world_normal_matrix * triangle_normal); | ||||
|       | ||||
|     if (slope.actived) { | ||||
|         if(world_pos.z<0.1&&world_pos.z>-0.1) | ||||
|          { | ||||
|               color = LightBlue; | ||||
|               alpha = 1.0; | ||||
|          } | ||||
|          else if( transformed_normal.z < slope.normal_z - EPSILON) | ||||
|         { | ||||
|             color = color * 0.5 + LightRed * 0.5; | ||||
|             alpha = 1.0; | ||||
|         } | ||||
|     } | ||||
|     // First transform the normal into camera space and normalize the result. | ||||
|     vec3 eye_normal = normalize(normal_matrix * triangle_normal); | ||||
| 
 | ||||
|     // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. | ||||
|     // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. | ||||
|     float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); | ||||
| 
 | ||||
|     // x = diffuse, y = specular; | ||||
|     vec2 intensity = vec2(0.0); | ||||
|     intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; | ||||
|     vec3 position = (view_model_matrix * model_pos).xyz; | ||||
|     intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); | ||||
| 
 | ||||
|     // Perform the same lighting calculation for the 2nd light source (no specular applied). | ||||
|     NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); | ||||
|     intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; | ||||
| 
 | ||||
|     gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); | ||||
| } | ||||
							
								
								
									
										35
									
								
								resources/shaders/110/mm_gouraud.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								resources/shaders/110/mm_gouraud.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,35 @@ | |||
| #version 110 | ||||
| 
 | ||||
| const vec3 ZERO = vec3(0.0, 0.0, 0.0); | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| 
 | ||||
| uniform mat4 volume_world_matrix; | ||||
| // 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; | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| 
 | ||||
| varying vec3 clipping_planes_dots; | ||||
| varying vec4 model_pos; | ||||
| varying vec4 world_pos; | ||||
| struct SlopeDetection | ||||
| { | ||||
|     bool actived; | ||||
| 	float normal_z; | ||||
|     mat3 volume_world_normal_matrix; | ||||
| }; | ||||
| uniform SlopeDetection slope; | ||||
| void main() | ||||
| { | ||||
|     model_pos = vec4(v_position, 1.0); | ||||
|     // Point in homogenous coordinates. | ||||
|     world_pos = volume_world_matrix * model_pos; | ||||
| 
 | ||||
|     gl_Position = projection_matrix * view_model_matrix * model_pos; | ||||
|     // 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); | ||||
| } | ||||
							
								
								
									
										34
									
								
								resources/shaders/110/printbed.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								resources/shaders/110/printbed.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,34 @@ | |||
| #version 110 | ||||
| 
 | ||||
| const vec3 back_color_dark  = vec3(0.235, 0.235, 0.235); | ||||
| const vec3 back_color_light = vec3(0.365, 0.365, 0.365); | ||||
| 
 | ||||
| uniform sampler2D texture; | ||||
| uniform bool transparent_background; | ||||
| uniform bool svg_source; | ||||
| 
 | ||||
| varying vec2 tex_coord; | ||||
| 
 | ||||
| vec4 svg_color() | ||||
| { | ||||
|     // takes foreground from texture | ||||
|     vec4 fore_color = texture2D(texture, tex_coord); | ||||
| 
 | ||||
|     // calculates radial gradient | ||||
|     vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5))))); | ||||
| 
 | ||||
|     // blends foreground with background | ||||
|     return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0); | ||||
| } | ||||
| 
 | ||||
| vec4 non_svg_color() | ||||
| { | ||||
|     // takes foreground from texture | ||||
|     vec4 color = texture2D(texture, tex_coord); | ||||
|     return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a); | ||||
| } | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     gl_FragColor = svg_source ? svg_color() : non_svg_color(); | ||||
| } | ||||
							
								
								
									
										15
									
								
								resources/shaders/110/printbed.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								resources/shaders/110/printbed.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| attribute vec2 v_tex_coord; | ||||
| 
 | ||||
| varying vec2 tex_coord; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
| 	tex_coord = v_tex_coord; | ||||
|     gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0); | ||||
| } | ||||
							
								
								
									
										16
									
								
								resources/shaders/110/thumbnail.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								resources/shaders/110/thumbnail.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | |||
| #version 110 | ||||
| 
 | ||||
| uniform vec4 uniform_color; | ||||
| uniform float emission_factor; | ||||
| 
 | ||||
| // x = tainted, y = specular; | ||||
| varying vec2 intensity; | ||||
| //varying float drop; | ||||
| varying vec4 world_pos; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     if (world_pos.z < 0.0) | ||||
|         discard; | ||||
|     gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a); | ||||
| } | ||||
							
								
								
									
										51
									
								
								resources/shaders/110/thumbnail.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								resources/shaders/110/thumbnail.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,51 @@ | |||
| #version 110 | ||||
| 
 | ||||
| #define INTENSITY_CORRECTION 0.6 | ||||
| 
 | ||||
| // normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) | ||||
| const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); | ||||
| #define LIGHT_TOP_DIFFUSE    (0.8 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SPECULAR   (0.125 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SHININESS  20.0 | ||||
| 
 | ||||
| // normalized values for (1./1.43, 0.2/1.43, 1./1.43) | ||||
| const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); | ||||
| #define LIGHT_FRONT_DIFFUSE  (0.3 * INTENSITY_CORRECTION) | ||||
| 
 | ||||
| #define INTENSITY_AMBIENT    0.3 | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| attribute vec3 v_normal; | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| uniform mat3 normal_matrix; | ||||
| 
 | ||||
| uniform mat4 volume_world_matrix; | ||||
| 
 | ||||
| // x = tainted, y = specular; | ||||
| varying vec2 intensity; | ||||
| varying vec4 world_pos; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     // First transform the normal into camera space and normalize the result. | ||||
|     vec3 normal = normalize(normal_matrix * v_normal); | ||||
|      | ||||
|     // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. | ||||
|     // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. | ||||
|     float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); | ||||
| 
 | ||||
|     intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; | ||||
|     vec4 position = view_model_matrix * vec4(v_position, 1.0); | ||||
|     intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); | ||||
| 
 | ||||
|     // Perform the same lighting calculation for the 2nd light source (no specular applied). | ||||
|     NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); | ||||
|     intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; | ||||
| 
 | ||||
|     // Point in homogenous coordinates. | ||||
|     world_pos = volume_world_matrix * gl_Vertex; | ||||
| 
 | ||||
|     gl_Position = projection_matrix * position; | ||||
| } | ||||
							
								
								
									
										41
									
								
								resources/shaders/110/variable_layer_height.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								resources/shaders/110/variable_layer_height.fs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| #version 110 | ||||
| 
 | ||||
| #define M_PI 3.1415926535897932384626433832795 | ||||
| 
 | ||||
| // 2D texture (1D texture split by the rows) of color along the object Z axis. | ||||
| uniform sampler2D z_texture; | ||||
| // Scaling from the Z texture rows coordinate to the normalized texture row coordinate. | ||||
| uniform float z_to_texture_row; | ||||
| uniform float z_texture_row_to_normalized; | ||||
| uniform float z_cursor; | ||||
| uniform float z_cursor_band_width; | ||||
| 
 | ||||
| // x = tainted, y = specular; | ||||
| varying vec2 intensity; | ||||
| 
 | ||||
| varying float object_z; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     float object_z_row = z_to_texture_row * object_z; | ||||
|     // Index of the row in the texture. | ||||
|     float z_texture_row = floor(object_z_row); | ||||
|     // Normalized coordinate from 0. to 1. | ||||
|     float z_texture_col = object_z_row - z_texture_row; | ||||
|     float z_blend = 0.25 * cos(min(M_PI, abs(M_PI * (object_z - z_cursor) * 1.8 / z_cursor_band_width))) + 0.25; | ||||
|     // Calculate level of detail from the object Z coordinate. | ||||
|     // This makes the slowly sloping surfaces to be shown with high detail (with stripes), | ||||
|     // and the vertical surfaces to be shown with low detail (no stripes) | ||||
|     float z_in_cells = object_z_row * 190.; | ||||
|     // Gradient of Z projected on the screen. | ||||
|     float dx_vtc = dFdx(z_in_cells); | ||||
|     float dy_vtc = dFdy(z_in_cells); | ||||
|     float lod = clamp(0.5 * log2(max(dx_vtc * dx_vtc, dy_vtc * dy_vtc)), 0., 1.); | ||||
|     // Sample the Z texture. Texture coordinates are normalized to <0, 1>. | ||||
|     vec4 color = vec4(0.25, 0.25, 0.25, 1.0); | ||||
|     if (z_texture_row >= 0.0) | ||||
|         color = mix(texture2D(z_texture, vec2(z_texture_col, z_texture_row_to_normalized * (z_texture_row + 0.5    )), -10000.), | ||||
|                     texture2D(z_texture, vec2(z_texture_col, z_texture_row_to_normalized * (z_texture_row * 2. + 1.)),  10000.), lod);             | ||||
|     // Mix the final color. | ||||
|     gl_FragColor = vec4(vec3(intensity.y), 1.0) +  intensity.x * mix(color, vec4(1.0, 1.0, 0.0, 1.0), z_blend); | ||||
| } | ||||
							
								
								
									
										60
									
								
								resources/shaders/110/variable_layer_height.vs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								resources/shaders/110/variable_layer_height.vs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,60 @@ | |||
| #version 110 | ||||
| 
 | ||||
| #define INTENSITY_CORRECTION 0.6 | ||||
| 
 | ||||
| const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); | ||||
| #define LIGHT_TOP_DIFFUSE    (0.8 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SPECULAR   (0.125 * INTENSITY_CORRECTION) | ||||
| #define LIGHT_TOP_SHININESS  20.0 | ||||
| 
 | ||||
| const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); | ||||
| #define LIGHT_FRONT_DIFFUSE  (0.3 * INTENSITY_CORRECTION) | ||||
| //#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION) | ||||
| //#define LIGHT_FRONT_SHININESS 5.0 | ||||
| 
 | ||||
| #define INTENSITY_AMBIENT    0.3 | ||||
| 
 | ||||
| uniform mat4 view_model_matrix; | ||||
| uniform mat4 projection_matrix; | ||||
| uniform mat3 normal_matrix; | ||||
| uniform mat4 volume_world_matrix; | ||||
| uniform float object_max_z; | ||||
| 
 | ||||
| attribute vec3 v_position; | ||||
| attribute vec3 v_normal; | ||||
| attribute vec2 v_tex_coord; | ||||
| 
 | ||||
| // x = tainted, y = specular; | ||||
| varying vec2 intensity; | ||||
| 
 | ||||
| varying float object_z; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
| 	// ===================================================== | ||||
| 	// NOTE: | ||||
| 	// when object_max_z > 0.0  we are rendering the overlay | ||||
| 	// when object_max_z == 0.0 we are rendering the volumes | ||||
| 	// ===================================================== | ||||
| 
 | ||||
|     // First transform the normal into camera space and normalize the result. | ||||
|     vec3 normal = (object_max_z > 0.0) ? vec3(0.0, 0.0, 1.0) : normalize(normal_matrix * v_normal); | ||||
|      | ||||
|     // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. | ||||
|     // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. | ||||
|     float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); | ||||
| 
 | ||||
|     intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; | ||||
|     vec4 position = view_model_matrix * vec4(v_position, 1.0); | ||||
|     intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); | ||||
| 
 | ||||
|     // Perform the same lighting calculation for the 2nd light source (no specular) | ||||
|     NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); | ||||
|      | ||||
|     intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; | ||||
| 
 | ||||
|     // Scaled to widths of the Z texture. | ||||
|     object_z = (object_max_z > 0.0) ? object_max_z * v_tex_coord.y : (volume_world_matrix * vec4(v_position, 1.0)).z; | ||||
|          | ||||
|     gl_Position = projection_matrix * position; | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 enricoturri1966
						enricoturri1966