Skip to content

Commit 3001280

Browse files
authored
Additional tweaks to get skies closer to 6.6.17 in classic mode. (#3202)
1 parent 73420f4 commit 3001280

File tree

9 files changed

+71
-27
lines changed

9 files changed

+71
-27
lines changed

indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,10 @@ vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor,
544544
pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv, nl, diffPunc, specPunc);
545545
color = intensity * clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10));
546546
}
547-
548-
return color;
547+
float final_scale = 1.0;
548+
if (classic_mode > 0)
549+
final_scale = 0.9;
550+
return color * final_scale;
549551
}
550552

551553
void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor)
@@ -576,22 +578,25 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v,
576578
// Depending on the sky, we combine these differently.
577579
if (classic_mode > 0)
578580
{
581+
irradiance.rgb = srgb_to_linear(irradiance * 0.9); // BINGO
582+
579583
// Reconstruct the diffuse lighting that we do for blinn-phong materials here.
580584
// A special note about why we do some really janky stuff for classic mode.
581585
// Since adding classic mode, we've moved the lambertian diffuse multiply out from pbrPunctual and instead handle it in the different light type calcs.
582-
// For classic mode, this baiscally introduces a double multiplication that we need to somehow avoid
583-
// Using one of the old mobile gamma correction tricks (val * val to "linearize", sqrt(val) to bring back into sRGB), we can _mostly_ avert this
584586
// This will never be 100% correct, but at the very least we can make it look mostly correct with legacy skies and classic mode.
585587

586-
float da = pow(sqrt(nl), 1.2);
588+
float da = pow(nl, 1.2);
587589

588590
vec3 sun_contrib = vec3(min(da, scol));
589591

590592
// Multiply by PI to account for lambertian diffuse colors. Otherwise things will be too dark when lit by the sun on legacy skies.
591-
sun_contrib = srgb_to_linear(color.rgb * 0.9 + linear_to_srgb(sun_contrib) * sunlit * 0.7) * M_PI;
593+
sun_contrib = srgb_to_linear(linear_to_srgb(sun_contrib) * sunlit * 0.7) * M_PI;
592594

593595
// Manually recombine everything here. We have to separate the shading to ensure that lighting is able to more closely match blinn-phong.
594-
color.rgb = srgb_to_linear(iblDiff) + clamp(sun_contrib * (da * (diffPunc.rgb + specPunc.rgb) * scol), vec3(0), vec3(10));
596+
vec3 finalAmbient = irradiance.rgb * diffuseColor.rgb; // BINGO
597+
vec3 finalSun = clamp(sun_contrib * ((diffPunc.rgb + specPunc.rgb) * scol), vec3(0), vec3(10)); // QUESTIONABLE BINGO?
598+
color.rgb = srgb_to_linear(linear_to_srgb(finalAmbient) + (linear_to_srgb(finalSun) * 1.1));
599+
//color.rgb = sun_contrib * diffuseColor.rgb;
595600
}
596601
else
597602
{

indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec
163163

164164
// no spec for alpha shader...
165165
}
166-
col = max(col, vec3(0));
166+
float final_scale = 1.0;
167+
if (classic_mode > 0)
168+
final_scale = 0.9;
169+
col = max(col * final_scale, vec3(0));
167170
return col;
168171
}
169172

@@ -241,7 +244,8 @@ void main()
241244
vec3 atten;
242245

243246
calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten);
244-
247+
if (classic_mode > 0)
248+
sunlit *= 1.35;
245249
vec3 sunlit_linear = sunlit;
246250
vec3 amblit_linear = amblit;
247251

@@ -296,11 +300,14 @@ void main()
296300
color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, color).rgb;
297301

298302
#endif // #else // FOR_IMPOSTOR
299-
303+
float final_scale = 1;
304+
if (classic_mode > 0)
305+
final_scale = 1.1;
300306
#ifdef IS_HUD
301307
color.rgb = linear_to_srgb(color.rgb);
308+
final_scale = 1;
302309
#endif
303310

