Fixed toolpaths_cog shaders

This commit is contained in:
enricoturri1966 2023-10-31 12:02:42 +01:00 committed by Lukas Matena
parent c8601fbc4a
commit ddabc3312d
6 changed files with 39 additions and 48 deletions

View File

@ -1,19 +1,16 @@
#version 110 #version 110
const vec4 BLACK = vec4(vec3(0.1), 1.0); const vec3 BLACK = vec3(0.1);
const vec4 WHITE = vec4(vec3(1.0), 1.0); const vec3 WHITE = vec3(0.9);
const float emission_factor = 0.25; const float emission_factor = 0.25;
uniform vec3 world_center;
// x = tainted, y = specular; // x = tainted, y = specular;
varying vec2 intensity; varying vec2 intensity;
varying vec3 world_position; varying vec3 position;
void main() void main()
{ {
vec3 delta = world_position - world_center; vec3 color = position.x * position.y * position.z > 0.0 ? BLACK : WHITE;
vec4 color = delta.x * delta.y * delta.z > 0.0 ? BLACK : WHITE; gl_FragColor = vec4(vec3(intensity.y) + color * (intensity.x + emission_factor), 1.0);
gl_FragColor = vec4(vec3(intensity.y) + color.rgb * (intensity.x + emission_factor), 1.0);
} }

View File

@ -23,25 +23,25 @@ attribute vec3 v_normal;
// x = tainted, y = specular; // x = tainted, y = specular;
varying vec2 intensity; varying vec2 intensity;
varying vec3 world_position; varying vec3 position;
void main() void main()
{ {
// First transform the normal into camera space and normalize the result. // 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. // 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. // 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.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 position = view_model_matrix * vec4(v_position, 1.0); vec4 eye_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); 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). // 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; intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
world_position = v_position; position = v_position;
gl_Position = projection_matrix * position; gl_Position = projection_matrix * eye_position;
} }

View File

@ -1,21 +1,18 @@
#version 140 #version 140
const vec4 BLACK = vec4(vec3(0.1), 1.0); const vec3 BLACK = vec3(0.1);
const vec4 WHITE = vec4(vec3(1.0), 1.0); const vec3 WHITE = vec3(0.9);
const float emission_factor = 0.25; const float emission_factor = 0.25;
uniform vec3 world_center;
// x = tainted, y = specular; // x = tainted, y = specular;
in vec2 intensity; in vec2 intensity;
in vec3 world_position; in vec3 position;
out vec4 out_color; out vec4 out_color;
void main() void main()
{ {
vec3 delta = world_position - world_center; vec3 color = position.x * position.y * position.z > 0.0 ? BLACK : WHITE;
vec4 color = delta.x * delta.y * delta.z > 0.0 ? BLACK : WHITE; out_color = vec4(vec3(intensity.y) + color * (intensity.x + emission_factor), 1.0);
out_color = vec4(vec3(intensity.y) + color.rgb * (intensity.x + emission_factor), 1.0);
} }

View File

@ -23,25 +23,25 @@ in vec3 v_normal;
// x = tainted, y = specular; // x = tainted, y = specular;
out vec2 intensity; out vec2 intensity;
out vec3 world_position; out vec3 position;
void main() void main()
{ {
// First transform the normal into camera space and normalize the result. // 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. // 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. // 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.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 position = view_model_matrix * vec4(v_position, 1.0); vec4 eye_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); 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). // 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; intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
world_position = v_position; position = v_position;
gl_Position = projection_matrix * position; gl_Position = projection_matrix * eye_position;
} }

View File

@ -2,20 +2,17 @@
precision highp float; precision highp float;
const vec4 BLACK = vec4(vec3(0.1), 1.0); const vec3 BLACK = vec3(0.1);
const vec4 WHITE = vec4(vec3(1.0), 1.0); const vec3 WHITE = vec3(0.9);
const float emission_factor = 0.25; const float emission_factor = 0.25;
uniform vec3 world_center;
// x = tainted, y = specular; // x = tainted, y = specular;
varying vec2 intensity; varying vec2 intensity;
varying vec3 world_position; varying vec3 position;
void main() void main()
{ {
vec3 delta = world_position - world_center; vec3 color = position.x * position.y * position.z > 0.0 ? BLACK : WHITE;
vec4 color = delta.x * delta.y * delta.z > 0.0 ? BLACK : WHITE; gl_FragColor = vec4(vec3(intensity.y) + color * (intensity.x + emission_factor), 1.0);
gl_FragColor = vec4(vec3(intensity.y) + color.rgb * (intensity.x + emission_factor), 1.0);
} }

View File

@ -23,25 +23,25 @@ attribute vec3 v_normal;
// x = tainted, y = specular; // x = tainted, y = specular;
varying vec2 intensity; varying vec2 intensity;
varying vec3 world_position; varying vec3 position;
void main() void main()
{ {
// First transform the normal into camera space and normalize the result. // 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. // 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. // 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.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 position = view_model_matrix * vec4(v_position, 1.0); vec4 eye_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); 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). // 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; intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
world_position = v_position; position = v_position;
gl_Position = projection_matrix * position; gl_Position = projection_matrix * eye_position;
} }