@@ -146,6 +146,7 @@ out vec4 fragOut0;
146146out vec4 fragOut1;
147147out vec4 fragOut2;
148148out vec4 fragOut3;
149+ out vec4 fragOut4;
149150
150151vec3 FresnelLazarovEnv(vec3 specColor, vec3 view, vec3 normal, float gloss)
151152{
@@ -213,12 +214,15 @@ void main()
213214#ifdef FLAG_SHADOW_MAP
214215 // need depth and depth squared for variance shadow maps
215216 fragOut0 = vec4(fragPosition.z, fragPosition.z * fragPosition.z * VARIANCE_SHADOW_SCALE_INV, 0.0, 1.0);
216- return;
217+ if (true) {
218+ return;
219+ }
217220#endif
218221 vec3 eyeDir = vec3(normalize(-fragPosition).xyz);
219222 vec2 texCoord = fragTexCoord.xy;
220223 vec4 baseColor = color;
221224 vec4 specColor = vec4(0.0, 0.0, 0.0, 1.0);
225+ vec4 emissiveColor = vec4(0.0, 0.0, 0.0, 1.0);
222226 float fresnelFactor = 0.0;
223227 float glossData = 0.6;
224228#ifdef FLAG_LIGHT
@@ -295,30 +299,45 @@ void main()
295299 baseColor.rgb = max(baseColor.rgb, vec3(0.0));
296300 #endif
297301#endif
302+ // Lights aren't applied when we are rendering to the G-buffers since that gets handled later
303+ #ifdef FLAG_DEFERRED
304+ #ifdef FLAG_LIGHT
305+ // Ambient lighting still needs to be done since that counts as an "emissive" color
306+ vec3 lightAmbient = (emissionFactor + ambientFactor * ambientFactor) * aoFactors.x; // ambientFactor^2 due to legacy OpenGL compatibility behavior
307+ emissiveColor.rgb += baseColor.rgb * lightAmbient;
308+ #else
309+ #ifdef FLAG_SPEC_MAP
310+ baseColor.rgb += pow(1.0 - clamp(dot(eyeDir, normal), 0.0, 1.0), 5.0 * clamp(glossData, 0.01, 1.0)) * specColor.rgb;
311+ #endif
312+ // If there is no lighting then we copy the color data so far into the
313+ emissiveColor.rgb += baseColor.rgb;
314+ #endif
315+ #else
316+ #ifdef FLAG_LIGHT
298317 float shadow = 1.0;
299- #ifdef FLAG_SHADOWS
318+ #ifdef FLAG_SHADOWS
300319 shadow = getShadowValue(shadow_map, -fragPosition.z, fragShadowPos.z, fragShadowUV, fardist, middist, neardist, veryneardist);
301- #endif
302- #ifdef FLAG_LIGHT
320+ #endif
303321 baseColor.rgb = CalculateLighting(normal, baseColor.rgb, specColor.rgb, glossData, fresnelFactor, shadow, aoFactors.x);
304- #else
305- #ifdef FLAG_SPEC_MAP
322+ #else
323+ #ifdef FLAG_SPEC_MAP
306324 baseColor.rgb += pow(1.0 - clamp(dot(eyeDir, normal), 0.0, 1.0), 5.0 * clamp(glossData, 0.01, 1.0)) * specColor.rgb;
325+ #endif
307326 #endif
308327#endif
309328#ifdef FLAG_ENV_MAP
310- vec3 envReflectNM = fragEnvReflect;
329+ vec3 envReflectNM = fragEnvReflect;
311330 #ifdef FLAG_NORMAL_MAP
312- envReflectNM += vec3(normalSample, 0.0);
331+ envReflectNM += vec3(normalSample, 0.0);
313332 envReflectNM = normalize(envReflectNM);
314333 #endif
315334 float mip = (envGloss) ? (1.0 - glossData) * 7.0 : 0.0;
316- vec4 envColour = textureLod(sEnvmap, envReflectNM, mip);
335+ vec4 envColour = textureLod(sEnvmap, envReflectNM, mip);
317336 #ifdef FLAG_HDR
318337 envColour.rgb = pow(envColour.rgb, vec3(SRGB_GAMMA));
319338 #endif
320339 envColour.rgb *= (envGloss) ? 1.0 : specColor.a;
321- baseColor .rgb += envColour.rgb * FresnelLazarovEnv(specColor.rgb, eyeDir, normal, glossData);
340+ emissiveColor .rgb += envColour.rgb * FresnelLazarovEnv(specColor.rgb, eyeDir, normal, glossData);
322341#endif
323342#ifdef FLAG_GLOW_MAP
324343 vec3 glowColor = texture(sGlowmap, vec3(texCoord, float(sGlowmapIndex))).rgb;
@@ -332,7 +351,7 @@ void main()
332351 glowColor = team_glow_enabled ? mix((base * teamMask.b) + (stripe * teamMask.a), glowColor, clamp(glowColorLuminance - teamMask.b - teamMask.a, 0.0, 1.0)) : glowColor;
333352 #endif
334353 #endif
335- baseColor .rgb += glowColor * GLOW_MAP_INTENSITY;
354+ emissiveColor .rgb += glowColor * GLOW_MAP_INTENSITY;
336355#endif
337356
338357#ifdef FLAG_FOG
@@ -355,15 +374,13 @@ void main()
355374#ifdef FLAG_ANIMATED
356375 if (effect_num == 0) {
357376 float shinefactor = 1.0/(1.0 + pow(abs((fract(abs(texCoord.x))-anim_timer) * 1000.0), 2.0)) * 1000.0;
358- baseColor .rgb = baseColor.rgb + vec3(shinefactor);
377+ emissiveColor .rgb += vec3(shinefactor);
359378 baseColor.a = baseColor.a * clamp(shinefactor * (fract(abs(texCoord.x))-anim_timer) * -10000.0,0.0,1.0);
360379 }
361380 if (effect_num == 1) {
362381 float shinefactor = 1.0/(1.0 + pow(abs(fragPosition.y-anim_timer), 2.0));
363- baseColor.rgb = baseColor.rgb + vec3(shinefactor);
364- #ifdef FLAG_LIGHT
365- baseColor.a = baseColor.a;
366- #else
382+ emissiveColor.rgb += vec3(shinefactor);
383+ #ifndef FLAG_LIGHT
367384 // ATI Wireframe fix *grumble*
368385 baseColor.a = clamp((fragPosition.y-anim_timer) * 10000.0,0.0,1.0);
369386 #endif
@@ -382,11 +399,16 @@ void main()
382399#ifdef FLAG_NORMAL_ALPHA
383400 float normViewOffset = dot(vec3(0.0, 0.0, 1.0), normal);
384401 baseColor.a = smoothstep(min(normalAlphaMinMax.x, normalAlphaMinMax.y), max(normalAlphaMinMax.x, normalAlphaMinMax.y), clamp(normalAlphaMinMax.x > normalAlphaMinMax.y ? normViewOffset : 1.0 - normViewOffset, 0.0, 1.0));
402+ #endif
403+ #ifndef FLAG_DEFERRED
404+ // emissive colors won't be added later when we are using forward rendering so we need to do that here
405+ baseColor.rgb += emissiveColor.rgb;
385406#endif
386407 fragOut0 = baseColor;
387408#ifdef FLAG_DEFERRED
388409 fragOut1 = vec4(fragPosition.xyz, 1.0);
389410 fragOut2 = vec4(normal, glossData);
390411 fragOut3 = vec4(specColor.rgb, fresnelFactor);
412+ fragOut4 = emissiveColor;
391413#endif
392414}
0 commit comments