Skip to content

Commit 74a54c9

Browse files
committed
overbright after linearization
1 parent 15d3e53 commit 74a54c9

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/engine/renderer/glsl_source/computeLight_fp.glsl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,32 @@ vec4 EnvironmentalSpecularFactor( vec3 viewDir, vec3 normal )
4949

5050
// lighting helper functions
5151

52+
#if defined(USE_LIGHT_MAPPING)
53+
void TransformLightMap( inout vec3 lightColor, in float lightFactor, bool linearizeLightMap )
54+
{
55+
convertFromSRGB(lightColor, linearizeLightMap);
56+
57+
// When doing vertex lighting with full-range overbright, this reads out
58+
// 1<<overbrightBits and serves for the overbright shift for vertex colors.
59+
lightColor *= lightFactor;
60+
}
61+
#endif
62+
5263
#if defined(USE_GRID_LIGHTING) || defined(USE_GRID_DELUXE_MAPPING)
53-
void ReadLightGrid( in vec4 texel, in float lightFactor, out vec3 ambientColor, out vec3 lightColor ) {
64+
void ReadLightGrid( in vec4 texel, in float lightFactor, in bool linearizeLightMap, out vec3 ambientColor, out vec3 lightColor) {
5465
float ambientScale = 2.0 * texel.a;
5566
float directedScale = 2.0 - ambientScale;
5667
ambientColor = ambientScale * texel.rgb;
5768
lightColor = directedScale * texel.rgb;
69+
70+
#if defined(r_cheapSRGB)
71+
/* The light grid conversion from sRGB is done in C++ code
72+
when loading it, meaning it's done before interpolation. */
73+
#else
74+
convertFromSRGB(lightColor, linearizeLightMap);
75+
convertFromSRGB(ambientColor, linearizeLightMap);
76+
#endif
77+
5878
ambientColor *= lightFactor;
5979
lightColor *= lightFactor;
6080
}

src/engine/renderer/glsl_source/lightMapping_fp.glsl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,27 +162,13 @@ void main()
162162
float lightFactor = ColorModulateToLightFactor( u_ColorModulateColorGen );
163163
#if defined(USE_LIGHT_MAPPING)
164164
// Compute light color from world space lightmap.
165-
// When doing vertex lighting with full-range overbright, this reads out
166-
// 1<<overbrightBits and serves for the overbright shift for vertex colors.
167165
vec3 lightColor = texture2D(u_LightMap, var_TexLight).rgb;
168-
lightColor *= lightFactor;
169-
170-
convertFromSRGB(lightColor, linearizeLightMap);
171-
166+
TransformLightMap(lightColor, lightFactor, linearizeLightMap);
172167
color.rgb = vec3(0.0);
173168
#else
174169
// Compute light color from lightgrid.
175170
vec3 ambientColor, lightColor;
176-
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), lightFactor, ambientColor, lightColor);
177-
178-
#if defined(r_cheapSRGB)
179-
/* The light grid conversion from sRGB is done in C++ code
180-
when loading it, meaning it's done before interpolation. */
181-
#else
182-
convertFromSRGB(lightColor, linearizeLightMap);
183-
convertFromSRGB(ambientColor, linearizeLightMap);
184-
#endif
185-
171+
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), lightFactor, linearizeLightMap, ambientColor, lightColor);
186172
color.rgb = ambientColor * r_AmbientScale * diffuse.rgb;
187173
#endif
188174

0 commit comments

Comments
 (0)