Skip to content

Commit aa60a63

Browse files
authored
Merge pull request scp-fs2open#1633 from The-E/fix/team_colors_washed_out
Add SRGB adjustment to the team colors
2 parents be9a881 + ef0c6b5 commit aa60a63

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

code/def_files/data/effects/lighting.sdr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const float SPEC_FACTOR_NO_SPEC_MAP = 0.6;
1212
const float ENV_ALPHA_FACTOR = 0.3;
1313
const float GLOW_MAP_INTENSITY = 1.5;
1414
const float AMBIENT_LIGHT_BOOST = 1.0;
15+
const float GLOW_MAP_SRGB_MULTIPLIER = 3.0;
1516

1617
vec3 FresnelSchlick(vec3 specColor, vec3 light, vec3 halfVec)
1718
{

code/def_files/data/effects/main-f.sdr

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,20 @@ void main()
293293
#ifdef FLAG_TEAMCOLOR
294294
vec4 teamMask = vec4(0.0, 0.0, 0.0, 0.0);
295295
teamMask = texture(sMiscmap, vec3(texCoord, float(sMiscmapIndex)));
296-
vec3 base = max(base_color - vec3(0.5), vec3(0.0));
297-
vec3 stripe = max(stripe_color - vec3(0.5), vec3(0.0));
298-
baseColor.rgb += (base * teamMask.x) + (stripe * teamMask.y);
299-
baseColor.rgb = max(baseColor.rgb, vec3(0.0));
296+
//For team colors applied to a diffuse or spec map, we assume that the base color of the diffuse
297+
//at this point is vec3(0.5). To get accurate results, we subtract 0.5 from the team colors
298+
vec3 team_color = ((base_color - vec3(0.5)) * teamMask.x) + ((stripe_color - vec3(0.5)) * teamMask.y);
299+
vec3 team_color_glow = (base_color * teamMask.b) + (stripe_color * teamMask.a);
300+
301+
#ifdef FLAG_HDR
302+
team_color = pow(team_color, vec3(SRGB_GAMMA));
303+
team_color_glow = pow(team_color_glow, vec3(SRGB_GAMMA)) * GLOW_MAP_SRGB_MULTIPLIER;
304+
#endif
305+
306+
baseColor.rgb += team_color;
307+
baseColor.rgb = max(baseColor.rgb, vec3(0.0)); // We need to make sure that nothing here ever goes negative
308+
specColor.rgb += team_color;
309+
specColor.rgb = max(specColor.rgb, vec3(0.03));
300310
#endif
301311
#endif
302312
// Lights aren't applied when we are rendering to the G-buffers since that gets handled later
@@ -343,12 +353,12 @@ void main()
343353
vec3 glowColor = texture(sGlowmap, vec3(texCoord, float(sGlowmapIndex))).rgb;
344354
if(overrideGlow) glowColor = glowClr;
345355
#ifdef FLAG_HDR
346-
glowColor = pow(glowColor, vec3(SRGB_GAMMA)) * 3.0f;
356+
glowColor = pow(glowColor, vec3(SRGB_GAMMA)) * GLOW_MAP_SRGB_MULTIPLIER;
347357
#endif
348358
#ifdef FLAG_MISC_MAP
349359
#ifdef FLAG_TEAMCOLOR
350360
float glowColorLuminance = dot(glowColor, vec3(0.299, 0.587, 0.114));
351-
glowColor = team_glow_enabled ? mix((base * teamMask.b) + (stripe * teamMask.a), glowColor, clamp(glowColorLuminance - teamMask.b - teamMask.a, 0.0, 1.0)) : glowColor;
361+
glowColor = team_glow_enabled ? mix(max(team_color_glow, vec3(0.0)), glowColor, clamp(glowColorLuminance - teamMask.b - teamMask.a, 0.0, 1.0)) : glowColor;
352362
#endif
353363
#endif
354364
emissiveColor.rgb += glowColor * GLOW_MAP_INTENSITY;

0 commit comments

Comments
 (0)