GCodeViewer -> Pass vertex normal to shaders for toolpaths
This commit is contained in:
parent
d41781f674
commit
69de5c8c9f
13 changed files with 431 additions and 265 deletions
31
resources/shaders/toolpaths.fs
Normal file
31
resources/shaders/toolpaths.fs
Normal file
|
@ -0,0 +1,31 @@
|
|||
#version 110
|
||||
|
||||
// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31)
|
||||
const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
|
||||
const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0);
|
||||
|
||||
// x = ambient, y = top diffuse, z = front diffuse, w = global
|
||||
uniform vec4 light_intensity;
|
||||
uniform vec3 uniform_color;
|
||||
|
||||
varying vec3 eye_position;
|
||||
varying vec3 eye_normal;
|
||||
|
||||
float intensity;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = normalize(eye_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. Take the abs value to light the lines no matter in which direction the normal points.
|
||||
float NdotL = abs(dot(normal, LIGHT_TOP_DIR));
|
||||
|
||||
intensity = light_intensity.x + NdotL * light_intensity.y;
|
||||
|
||||
// Perform the same lighting calculation for the 2nd light source.
|
||||
NdotL = abs(dot(normal, LIGHT_FRONT_DIR));
|
||||
intensity += NdotL * light_intensity.z;
|
||||
|
||||
gl_FragColor = vec4(uniform_color * light_intensity.w * intensity, 1.0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue