Page MenuHomec4science

shader.frag
No OneTemporary

File Metadata

Created
Fri, Nov 8, 23:55

shader.frag

precision highp float;
in vec2 texCoordHack;
const float texCoordHackScale = 0.05;
uniform vec4 CameraEye;
uniform vec4 FogColor;
uniform vec2 FogBounds;
uniform sampler2D causticsTexture;
uniform float time;
uniform float causticsScale;
uniform float causticsAmount;
const float timeScale = 0.04;
in vec4 sVertex;
float getFogFactor(float d) {
float FogMax = FogBounds.y;
float FogMin = FogBounds.x;
if (d>=FogMax) return 1.0;
if (d<=FogMin) return 0.0;
return 1.0 - pow((FogMax - d) / (FogMax - FogMin), 3.0);
}
vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
vec4 c = graphicsColor * lovrDiffuseColor * vertexColor * texture(image, uv);
// apply caustics
float t = time * timeScale;
vec2 texUV = texCoordHack;
c += min(
texture(causticsTexture, texUV / texCoordHackScale * causticsScale + vec2(t, 2.0 + t)),
texture(causticsTexture, texUV / texCoordHackScale * causticsScale + vec2(-t / 2.0, -t))
) * 2.0 * causticsAmount;
// apply fog
float d = distance(CameraEye, sVertex);
float alpha = getFogFactor(d);
c = mix(c, FogColor, alpha);
return c;
}

Event Timeline