Variable fog of war
This commit is contained in:
32
resources/shaders/fog.fs
Normal file
32
resources/shaders/fog.fs
Normal file
@@ -0,0 +1,32 @@
|
||||
#version 330
|
||||
|
||||
in vec3 vWorldPos;
|
||||
in vec2 vTexCoord;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec3 u_playerPos; // player world pos
|
||||
uniform float u_inner; // start of vignette (m)
|
||||
uniform float u_outer; // end of vignette (m) u_outer > u_inner
|
||||
uniform float u_minShadow; // baseline darkness at center [0..1], e.g. 0.15
|
||||
uniform vec4 u_fogColor; // usually vec4(0,0,0,1)
|
||||
uniform float u_alphaCutoff; // for trees/billboards too
|
||||
|
||||
out vec4 finalColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texel = texture(texture0, vTexCoord);
|
||||
if (texel.a < u_alphaCutoff) discard;
|
||||
|
||||
// distance on the ground plane
|
||||
float distXZ = length(vWorldPos.xz - u_playerPos.xz);
|
||||
|
||||
// 0 at u_inner, 1 at u_outer
|
||||
float t = smoothstep(u_inner, u_outer, distXZ);
|
||||
|
||||
// add baseline shadow so center is not fully bright
|
||||
t = u_minShadow + (1.0 - u_minShadow) * t;
|
||||
|
||||
vec3 rgb = mix(texel.rgb, u_fogColor.rgb, t);
|
||||
finalColor = vec4(rgb, texel.a);
|
||||
}
|
||||
16
resources/shaders/fog.vs
Normal file
16
resources/shaders/fog.vs
Normal file
@@ -0,0 +1,16 @@
|
||||
#version 330
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
|
||||
uniform mat4 matModel, matView, matProjection;
|
||||
|
||||
out vec3 vWorldPos;
|
||||
out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 world = matModel * vec4(vertexPosition, 1.0);
|
||||
vWorldPos = world.xyz;
|
||||
vTexCoord = vertexTexCoord;
|
||||
gl_Position = matProjection * matView * world;
|
||||
}
|
||||
Reference in New Issue
Block a user