'gouraud' shader modified to allow to draw an object with two different colors in Cut Gizmo

This commit is contained in:
enricoturri1966 2023-02-09 15:03:39 +01:00 committed by YuSanka
parent b40473be51
commit 224ee922c5
10 changed files with 89 additions and 24 deletions

View file

@ -24,6 +24,9 @@ struct SlopeDetection
};
uniform vec4 uniform_color;
uniform bool use_color_clip_plane;
uniform vec4 uniform_color_clip_plane_1;
uniform vec4 uniform_color_clip_plane_2;
uniform SlopeDetection slope;
#ifdef ENABLE_ENVIRONMENT_MAP
@ -34,6 +37,7 @@ uniform SlopeDetection slope;
uniform PrintVolumeDetection print_volume;
varying vec3 clipping_planes_dots;
varying float color_clip_plane_dot;
// x = diffuse, y = specular;
varying vec2 intensity;
@ -46,12 +50,16 @@ void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;
vec3 color = uniform_color.rgb;
float alpha = uniform_color.a;
vec4 color;
if (use_color_clip_plane)
color = (color_clip_plane_dot < 0.0) ? uniform_color_clip_plane_1 : uniform_color_clip_plane_2;
else
color = uniform_color;
if (slope.actived && world_normal_z < slope.normal_z - EPSILON) {
color = vec3(0.7, 0.7, 1.0);
alpha = 1.0;
color.rgb = vec3(0.7, 0.7, 1.0);
color.a = 1.0;
}
// if the fragment is outside the print volume -> use darker color
@ -67,13 +75,13 @@ void main()
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;
}
color.rgb = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color.rgb, ZERO, 0.3333) : color.rgb;
#ifdef ENABLE_ENVIRONMENT_MAP
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);
gl_FragColor = vec4(0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color.rgb * intensity.x, color.a);
else
#endif
gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha);
gl_FragColor = vec4(vec3(intensity.y) + color.rgb * intensity.x, color.a);
}

View file

@ -35,6 +35,8 @@ uniform SlopeDetection slope;
uniform vec2 z_range;
// Clipping plane - general orientation. Used by the SLA gizmo.
uniform vec4 clipping_plane;
// Color clip plane - general orientation. Used by the cut gizmo.
uniform vec4 color_clip_plane;
attribute vec3 v_position;
attribute vec3 v_normal;
@ -43,6 +45,7 @@ attribute vec3 v_normal;
varying vec2 intensity;
varying vec3 clipping_planes_dots;
varying float color_clip_plane_dot;
varying vec4 world_pos;
varying float world_normal_z;
@ -74,4 +77,5 @@ void main()
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);
color_clip_plane_dot = dot(world_pos, color_clip_plane);
}

View file

@ -24,6 +24,9 @@ struct SlopeDetection
};
uniform vec4 uniform_color;
uniform bool use_color_clip_plane;
uniform vec4 uniform_color_clip_plane_1;
uniform vec4 uniform_color_clip_plane_2;
uniform SlopeDetection slope;
#ifdef ENABLE_ENVIRONMENT_MAP
@ -34,6 +37,7 @@ uniform SlopeDetection slope;
uniform PrintVolumeDetection print_volume;
in vec3 clipping_planes_dots;
in float color_clip_plane_dot;
// x = diffuse, y = specular;
in vec2 intensity;
@ -48,12 +52,16 @@ void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;
vec3 color = uniform_color.rgb;
float alpha = uniform_color.a;
vec4 color;
if (use_color_clip_plane)
color = (color_clip_plane_dot < 0.0) ? uniform_color_clip_plane_1 : uniform_color_clip_plane_2;
else
color = uniform_color;
if (slope.actived && world_normal_z < slope.normal_z - EPSILON) {
color = vec3(0.7, 0.7, 1.0);
alpha = 1.0;
color.rgb = vec3(0.7, 0.7, 1.0);
color.a = 1.0;
}
// if the fragment is outside the print volume -> use darker color
@ -69,13 +77,13 @@ void main()
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;
}
color.rgb = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color.rgb, ZERO, 0.3333) : color.rgb;
#ifdef ENABLE_ENVIRONMENT_MAP
if (use_environment_tex)
out_color = vec4(0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, alpha);
out_color = vec4(0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color.rgb * intensity.x, color.a);
else
#endif
out_color = vec4(vec3(intensity.y) + color * intensity.x, alpha);
out_color = vec4(vec3(intensity.y) + color.rgb * intensity.x, color.a);
}

View file

@ -35,6 +35,8 @@ uniform SlopeDetection slope;
uniform vec2 z_range;
// Clipping plane - general orientation. Used by the SLA gizmo.
uniform vec4 clipping_plane;
// Color clip plane - general orientation. Used by the cut gizmo.
uniform vec4 color_clip_plane;
in vec3 v_position;
in vec3 v_normal;
@ -43,6 +45,7 @@ in vec3 v_normal;
out vec2 intensity;
out vec3 clipping_planes_dots;
out float color_clip_plane_dot;
out vec4 world_pos;
out float world_normal_z;
@ -74,4 +77,5 @@ void main()
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);
color_clip_plane_dot = dot(world_pos, color_clip_plane);
}

View file

@ -26,6 +26,9 @@ struct SlopeDetection
};
uniform vec4 uniform_color;
uniform bool use_color_clip_plane;
uniform vec4 uniform_color_clip_plane_1;
uniform vec4 uniform_color_clip_plane_2;
uniform SlopeDetection slope;
#ifdef ENABLE_ENVIRONMENT_MAP
@ -36,6 +39,7 @@ uniform SlopeDetection slope;
uniform PrintVolumeDetection print_volume;
varying vec3 clipping_planes_dots;
varying float color_clip_plane_dot;
// x = diffuse, y = specular;
varying vec2 intensity;
@ -48,12 +52,16 @@ void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;
vec3 color = uniform_color.rgb;
float alpha = uniform_color.a;
vec4 color;
if (use_color_clip_plane)
color = (color_clip_plane_dot < 0.0) ? uniform_color_clip_plane_1 : uniform_color_clip_plane_2;
else
color = uniform_color;
if (slope.actived && world_normal_z < slope.normal_z - EPSILON) {
color = vec3(0.7, 0.7, 1.0);
alpha = 1.0;
color.rgb = vec3(0.7, 0.7, 1.0);
color.a = 1.0;
}
// if the fragment is outside the print volume -> use darker color
@ -70,12 +78,12 @@ void main()
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;
color.rgb = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color.rgb, ZERO, 0.3333) : color.rgb;
#ifdef ENABLE_ENVIRONMENT_MAP
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);
gl_FragColor = vec4(0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color.rgb * intensity.x, color.a);
else
#endif
gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha);
gl_FragColor = vec4(vec3(intensity.y) + color.rgb * intensity.x, color.a);
}

View file

@ -35,6 +35,8 @@ uniform SlopeDetection slope;
uniform vec2 z_range;
// Clipping plane - general orientation. Used by the SLA gizmo.
uniform vec4 clipping_plane;
// Color clip plane - general orientation. Used by the cut gizmo.
uniform vec4 color_clip_plane;
attribute vec3 v_position;
attribute vec3 v_normal;
@ -43,6 +45,7 @@ attribute vec3 v_normal;
varying vec2 intensity;
varying vec3 clipping_planes_dots;
varying float color_clip_plane_dot;
varying vec4 world_pos;
varying float world_normal_z;
@ -74,4 +77,5 @@ void main()
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);
color_clip_plane_dot = dot(world_pos, color_clip_plane);
}