Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'resources/shaders/gouraud.vs')
-rw-r--r--resources/shaders/gouraud.vs30
1 files changed, 21 insertions, 9 deletions
diff --git a/resources/shaders/gouraud.vs b/resources/shaders/gouraud.vs
index cc54c1c44..ed7e3f56b 100644
--- a/resources/shaders/gouraud.vs
+++ b/resources/shaders/gouraud.vs
@@ -20,13 +20,21 @@ const vec3 ZERO = vec3(0.0, 0.0, 0.0);
struct PrintBoxDetection
{
+ bool actived;
vec3 min;
vec3 max;
- bool volume_detection;
mat4 volume_world_matrix;
};
+struct SlopeDetection
+{
+ bool actived;
+ float normal_z;
+ mat3 volume_world_normal_matrix;
+};
+
uniform PrintBoxDetection print_box;
+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;
@@ -41,27 +49,28 @@ varying vec3 delta_box_max;
varying vec3 clipping_planes_dots;
+varying float world_normal_z;
+varying vec3 eye_normal;
+
void main()
{
// First transform the normal into camera space and normalize the result.
- vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
+ eye_normal = normalize(gl_NormalMatrix * gl_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);
+ float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
- intensity.y = 0.0;
-
- if (NdotL > 0.0)
- intensity.y += LIGHT_TOP_SPECULAR * pow(max(dot(normal, reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS);
+ vec3 position = (gl_ModelViewMatrix * gl_Vertex).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(normal, LIGHT_FRONT_DIR), 0.0);
+ NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
// compute deltas for out of print volume detection (world coordinates)
- if (print_box.volume_detection)
+ if (print_box.actived)
{
vec3 v = (print_box.volume_world_matrix * gl_Vertex).xyz;
delta_box_min = v - print_box.min;
@@ -73,6 +82,9 @@ void main()
delta_box_max = ZERO;
}
+ // z component of normal vector in world coordinate used for slope shading
+ world_normal_z = slope.actived ? (normalize(slope.volume_world_normal_matrix * gl_Normal)).z : 0.0;
+
gl_Position = ftransform();
// Point in homogenous coordinates.
vec4 world_pos = print_box.volume_world_matrix * gl_Vertex;