304-
frag_color = max(color, vec4(0));
311+
frag_color = max(color * final_scale, vec4(0));
305312
}
306313

indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ uniform sampler2D lightMap;
4343
uniform int sun_up_factor;
4444
uniform vec3 sun_dir;
4545
uniform vec3 moon_dir;
46+
uniform int classic_mode;
4647

4748
out vec4 frag_color;
4849

@@ -160,7 +161,8 @@ void main()
160161
vec3 additive;
161162
vec3 atten;
162163
calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten);
163-
164+
if (classic_mode > 0)
165+
sunlit *= 1.35;
164166
vec3 sunlit_linear = sunlit;
165167

166168
vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
@@ -212,8 +214,10 @@ void main()
212214
color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb;
213215

214216
float a = basecolor.a*vertex_color.a;
215-
216-
frag_color = max(vec4(color.rgb,a), vec4(0));
217+
float final_scale = 1;
218+
if (classic_mode > 0)
219+
final_scale = 1.1;
220+
frag_color = max(vec4(color.rgb * final_scale,a), vec4(0));
217221
}
218222

219223
#else

indra/newview/app_settings/shaders/class3/deferred/materialF.glsl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe
178178
}
179179
}
180180
}
181-
182-
return max(col, vec3(0.0, 0.0, 0.0));
181+
float final_scale = 1.0;
182+
if (classic_mode > 0)
183+
final_scale = 0.9;
184+
return max(col * final_scale, vec3(0.0, 0.0, 0.0));
183185
}
184186

185187
#else
@@ -329,7 +331,8 @@ void main()
329331
vec3 additive;
330332
vec3 atten;
331333
calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten);
332-
334+
if (classic_mode > 0)
335+
sunlit *= 1.35;
333336
vec3 sunlit_linear = sunlit;
334337
vec3 amblit_linear = amblit;
335338

@@ -418,8 +421,10 @@ void main()
418421
glare *= 1.0-emissive;
419422
glare = min(glare, 1.0);
420423
float al = max(diffcol.a, glare) * vertex_color.a;
421-
422-
frag_color = max(vec4(color, al), vec4(0));
424+
float final_scale = 1;
425+
if (classic_mode > 0)
426+
final_scale = 1.1;
427+
frag_color = max(vec4(color * final_scale, al), vec4(0));
423428

424429
#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer
425430
// deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl

indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ uniform vec4 light_col[LIGHT_COUNT]; // .a = falloff
3838
uniform vec2 screen_res;
3939
uniform float far_z;
4040
uniform mat4 inv_proj;
41+
uniform int classic_mode;
4142

4243
in vec4 vary_fragcoord;
4344

@@ -169,8 +170,10 @@ void main()
169170
}
170171
}
171172
}
172-
173-
frag_color.rgb = max(final_color, vec3(0));
173+
float final_scale = 1.0;
174+
if (classic_mode > 0)
175+
final_scale = 0.9;
176+
frag_color.rgb = max(final_color * final_scale, vec3(0));
174177
frag_color.a = 0.0;
175178

176179
#ifdef IS_AMD_CARD

indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ uniform vec2 screen_res;
4444

4545
uniform mat4 inv_proj;
4646
uniform vec4 viewport;
47+
uniform int classic_mode;
4748

4849
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
4950
float calcLegacyDistanceAttenuation(float distance, float falloff);
@@ -149,7 +150,9 @@ void main()
149150
discard;
150151
}
151152
}
152-
153-
frag_color.rgb = max(final_color, vec3(0));
153+
float final_scale = 1.0;
154+
if (classic_mode > 0)
155+
final_scale = 0.9;
156+
frag_color.rgb = max(final_color * final_scale, vec3(0));
154157
frag_color.a = 0.0;
155158
}

indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ void main()
155155

156156
calcAtmosphericVarsLinear(pos.xyz, gb.normal, light_dir, sunlit, amblit, additive, atten);
157157

158+
if (classic_mode > 0)
159+
sunlit *= 1.35;
160+
158161
vec3 sunlit_linear = sunlit;
159162
vec3 amblit_linear = amblit;
160163

