2018-05-21 11:08:02 +00:00
|
|
|
#version 110
|
|
|
|
|
|
|
|
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
|
2020-03-16 07:35:13 +00:00
|
|
|
const vec3 GREEN = vec3(0.0, 0.7, 0.0);
|
|
|
|
const vec3 YELLOW = vec3(0.5, 0.7, 0.0);
|
|
|
|
const vec3 RED = vec3(0.7, 0.0, 0.0);
|
2020-03-13 14:09:07 +00:00
|
|
|
const float EPSILON = 0.0001;
|
|
|
|
|
|
|
|
struct SlopeDetection
|
|
|
|
{
|
2020-03-31 10:51:50 +00:00
|
|
|
bool actived;
|
2020-03-16 07:35:13 +00:00
|
|
|
// x = yellow, y = red
|
2020-03-13 14:09:07 +00:00
|
|
|
vec2 z_range;
|
|
|
|
mat3 volume_world_normal_matrix;
|
|
|
|
};
|
|
|
|
|
|
|
|
uniform vec4 uniform_color;
|
|
|
|
uniform SlopeDetection slope;
|
2018-05-21 11:08:02 +00:00
|
|
|
|
2019-04-12 09:01:53 +00:00
|
|
|
varying vec3 clipping_planes_dots;
|
|
|
|
|
2018-05-21 11:08:02 +00:00
|
|
|
// x = tainted, y = specular;
|
|
|
|
varying vec2 intensity;
|
|
|
|
|
|
|
|
varying vec3 delta_box_min;
|
|
|
|
varying vec3 delta_box_max;
|
|
|
|
|
2020-03-13 14:09:07 +00:00
|
|
|
varying float world_normal_z;
|
2018-05-21 11:08:02 +00:00
|
|
|
|
2020-03-13 14:09:07 +00:00
|
|
|
vec3 slope_color()
|
|
|
|
{
|
2020-03-16 07:35:13 +00:00
|
|
|
float gradient_range = slope.z_range.x - slope.z_range.y;
|
|
|
|
return (world_normal_z > slope.z_range.x - EPSILON) ? GREEN : ((gradient_range == 0.0) ? RED : mix(RED, YELLOW, clamp((world_normal_z - slope.z_range.y) / gradient_range, 0.0, 1.0)));
|
2020-03-13 14:09:07 +00:00
|
|
|
}
|
2019-03-25 11:01:02 +00:00
|
|
|
|
2018-05-21 11:08:02 +00:00
|
|
|
void main()
|
|
|
|
{
|
2019-04-12 09:01:53 +00:00
|
|
|
if (any(lessThan(clipping_planes_dots, ZERO)))
|
2019-03-25 11:01:02 +00:00
|
|
|
discard;
|
2020-03-31 10:51:50 +00:00
|
|
|
vec3 color = slope.actived ? slope_color() : uniform_color.rgb;
|
2018-05-21 11:08:02 +00:00
|
|
|
// if the fragment is outside the print volume -> use darker color
|
2020-03-13 14:09:07 +00:00
|
|
|
color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(color, ZERO, 0.3333) : color;
|
2018-05-21 11:08:02 +00:00
|
|
|
gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + color * intensity.x, uniform_color.a);
|
|
|
|
}
|