mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-27 19:01:02 +00:00
Add X-Ray view mode to 3D viewport (#15770)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#version 140
|
||||
|
||||
// X-Ray view: each surface is a thin translucent layer of its own color, covering more the more
|
||||
// edge-on it is seen. The caller draws it with depth writes off, so every surface a view ray crosses
|
||||
// composites and overlapping geometry reads as denser. Source-alpha rather than additive blending:
|
||||
// additive would saturate to white on the light theme's near-white background.
|
||||
#define EDGE_FALLOFF 2.0
|
||||
// Coverage head-on and edge-on.
|
||||
#define FACE_DENSITY 0.12
|
||||
#define EDGE_DENSITY 0.65
|
||||
|
||||
uniform vec4 uniform_color;
|
||||
|
||||
in vec3 eye_normal;
|
||||
in vec3 eye_position;
|
||||
in vec3 clipping_planes_dots;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (any(lessThan(clipping_planes_dots, vec3(0.0))))
|
||||
discard;
|
||||
|
||||
// abs(): back faces are drawn too, and there only the angle matters.
|
||||
float facing = abs(dot(normalize(eye_normal), normalize(-eye_position)));
|
||||
float density = mix(EDGE_DENSITY, FACE_DENSITY, pow(facing, EDGE_FALLOFF));
|
||||
|
||||
out_color = vec4(uniform_color.rgb, density * uniform_color.a);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#version 140
|
||||
|
||||
uniform mat4 view_model_matrix;
|
||||
uniform mat4 projection_matrix;
|
||||
uniform mat3 view_normal_matrix;
|
||||
uniform mat4 volume_world_matrix;
|
||||
|
||||
// Clipping, as in gouraud.vs: the preview's top / bottom plane and the SLA gizmo's free one.
|
||||
uniform vec2 z_range;
|
||||
uniform vec4 clipping_plane;
|
||||
|
||||
in vec3 v_position;
|
||||
in vec3 v_normal;
|
||||
|
||||
out vec3 eye_normal;
|
||||
out vec3 eye_position;
|
||||
out vec3 clipping_planes_dots;
|
||||
|
||||
void main()
|
||||
{
|
||||
eye_normal = view_normal_matrix * v_normal;
|
||||
|
||||
vec4 position = view_model_matrix * vec4(v_position, 1.0);
|
||||
eye_position = position.xyz;
|
||||
|
||||
// A component below zero means the fragment is clipped away.
|
||||
vec4 world_pos = volume_world_matrix * vec4(v_position, 1.0);
|
||||
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
|
||||
|
||||
gl_Position = projection_matrix * position;
|
||||
}
|
||||
Reference in New Issue
Block a user