diff --git a/resources/shaders/110/toolpaths_cog.fs b/resources/shaders/110/toolpaths_cog.fs index 668fe03ecf..0c35b20b29 100644 --- a/resources/shaders/110/toolpaths_cog.fs +++ b/resources/shaders/110/toolpaths_cog.fs @@ -1,19 +1,16 @@ #version 110 -const vec4 BLACK = vec4(vec3(0.1), 1.0); -const vec4 WHITE = vec4(vec3(1.0), 1.0); +const vec3 BLACK = vec3(0.1); +const vec3 WHITE = vec3(0.9); const float emission_factor = 0.25; -uniform vec3 world_center; - // x = tainted, y = specular; varying vec2 intensity; -varying vec3 world_position; +varying vec3 position; void main() { - vec3 delta = world_position - world_center; - vec4 color = delta.x * delta.y * delta.z > 0.0 ? BLACK : WHITE; - gl_FragColor = vec4(vec3(intensity.y) + color.rgb * (intensity.x + emission_factor), 1.0); + vec3 color = position.x * position.y * position.z > 0.0 ? BLACK : WHITE; + gl_FragColor = vec4(vec3(intensity.y) + color * (intensity.x + emission_factor), 1.0); } diff --git a/resources/shaders/110/toolpaths_cog.vs b/resources/shaders/110/toolpaths_cog.vs index f37e796ab2..bec14df5e5 100644 --- a/resources/shaders/110/toolpaths_cog.vs +++ b/resources/shaders/110/toolpaths_cog.vs @@ -23,25 +23,25 @@ attribute vec3 v_normal; // x = tainted, y = specular; varying vec2 intensity; -varying vec3 world_position; +varying vec3 position; void main() { // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(view_normal_matrix * v_normal); + vec3 eye_normal = normalize(view_normal_matrix * v_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; - vec4 position = view_model_matrix * vec4(v_position, 1.0); - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); + vec4 eye_position = view_model_matrix * vec4(v_position, 1.0); + intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_position.xyz), 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; - world_position = v_position; - gl_Position = projection_matrix * position; + position = v_position; + gl_Position = projection_matrix * eye_position; } diff --git a/resources/shaders/140/toolpaths_cog.fs b/resources/shaders/140/toolpaths_cog.fs index 010abe9711..62067e1dff 100644 --- a/resources/shaders/140/toolpaths_cog.fs +++ b/resources/shaders/140/toolpaths_cog.fs @@ -1,21 +1,18 @@ #version 140 -const vec4 BLACK = vec4(vec3(0.1), 1.0); -const vec4 WHITE = vec4(vec3(1.0), 1.0); +const vec3 BLACK = vec3(0.1); +const vec3 WHITE = vec3(0.9); const float emission_factor = 0.25; -uniform vec3 world_center; - // x = tainted, y = specular; in vec2 intensity; -in vec3 world_position; +in vec3 position; out vec4 out_color; void main() { - vec3 delta = world_position - world_center; - vec4 color = delta.x * delta.y * delta.z > 0.0 ? BLACK : WHITE; - out_color = vec4(vec3(intensity.y) + color.rgb * (intensity.x + emission_factor), 1.0); + vec3 color = position.x * position.y * position.z > 0.0 ? BLACK : WHITE; + out_color = vec4(vec3(intensity.y) + color * (intensity.x + emission_factor), 1.0); } diff --git a/resources/shaders/140/toolpaths_cog.vs b/resources/shaders/140/toolpaths_cog.vs index a39595ebf5..66109f1704 100644 --- a/resources/shaders/140/toolpaths_cog.vs +++ b/resources/shaders/140/toolpaths_cog.vs @@ -23,25 +23,25 @@ in vec3 v_normal; // x = tainted, y = specular; out vec2 intensity; -out vec3 world_position; +out vec3 position; void main() { // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(view_normal_matrix * v_normal); + vec3 eye_normal = normalize(view_normal_matrix * v_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; - vec4 position = view_model_matrix * vec4(v_position, 1.0); - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); + vec4 eye_position = view_model_matrix * vec4(v_position, 1.0); + intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_position.xyz), 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; - world_position = v_position; - gl_Position = projection_matrix * position; + position = v_position; + gl_Position = projection_matrix * eye_position; } diff --git a/resources/shaders/ES/toolpaths_cog.fs b/resources/shaders/ES/toolpaths_cog.fs index f5e4404be9..e815a198d9 100644 --- a/resources/shaders/ES/toolpaths_cog.fs +++ b/resources/shaders/ES/toolpaths_cog.fs @@ -2,20 +2,17 @@ precision highp float; -const vec4 BLACK = vec4(vec3(0.1), 1.0); -const vec4 WHITE = vec4(vec3(1.0), 1.0); +const vec3 BLACK = vec3(0.1); +const vec3 WHITE = vec3(0.9); const float emission_factor = 0.25; -uniform vec3 world_center; - // x = tainted, y = specular; varying vec2 intensity; -varying vec3 world_position; +varying vec3 position; void main() { - vec3 delta = world_position - world_center; - vec4 color = delta.x * delta.y * delta.z > 0.0 ? BLACK : WHITE; - gl_FragColor = vec4(vec3(intensity.y) + color.rgb * (intensity.x + emission_factor), 1.0); + vec3 color = position.x * position.y * position.z > 0.0 ? BLACK : WHITE; + gl_FragColor = vec4(vec3(intensity.y) + color * (intensity.x + emission_factor), 1.0); } diff --git a/resources/shaders/ES/toolpaths_cog.vs b/resources/shaders/ES/toolpaths_cog.vs index 72b5835bdd..f4ce00160c 100644 --- a/resources/shaders/ES/toolpaths_cog.vs +++ b/resources/shaders/ES/toolpaths_cog.vs @@ -23,25 +23,25 @@ attribute vec3 v_normal; // x = tainted, y = specular; varying vec2 intensity; -varying vec3 world_position; +varying vec3 position; void main() { // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(view_normal_matrix * v_normal); + vec3 eye_normal = normalize(view_normal_matrix * v_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; - vec4 position = view_model_matrix * vec4(v_position, 1.0); - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); + vec4 eye_position = view_model_matrix * vec4(v_position, 1.0); + intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_position.xyz), 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; - world_position = v_position; - gl_Position = projection_matrix * position; + position = v_position; + gl_Position = projection_matrix * eye_position; }