This commit is contained in:
2019-10-03 16:25:28 +02:00
parent 13dedc1b27
commit ebb55da52c
4 changed files with 78 additions and 13 deletions
+47 -3
View File
@@ -1,31 +1,75 @@
#version 140
#extension GL_OES_standard_derivatives : enable
uniform sampler2D tex;
uniform vec3 diffuse;
in vec3 v_normal;
in vec2 v_tex_coords;
in vec3 v_barycentric;
in vec4 v_position;
out vec4 color;
vec4 wireframe_color;
vec4 render_color;
vec3 ambientLight = vec3(0.3,0.3,0.3);
vec3 directionnalLight = normalize(vec3(10,5,7));
vec3 directionnalLightFactor = vec3(0.6,0.6,0.6);
// float edgeFactor(vec3 a){
// vec3 d = fwidth(v_barycentric);
// vec3 a3 = smoothstep(vec3(0.0), d*1.5, v_barycentric);
// return min(min(a3.x, a3.y), a3.z);
// }
void main() {
vec3 d = fwidth(v_barycentric);
vec3 a3 = smoothstep(vec3(0.0), 0.8 * d, v_barycentric);
float scale = (1 - min(min(a3.x, a3.y), a3.z)) / 2 + 0.5;
wireframe_color = vec4(scale, scale, scale, 1.0);
// float threshold = 0.1;
// vec3 d = fwidth(v_barycentric);
// if (d.x < threshold || d.y < threshold || d.z < threshold) {
// wireframe_color = vec4(1.0, 1.0, 1.0, 1.0);
// } else {
// wireframe_color = vec4(0.5, 0.5, 0.5, 1.0);
// }
vec3 lambertComponent = dot(directionnalLight, v_normal) * directionnalLightFactor;
lambertComponent = max(vec3(0.0, 0.0, 0.0), lambertComponent);
vec4 factor = vec4(ambientLight + lambertComponent, 1.0);
color = factor * vec4(diffuse, 1.0) * texture(tex, v_tex_coords);
render_color = factor * vec4(diffuse, 1.0) * texture(tex, v_tex_coords);
if (color.a < 0.05) {
if (render_color.a < 0.05) {
discard;
} else {
color.a = 1.0;
render_color.a = 1.0;
}
float z_min = 0.15;
float z_max = 0.25;
float lambda = (v_position.z - z_min) / (z_max - z_min);
if (lambda < 0) {
lambda = 0;
}
if (lambda > 1) {
lambda = 1;
}
color = lambda * wireframe_color + (1 - lambda) * render_color;
}
+5
View File
@@ -6,14 +6,19 @@ uniform vec3 texture_size;
in vec3 vertex;
in vec2 tex_coords;
in vec3 barycentric;
in vec3 normal;
out vec2 v_tex_coords;
out vec3 v_normal;
out vec3 v_barycentric;
out vec4 v_position;
void main() {
v_normal = normal;
v_barycentric = barycentric;
v_tex_coords = vec2(tex_coords.x * texture_size.x, tex_coords.y * texture_size.y);
gl_Position = perspective * view * vec4(vertex, 1.0);
v_position = gl_Position;
}