@@ -224,7 +227,7 @@ void main()
224227
da = pow(da,1.2);
225228
vec3 sun_contrib = vec3(min(da, scol));
226229

227-
color.rgb = srgb_to_linear(color.rgb * 0.9 + linear_to_srgb(sun_contrib) * sunlit_linear * 0.7);
230+
color.rgb = srgb_to_linear(color.rgb * 0.9 + (linear_to_srgb(sun_contrib) * sunlit_linear * 0.7));
228231
sunlit_linear = srgb_to_linear(sunlit_linear);
229232
}
230233
else
@@ -272,6 +275,9 @@ void main()
272275
}
273276

274277
//color.r = classic_mode > 0 ? 1.0 : 0.0;
275-
frag_color.rgb = max(color.rgb, vec3(0)); //output linear since local lights will be added to this shader's results
278+
float final_scale = 1;
279+
if (classic_mode > 0)
280+
final_scale = 1.1;
281+
frag_color.rgb = max(color.rgb * final_scale, vec3(0)); //output linear since local lights will be added to this shader's results
276282
frag_color.a = 0.0;
277283
}

indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ uniform vec3 proj_origin; //origin of projection to be used for angular attenuat
4747
uniform float sun_wash;
4848
uniform int proj_shadow_idx;
4949
uniform float shadow_fade;
50+
uniform int classic_mode;
5051

5152
// Light params
5253
#if defined(MULTI_SPOTLIGHT)
@@ -267,8 +268,10 @@ void main()
267268

268269
//not sure why, but this line prevents MATBUG-194
269270
final_color = max(final_color, vec3(0.0));
270-
271+
float final_scale = 1.0;
272+
if (classic_mode > 0)
273+
final_scale = 0.9;
271274
//output linear
272-
frag_color.rgb = final_color;
275+
frag_color.rgb = final_color * final_scale;
273276
frag_color.a = 0.0;
274277
}

indra/newview/pipeline.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8518,6 +8518,7 @@ void LLPipeline::renderDeferredLighting()
85188518
std::list<LLVector4> fullscreen_lights;
85198519
LLDrawable::drawable_list_t spot_lights;
85208520
LLDrawable::drawable_list_t fullscreen_spot_lights;
8521+
LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
85218522

85228523
if (!gCubeSnapshot)
85238524
{
@@ -8613,6 +8614,8 @@ void LLPipeline::renderDeferredLighting()
86138614
gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
86148615
gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
86158616
gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
8617+
gDeferredLightProgram.uniform1i(LLShaderMgr::CLASSIC_MODE, (psky->canAutoAdjust()) ? 1 : 0);
8618+
86168619
gGL.syncMatrices();
86178620

86188621
mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center));
@@ -8673,6 +8676,8 @@ void LLPipeline::renderDeferredLighting()
86738676
gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
86748677
gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
86758678
gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
8679+
gDeferredSpotLightProgram.uniform1i(LLShaderMgr::CLASSIC_MODE, (psky->canAutoAdjust()) ? 1 : 0);
8680+
86768681
gGL.syncMatrices();
86778682

86788683
mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center));
@@ -8711,6 +8716,7 @@ void LLPipeline::renderDeferredLighting()
87118716
gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*)light);
87128717
gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*)col);
87138718
gDeferredMultiLightProgram[idx].uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z);
8719+
gDeferredMultiLightProgram[idx].uniform1i(LLShaderMgr::CLASSIC_MODE, (psky->canAutoAdjust()) ? 1 : 0);
87148720
far_z = 0.f;
87158721
count = 0;
87168722
mScreenTriangleVB->setBuffer();
@@ -8748,6 +8754,8 @@ void LLPipeline::renderDeferredLighting()
87488754
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, light_size_final);
87498755
gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
87508756
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, light_falloff_final);
8757+
gDeferredMultiSpotLightProgram.uniform1i(LLShaderMgr::CLASSIC_MODE, (psky->canAutoAdjust()) ? 1 : 0);
8758+
87518759
mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
87528760
}
87538761

0 commit comments

Comments
 (0)