-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathExample.frag
46 lines (36 loc) · 886 Bytes
/
Example.frag
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
// GLSL fragment shader
#version 140
#ifdef GL_ES
precision mediump float;
precision mediump sampler2DArray;
#endif
layout(std140) uniform Settings
{
mat4 vpMatrix;
vec4 viewPos;
vec4 fogColorAndDensity;
vec2 animVec;
};
uniform sampler2DArray tex;
// Fragment input from the vertex shader
in vec4 vWorldPos;
in vec3 vTexCoord;
in vec3 vColor;
// Fragment output color
out vec4 fragColor;
// Fragment shader main function
void main()
{
// Sample albedo texture
vec4 color = texture(tex, vTexCoord);
// Apply alpha clipping
if (color.a < 0.5)
discard;
// Compute fog density
float viewDist = distance(viewPos, vWorldPos);
float fog = viewDist*fogColorAndDensity.a;
fog = 1.0 - 1.0/exp(fog*fog);
// Interpolate between albedo and fog color
color.rgb = mix(color.rgb * vColor, fogColorAndDensity.rgb, fog);
fragColor = color;
}