2014-05-12 12:45:41 +00:00
|
|
|
in vec4 pixelpos;
|
2017-01-28 17:19:58 +00:00
|
|
|
in vec3 glowdist;
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2016-10-03 14:09:32 +00:00
|
|
|
in vec4 vWorldNormal;
|
|
|
|
in vec4 vEyeNormal;
|
2014-07-14 22:19:41 +00:00
|
|
|
in vec4 vTexCoord;
|
|
|
|
in vec4 vColor;
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-07-14 23:05:53 +00:00
|
|
|
out vec4 FragColor;
|
2016-09-20 00:57:57 +00:00
|
|
|
#ifdef GBUFFER_PASS
|
2016-10-05 05:57:27 +00:00
|
|
|
out vec4 FragFog;
|
|
|
|
out vec4 FragNormal;
|
2016-09-20 00:57:57 +00:00
|
|
|
#endif
|
2014-07-14 23:05:53 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
#ifdef SHADER_STORAGE_LIGHTS
|
2014-08-01 18:59:39 +00:00
|
|
|
layout(std430, binding = 1) buffer LightBufferSSO
|
2014-05-12 12:45:41 +00:00
|
|
|
{
|
|
|
|
vec4 lights[];
|
|
|
|
};
|
2016-04-26 09:31:27 +00:00
|
|
|
#elif defined NUM_UBO_LIGHTS
|
2014-09-20 07:10:01 +00:00
|
|
|
/*layout(std140)*/ uniform LightBufferUBO
|
2014-08-01 18:59:39 +00:00
|
|
|
{
|
|
|
|
vec4 lights[NUM_UBO_LIGHTS];
|
|
|
|
};
|
2013-06-23 09:13:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
uniform sampler2D tex;
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
vec4 Process(vec4 color);
|
|
|
|
vec4 ProcessTexel();
|
|
|
|
vec4 ProcessLight(vec4 color);
|
2013-06-23 09:13:01 +00:00
|
|
|
|
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Desaturate a color
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
vec4 desaturate(vec4 texel)
|
|
|
|
{
|
|
|
|
if (uDesaturationFactor > 0.0)
|
|
|
|
{
|
2014-05-21 13:25:25 +00:00
|
|
|
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
|
|
|
return mix (texel, vec4(gray,gray,gray,texel.a), uDesaturationFactor);
|
2014-05-12 12:45:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return texel;
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// This function is common for all (non-special-effect) fragment shaders
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
vec4 getTexel(vec2 st)
|
|
|
|
{
|
2014-11-28 11:28:45 +00:00
|
|
|
vec4 texel = texture(tex, st);
|
2014-05-12 12:45:41 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Apply texture modes
|
|
|
|
//
|
|
|
|
switch (uTextureMode)
|
|
|
|
{
|
2014-09-09 11:21:36 +00:00
|
|
|
case 1: // TM_MASK
|
2014-05-12 12:45:41 +00:00
|
|
|
texel.rgb = vec3(1.0,1.0,1.0);
|
|
|
|
break;
|
|
|
|
|
2014-09-09 11:21:36 +00:00
|
|
|
case 2: // TM_OPAQUE
|
2014-05-12 12:45:41 +00:00
|
|
|
texel.a = 1.0;
|
|
|
|
break;
|
|
|
|
|
2014-09-09 11:21:36 +00:00
|
|
|
case 3: // TM_INVERSE
|
2014-05-12 12:45:41 +00:00
|
|
|
texel = vec4(1.0-texel.r, 1.0-texel.b, 1.0-texel.g, texel.a);
|
|
|
|
break;
|
2014-09-09 11:21:36 +00:00
|
|
|
|
|
|
|
case 4: // TM_REDTOALPHA
|
2014-10-26 20:17:29 +00:00
|
|
|
texel = vec4(1.0, 1.0, 1.0, texel.r*texel.a);
|
2014-09-09 11:21:36 +00:00
|
|
|
break;
|
2014-09-21 09:08:17 +00:00
|
|
|
|
|
|
|
case 5: // TM_CLAMPY
|
|
|
|
if (st.t < 0.0 || st.t > 1.0)
|
|
|
|
{
|
|
|
|
texel.a = 0.0;
|
|
|
|
}
|
|
|
|
break;
|
2014-05-12 12:45:41 +00:00
|
|
|
}
|
2017-01-28 17:19:58 +00:00
|
|
|
if (uObjectColor2.a == 0) texel *= uObjectColor;
|
|
|
|
else texel *= mix(uObjectColor, uObjectColor2, glowdist.z);
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
return desaturate(texel);
|
|
|
|
}
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
2016-07-23 14:30:28 +00:00
|
|
|
// Doom lighting equation exactly as calculated by zdoom.
|
2014-05-12 12:45:41 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
2016-07-23 14:30:28 +00:00
|
|
|
float R_DoomLightingEquation(float light)
|
2013-06-23 09:13:01 +00:00
|
|
|
{
|
2016-07-23 14:30:28 +00:00
|
|
|
// Calculated from r_visibility. It differs between walls, floor and sprites.
|
|
|
|
//
|
|
|
|
// Wall: globVis = r_WallVisibility
|
|
|
|
// Floor: r_FloorVisibility / abs(plane.Zat0 - ViewPos.Z)
|
|
|
|
// Sprite: same as wall
|
|
|
|
// All are calculated in R_SetVisibility and seem to be decided by the
|
|
|
|
// aspect ratio amongst other things.
|
|
|
|
//
|
|
|
|
// 1706 is the value for walls on 1080p 16:9 displays.
|
|
|
|
float globVis = 1706.0;
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2016-07-23 14:30:28 +00:00
|
|
|
/* L is the integer light level used in the game */
|
|
|
|
float L = light * 255.0;
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2016-07-23 14:30:28 +00:00
|
|
|
/* z is the depth in view/eye space, positive going into the screen */
|
|
|
|
float z = pixelpos.w;
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2016-07-23 14:30:28 +00:00
|
|
|
/* The zdoom light equation */
|
|
|
|
float vis = globVis / z;
|
2016-07-23 15:19:07 +00:00
|
|
|
float shade = 64.0 - (L + 12.0) * 32.0/128.0;
|
2017-01-24 18:44:12 +00:00
|
|
|
float lightscale;
|
|
|
|
if (uPalLightLevels != 0)
|
2017-01-24 19:01:42 +00:00
|
|
|
lightscale = clamp(float(int(shade - min(24.0, vis))) / 32.0, 0.0, 31.0/32.0);
|
2017-01-24 18:44:12 +00:00
|
|
|
else
|
|
|
|
lightscale = clamp((shade - min(24.0, vis)) / 32.0, 0.0, 31.0/32.0);
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2016-07-23 14:30:28 +00:00
|
|
|
// Result is the normalized colormap index (0 bright .. 1 dark)
|
|
|
|
return lightscale;
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 14:09:32 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Standard lambertian diffuse light calculation
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
float diffuseContribution(vec3 lightDirection, vec3 normal)
|
|
|
|
{
|
|
|
|
return max(dot(normal, lightDirection), 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Calculates the brightness of a dynamic point light
|
|
|
|
// Todo: Find a better way to define which lighting model to use.
|
|
|
|
// (Specular mode has been removed for now.)
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2016-10-23 18:42:48 +00:00
|
|
|
float pointLightAttenuation(vec4 lightpos, float attenuate)
|
2016-10-03 14:09:32 +00:00
|
|
|
{
|
|
|
|
float attenuation = max(lightpos.w - distance(pixelpos.xyz, lightpos.xyz),0.0) / lightpos.w;
|
2017-03-02 17:07:47 +00:00
|
|
|
if (attenuate >= 0.0) // Sign bit is the attenuate flag
|
2016-10-23 18:42:48 +00:00
|
|
|
{
|
2016-10-03 14:09:32 +00:00
|
|
|
return attenuation;
|
2016-10-23 18:42:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-03 14:09:32 +00:00
|
|
|
vec3 lightDirection = normalize(lightpos.xyz - pixelpos.xyz);
|
|
|
|
float diffuseAmount = diffuseContribution(lightDirection, normalize(vWorldNormal.xyz));
|
|
|
|
return attenuation * diffuseAmount;
|
2016-10-23 18:42:48 +00:00
|
|
|
}
|
2016-10-03 14:09:32 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 09:13:01 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
2014-05-12 12:45:41 +00:00
|
|
|
// Calculate light
|
2013-06-23 09:13:01 +00:00
|
|
|
//
|
2014-05-12 12:45:41 +00:00
|
|
|
// It is important to note that the light color is not desaturated
|
|
|
|
// due to ZDoom's implementation weirdness. Everything that's added
|
|
|
|
// on top of it, e.g. dynamic lights and glows are, though, because
|
|
|
|
// the objects emitting these lights are also.
|
2013-06-23 09:13:01 +00:00
|
|
|
//
|
2014-05-12 12:45:41 +00:00
|
|
|
// This is making this a bit more complicated than it needs to
|
|
|
|
// because we can't just desaturate the final fragment color.
|
2013-06-23 09:13:01 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
vec4 getLightColor(float fogdist, float fogfactor)
|
|
|
|
{
|
2014-07-14 22:19:41 +00:00
|
|
|
vec4 color = vColor;
|
2014-05-12 12:45:41 +00:00
|
|
|
|
|
|
|
if (uLightLevel >= 0.0)
|
2013-06-23 09:13:01 +00:00
|
|
|
{
|
2016-07-23 14:30:28 +00:00
|
|
|
float newlightlevel = 1.0 - R_DoomLightingEquation(uLightLevel);
|
2014-05-12 12:45:41 +00:00
|
|
|
color.rgb *= newlightlevel;
|
|
|
|
}
|
2016-04-26 13:01:23 +00:00
|
|
|
else if (uFogEnabled > 0)
|
2014-05-12 12:45:41 +00:00
|
|
|
{
|
|
|
|
// brightening around the player for light mode 2
|
|
|
|
if (fogdist < uLightDist)
|
|
|
|
{
|
|
|
|
color.rgb *= uLightFactor - (fogdist / uLightDist) * (uLightFactor - 1.0);
|
|
|
|
}
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
//
|
|
|
|
// apply light diminishing through fog equation
|
|
|
|
//
|
2013-06-23 09:13:01 +00:00
|
|
|
color.rgb = mix(vec3(0.0, 0.0, 0.0), color.rgb, fogfactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// handle glowing walls
|
|
|
|
//
|
2014-05-12 12:45:41 +00:00
|
|
|
if (uGlowTopColor.a > 0.0 && glowdist.x < uGlowTopColor.a)
|
2013-06-23 09:13:01 +00:00
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
color.rgb += desaturate(uGlowTopColor * (1.0 - glowdist.x / uGlowTopColor.a)).rgb;
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
2014-05-12 12:45:41 +00:00
|
|
|
if (uGlowBottomColor.a > 0.0 && glowdist.y < uGlowBottomColor.a)
|
2013-06-23 09:13:01 +00:00
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
color.rgb += desaturate(uGlowBottomColor * (1.0 - glowdist.y / uGlowBottomColor.a)).rgb;
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
|
|
|
color = min(color, 1.0);
|
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
//
|
|
|
|
// apply brightmaps (or other light manipulation by custom shaders.
|
|
|
|
//
|
|
|
|
color = ProcessLight(color);
|
2013-06-23 09:13:01 +00:00
|
|
|
|
|
|
|
//
|
2014-05-12 12:45:41 +00:00
|
|
|
// apply dynamic lights (except additive)
|
2013-06-23 09:13:01 +00:00
|
|
|
//
|
2014-05-12 12:45:41 +00:00
|
|
|
|
|
|
|
vec4 dynlight = uDynLightColor;
|
|
|
|
|
2016-04-26 09:31:27 +00:00
|
|
|
#if defined NUM_UBO_LIGHTS || defined SHADER_STORAGE_LIGHTS
|
2014-08-01 18:59:39 +00:00
|
|
|
if (uLightIndex >= 0)
|
2013-06-23 09:13:01 +00:00
|
|
|
{
|
2014-08-01 18:59:39 +00:00
|
|
|
ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
|
|
|
|
if (lightRange.z > lightRange.x)
|
2014-05-12 12:45:41 +00:00
|
|
|
{
|
2014-08-01 18:59:39 +00:00
|
|
|
//
|
|
|
|
// modulated lights
|
|
|
|
//
|
|
|
|
for(int i=lightRange.x; i<lightRange.y; i+=2)
|
|
|
|
{
|
|
|
|
vec4 lightpos = lights[i];
|
|
|
|
vec4 lightcolor = lights[i+1];
|
|
|
|
|
2016-10-23 18:42:48 +00:00
|
|
|
lightcolor.rgb *= pointLightAttenuation(lightpos, lightcolor.a);
|
2014-08-01 18:59:39 +00:00
|
|
|
dynlight.rgb += lightcolor.rgb;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// subtractive lights
|
|
|
|
//
|
|
|
|
for(int i=lightRange.y; i<lightRange.z; i+=2)
|
|
|
|
{
|
|
|
|
vec4 lightpos = lights[i];
|
|
|
|
vec4 lightcolor = lights[i+1];
|
|
|
|
|
2016-10-23 18:42:48 +00:00
|
|
|
lightcolor.rgb *= pointLightAttenuation(lightpos, lightcolor.a);
|
2014-08-01 18:59:39 +00:00
|
|
|
dynlight.rgb -= lightcolor.rgb;
|
|
|
|
}
|
2014-05-12 12:45:41 +00:00
|
|
|
}
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
2016-04-26 09:31:27 +00:00
|
|
|
#endif
|
2014-05-12 12:45:41 +00:00
|
|
|
color.rgb = clamp(color.rgb + desaturate(dynlight).rgb, 0.0, 1.4);
|
|
|
|
|
|
|
|
// prevent any unintentional messing around with the alpha.
|
2014-07-14 22:19:41 +00:00
|
|
|
return vec4(color.rgb, vColor.a);
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Applies colored fog
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
vec4 applyFog(vec4 frag, float fogfactor)
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
return vec4(mix(uFogColor.rgb, frag.rgb, fogfactor), frag.a);
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 00:04:56 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// The color of the fragment if it is fully occluded by ambient lighting
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
vec3 AmbientOcclusionColor()
|
|
|
|
{
|
|
|
|
float fogdist;
|
|
|
|
float fogfactor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// calculate fog factor
|
|
|
|
//
|
|
|
|
if (uFogEnabled == -1)
|
|
|
|
{
|
|
|
|
fogdist = pixelpos.w;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-13 16:08:04 +00:00
|
|
|
fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz));
|
2016-09-21 00:04:56 +00:00
|
|
|
}
|
|
|
|
fogfactor = exp2 (uFogDensity * fogdist);
|
|
|
|
|
|
|
|
return mix(uFogColor.rgb, vec3(0.0), fogfactor);
|
|
|
|
}
|
2013-06-23 09:13:01 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Main shader routine
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
vec4 frag = ProcessTexel();
|
2014-07-14 19:14:43 +00:00
|
|
|
|
2014-07-30 21:13:16 +00:00
|
|
|
#ifndef NO_ALPHATEST
|
2014-07-14 19:14:43 +00:00
|
|
|
if (frag.a <= uAlphaThreshold) discard;
|
|
|
|
#endif
|
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
switch (uFixedColormap)
|
2013-06-23 09:13:01 +00:00
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
case 0:
|
2014-05-11 11:27:51 +00:00
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
float fogdist = 0.0;
|
|
|
|
float fogfactor = 0.0;
|
|
|
|
|
2014-05-11 14:49:17 +00:00
|
|
|
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
//
|
|
|
|
// calculate fog factor
|
|
|
|
//
|
|
|
|
if (uFogEnabled != 0)
|
|
|
|
{
|
|
|
|
if (uFogEnabled == 1 || uFogEnabled == -1)
|
|
|
|
{
|
|
|
|
fogdist = pixelpos.w;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz));
|
|
|
|
}
|
|
|
|
fogfactor = exp2 (uFogDensity * fogdist);
|
|
|
|
}
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
|
|
|
|
frag *= getLightColor(fogdist, fogfactor);
|
|
|
|
|
2016-04-26 09:31:27 +00:00
|
|
|
#if defined NUM_UBO_LIGHTS || defined SHADER_STORAGE_LIGHTS
|
2014-08-01 18:59:39 +00:00
|
|
|
if (uLightIndex >= 0)
|
2014-05-12 12:45:41 +00:00
|
|
|
{
|
2014-08-01 18:59:39 +00:00
|
|
|
ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
|
|
|
|
if (lightRange.w > lightRange.z)
|
2014-05-12 12:45:41 +00:00
|
|
|
{
|
2014-08-01 18:59:39 +00:00
|
|
|
vec4 addlight = vec4(0.0,0.0,0.0,0.0);
|
|
|
|
|
|
|
|
//
|
|
|
|
// additive lights - these can be done after the alpha test.
|
|
|
|
//
|
|
|
|
for(int i=lightRange.z; i<lightRange.w; i+=2)
|
|
|
|
{
|
|
|
|
vec4 lightpos = lights[i];
|
|
|
|
vec4 lightcolor = lights[i+1];
|
|
|
|
|
2016-10-23 18:42:48 +00:00
|
|
|
lightcolor.rgb *= pointLightAttenuation(lightpos, lightcolor.a);
|
2014-08-01 18:59:39 +00:00
|
|
|
addlight.rgb += lightcolor.rgb;
|
|
|
|
}
|
|
|
|
frag.rgb = clamp(frag.rgb + desaturate(addlight).rgb, 0.0, 1.0);
|
2014-05-12 12:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-26 09:31:27 +00:00
|
|
|
#endif
|
2014-05-12 12:45:41 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// colored fog
|
|
|
|
//
|
|
|
|
if (uFogEnabled < 0)
|
|
|
|
{
|
|
|
|
frag = applyFog(frag, fogfactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
2014-05-12 12:45:41 +00:00
|
|
|
|
|
|
|
case 1:
|
2013-06-23 09:13:01 +00:00
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
float gray = (frag.r * 0.3 + frag.g * 0.56 + frag.b * 0.14);
|
|
|
|
vec4 cm = uFixedColormapStart + gray * uFixedColormapRange;
|
2014-07-14 22:19:41 +00:00
|
|
|
frag = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a*vColor.a);
|
2014-05-12 12:45:41 +00:00
|
|
|
break;
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
case 2:
|
|
|
|
{
|
2014-10-05 07:40:36 +00:00
|
|
|
frag = vColor * frag * uFixedColormapStart;
|
2014-05-12 12:45:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-23 09:13:01 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
case 3:
|
2013-06-23 09:13:01 +00:00
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
float fogdist;
|
|
|
|
float fogfactor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// calculate fog factor
|
|
|
|
//
|
|
|
|
if (uFogEnabled == -1)
|
|
|
|
{
|
|
|
|
fogdist = pixelpos.w;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz));
|
|
|
|
}
|
|
|
|
fogfactor = exp2 (uFogDensity * fogdist);
|
|
|
|
|
2014-07-14 22:19:41 +00:00
|
|
|
frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a);
|
2014-05-12 12:45:41 +00:00
|
|
|
break;
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
2014-05-12 12:45:41 +00:00
|
|
|
}
|
2014-07-14 23:05:53 +00:00
|
|
|
FragColor = frag;
|
2016-09-20 00:57:57 +00:00
|
|
|
#ifdef GBUFFER_PASS
|
2016-10-05 05:57:27 +00:00
|
|
|
FragFog = vec4(AmbientOcclusionColor(), 1.0);
|
|
|
|
FragNormal = vec4(vEyeNormal.xyz * 0.5 + 0.5, 1.0);
|
2016-09-20 00:57:57 +00:00
|
|
|
#endif
|
2013-06-23 09:13:01 +00:00
|
|
|
}
|
2014-05-12 12:45:41 +00:00
|
|
|
|