Basic flashlight
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec3 fragPosition;
|
||||
|
||||
// Input uniform values
|
||||
uniform samplerCube environmentMap;
|
||||
uniform bool vflipped;
|
||||
uniform bool doGamma;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Fetch color from texture map
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
if (vflipped) color = texture(environmentMap, vec3(fragPosition.x, -fragPosition.y, fragPosition.z)).rgb;
|
||||
else color = texture(environmentMap, fragPosition).rgb;
|
||||
|
||||
if (doGamma)// Apply gamma correction
|
||||
{
|
||||
color = color/(color + vec3(1.0));
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
}
|
||||
|
||||
// Calculate final fragment color
|
||||
finalColor = vec4(color, 1.0);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 matProjection;
|
||||
uniform mat4 matView;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec3 fragPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Calculate fragment position based on model transformations
|
||||
fragPosition = vertexPosition;
|
||||
|
||||
// Remove translation from the view matrix
|
||||
mat4 rotView = mat4(mat3(matView));
|
||||
vec4 clipPos = matProjection*rotView*vec4(vertexPosition, 1.0);
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = clipPos;
|
||||
}
|
||||
Reference in New Issue
Block a user