2015-12-15 01:33:16 +00:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
// Input
|
2016-12-24 10:05:51 +00:00
|
|
|
in vec4 LightColor;
|
2015-12-15 01:33:16 +00:00
|
|
|
|
|
|
|
// Output
|
|
|
|
out vec4 PixelColor;
|
|
|
|
|
|
|
|
// Uniforms
|
|
|
|
uniform vec4 TintColor;
|
|
|
|
|
2016-12-25 21:47:59 +00:00
|
|
|
// Functions
|
|
|
|
float InterpolateDecelerate(float Min, float Max, float t, float Factor)
|
|
|
|
{
|
|
|
|
float Alpha = (1.0 - pow(1.0 - t, Factor));
|
|
|
|
return mix(Min, Max, Alpha);
|
|
|
|
}
|
|
|
|
|
2015-12-15 01:33:16 +00:00
|
|
|
// Main
|
|
|
|
void main()
|
|
|
|
{
|
2016-12-25 21:47:59 +00:00
|
|
|
const float kMaxDepth = 75.0; // Controls the max depth range that kDepthTintNear and kDepthTintFar are interpolated between
|
|
|
|
const float kDepthTintNear = 0.0; // Sets the pixel color offset for pixels close to the screen
|
|
|
|
const float kDepthTintFar = -0.2; // Sets the pixel color offset for pixels far from the screen
|
|
|
|
const float kDepthCurveFactor = 2; // Controls the strength of the interpolation curve (higher = color chabges faster from up close and slower from further away)
|
|
|
|
|
|
|
|
// Apply some fake fog so pixels closer to the camera appear slightly brighter
|
|
|
|
float Depth = ( (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) / (gl_DepthRange.far - gl_DepthRange.near) ) / gl_FragCoord.w;
|
|
|
|
float DepthAlpha = min(Depth, kMaxDepth) / kMaxDepth;
|
|
|
|
DepthAlpha = clamp(DepthAlpha, 0.0, 1.0);
|
|
|
|
float DepthTint = InterpolateDecelerate(kDepthTintNear, kDepthTintFar, DepthAlpha, kDepthCurveFactor);
|
|
|
|
PixelColor = (LightColor + vec4(DepthTint, DepthTint, DepthTint, 1.0)) * TintColor;
|
2015-12-15 01:33:16 +00:00
|
|
|
}
|