Various fixes

This commit is contained in:
enricoturri1966 2023-10-27 19:23:19 +08:00 committed by Noisyfox
parent a50c5a2b7a
commit fe78e40cb4
26 changed files with 176 additions and 58 deletions

View file

@ -0,0 +1,17 @@
#version 140
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
uniform vec4 uniform_color;
in vec3 clipping_planes_dots;
out vec4 out_color;
void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;
out_color = uniform_color;
}

View file

@ -0,0 +1,23 @@
#version 140
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;
in vec3 v_position;
out vec3 clipping_planes_dots;
void main()
{
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
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 * view_model_matrix * vec4(v_position, 1.0);
}

View file

@ -34,8 +34,6 @@ 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;
@ -97,9 +95,4 @@ void main()
#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);
}

View file

@ -1,13 +1,8 @@
#version 140
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;
}

View file

@ -2,10 +2,14 @@
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform float offset;
in vec3 v_position;
void main()
{
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
// Add small epsilon to z to solve z-fighting between painted triangles and contour lines.
vec4 clip_position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
clip_position.z -= offset * abs(clip_position.w);
gl_Position = clip_position;
}