-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrag.glsl
More file actions
45 lines (33 loc) · 1.04 KB
/
frag.glsl
File metadata and controls
45 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#version 300 es
precision highp float;
in float v_height;
in vec3 v_local_pos;
in float v_primitiveID;
uniform int u_display;
uniform vec3 u_light_direction;
uniform vec3 u_top_color;
uniform vec3 u_bottom_color;
out vec4 fragColor;
vec3 intToColor(int i) {
int r = (i * 127) & 255;
int g = (i * 251) & 255;
int b = (i * 373) & 255;
return vec3(float(r), float(g), float(b)) / 255.0;
}
void main() {
vec4 low_color = vec4(u_bottom_color, 1.0);
vec4 high_color = vec4(u_top_color, 1.0);
vec3 light_dir = normalize(u_light_direction);
vec3 normal = normalize(cross(dFdx(v_local_pos), dFdy(v_local_pos)));
float diffuse = dot(normal, light_dir);
if (u_display == 0 || u_display == 4) {
fragColor = mix(low_color, high_color, v_height);
fragColor.rgb *= 0.5 + 0.5 * (1.0 - diffuse);
} else if (u_display == 1) {
fragColor = vec4(vec3(diffuse), 1.0);
} else if (u_display == 2) {
fragColor = vec4(0.5 + 0.5 * normal, 1.0);
} else if (u_display == 3) {
fragColor = vec4(intToColor(int(v_primitiveID)), 1.0);
}
}