-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid_fshader.glsl
More file actions
52 lines (40 loc) · 1.55 KB
/
grid_fshader.glsl
File metadata and controls
52 lines (40 loc) · 1.55 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
46
47
48
49
50
51
52
#version 150
// Include the following line to declare the texture function
#extension GL_ARB_texture_query_lod : enable
// Inputs from the vertex shader
in vec3 v_position;
in vec3 v_normal;
in vec2 Tex;
out vec4 fragColor;
// Uniforms
uniform vec3 light_position;
uniform float maxHeight;
uniform sampler2D gTextureHeight0;
uniform sampler2D gTextureHeight1;
uniform sampler2D gTextureHeight2;
uniform sampler2D gTextureHeight3;
vec4 CalcTexColor() {
vec4 TexColor;
float Height = v_position.y;
// Define thresholds as percentages of maxHeight
float heightThreshold1 = maxHeight * 0.05;
float heightThreshold2 = maxHeight * 0.40;
float heightThreshold3 = maxHeight * 0.55;
if (Height < heightThreshold1) {
TexColor = texture2D(gTextureHeight0, Tex);
} else if (Height < heightThreshold2) {
TexColor = mix(texture2D(gTextureHeight0, Tex), texture2D(gTextureHeight1, Tex), (Height - heightThreshold1) / (heightThreshold2 - heightThreshold1));
} else if (Height < heightThreshold3) {
TexColor = mix(texture2D(gTextureHeight1, Tex), texture2D(gTextureHeight2, Tex), (Height - heightThreshold2) / (heightThreshold3 - heightThreshold2));
} else {
TexColor = texture2D(gTextureHeight3, Tex);
}
return TexColor;
}
void main() {
vec4 TexColor = CalcTexColor();
vec3 L = normalize(light_position - v_position); // Direction to the light
float NL = max(dot(normalize(v_normal), L), 0.0); // Diffuse lighting factor
vec3 litColor = TexColor.rgb * NL;
fragColor = vec4(litColor, 1);
}