From 69f5ab9004124a58e202425ab253a119e8e63e4b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 15 Mar 2019 14:31:32 -0700 Subject: Make alpha drawpool optimizations an opt-in render debug setting for the adventurous. --- indra/newview/app_settings/settings.xml | 22 +++++++++++++++++++++ indra/newview/lldrawpoolalpha.cpp | 34 +++++++++++++++++---------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 088bc3dfac..c0dcafdd51 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -8558,6 +8558,28 @@ + RenderAlphaBatchFullbrights + + Comment + Render fullbright alpha content more efficiently, but with possible visual differences from prev viewers. + Persist + 1 + Type + Boolean + Value + 0 + + RenderAlphaBatchEmissives + + Comment + Render emissive alpha content more efficiently, but with possible visual differences from prev viewers. + Persist + 1 + Type + Boolean + Value + 0 + RenderAnisotropic Comment diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 9f65a70a86..2efa208017 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -49,10 +49,6 @@ #include "llspatialpartition.h" #include "llglcommonfunc.h" -// These optimizations can and will induce lighting, texturing, and/or GL state bugs -#define BATCH_FULLBRIGHTS 0 -#define BATCH_EMISSIVES 0 - BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; static BOOL deferred_render = FALSE; @@ -612,6 +608,8 @@ void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissi void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { + BOOL batch_fullbrights = gSavedSettings.getBOOL("RenderAlphaBatchFullbrights"); + BOOL batch_emissives = gSavedSettings.getBOOL("RenderAlphaBatchEmissives"); BOOL initialized_lighting = FALSE; BOOL light_enabled = TRUE; @@ -671,13 +669,11 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } - #if BATCH_FULLBRIGHTS - if (params.mFullbright) + if (params.mFullbright && batch_fullbrights) { fullbrights.push_back(¶ms); continue; } - #endif LLRenderPass::applyModelMatrix(params); @@ -812,11 +808,15 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_EMISSIVE); - #if BATCH_EMISSIVES - emissives.push_back(¶ms); - #else - drawEmissiveInline(mask, ¶ms); - #endif + + if (batch_emissives) + { + emissives.push_back(¶ms); + } + else + { + drawEmissiveInline(mask, ¶ms); + } } if (tex_setup) @@ -828,15 +828,17 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } - #if BATCH_FULLBRIGHTS + if (batch_fullbrights) + { light_enabled = false; renderFullbrights(mask, fullbrights); - #endif + } - #if BATCH_EMISSIVES + if (batch_emissives) + { light_enabled = true; renderEmissives(mask, emissives); - #endif + } if (current_shader) { -- cgit v1.2.3 From 1a6f54cb5ede03f7e7d0b24f7eb45081adf0464e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 19 Mar 2019 15:02:13 -0700 Subject: SL-10764 Fix lighting issues when using shaders, but not ALM. Shader code cleanup (remove do nothing functions only in one file). Fix obsolete comment to refer to correct storage for projector ambiance. --- .../shaders/class1/deferred/fullbrightF.glsl | 13 ------------- .../shaders/class1/deferred/multiSpotLightF.glsl | 5 +++++ .../app_settings/shaders/class1/lighting/lightFuncV.glsl | 2 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 16 +++++++++++----- .../app_settings/shaders/class2/deferred/spotLightF.glsl | 11 ++++++++++- .../app_settings/shaders/class3/lighting/sumLightsV.glsl | 2 +- indra/newview/pipeline.cpp | 2 +- 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 08ddaeceb3..d5ef010017 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -45,17 +45,6 @@ VARYING vec2 vary_texcoord0; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 fullbrightAtmosTransportDeferred(vec3 light) -{ - return light; -} - -vec3 fullbrightScaleSoftClipDeferred(vec3 light) -{ - //soft clip effect: - return light; -} - #ifdef HAS_ALPHA_MASK uniform float minimum_alpha; #endif @@ -78,8 +67,6 @@ void main() #endif color.rgb *= vertex_color.rgb; - color.rgb = fullbrightAtmosTransportDeferred(color.rgb); - color.rgb = fullbrightScaleSoftClipDeferred(color.rgb); #ifdef WATER_FOG vec3 pos = vary_position; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 2569e49743..57916eb3e5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -72,10 +72,13 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -95,6 +98,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -112,6 +116,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index a9288b3df6..dd14192ad6 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -52,7 +52,7 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= calcDirectionalLight(n, lv); + da *= calcDirectionalLight(n, -lv); return da; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 275bc829a7..4e3ecbcbf5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,11 +71,19 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 srgb_to_linear(vec3 cs); + vec3 getNorm(vec2 pos_screen); +vec4 correctWithGamma(vec4 col) +{ + return vec4(srgb_to_linear(col.rgb), col.a); +} + vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -95,6 +103,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -211,16 +220,13 @@ void main() dlit = color.rgb * plcol.rgb * plcol.a; col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5) * proj_ambiance; - amb_da += (da*da*0.5 + 0.5) * proj_ambiance; - //amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; - //amb_da = min(amb_da,shadow); + amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - amb_da += (da*da*0.5+0.5)*proj_ambiance; + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; amb_da *= dist_atten * noise; diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 9b69d8d855..abea8aecca 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,11 +71,18 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 srgb_to_linear(vec3 cs); vec3 getNorm(vec2 pos_screen); +vec4 correctWithGamma(vec4 col) +{ + return vec4(srgb_to_linear(col.rgb), col.a); +} + vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -95,6 +102,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -112,6 +120,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); @@ -216,7 +225,7 @@ void main() //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - amb_da += (da*da*0.5+0.5)*proj_ambiance; + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; amb_da *= dist_atten * noise; diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index 9842d9ba93..5302b05043 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -32,7 +32,7 @@ vec3 atmosAffectDirectionalLight(float lightIntensity); uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index c3bccfd19b..c4a644c7b6 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -6346,7 +6346,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) light_state->setSpotExponent(0.f); light_state->setSpotCutoff(180.f); - // we use specular.w = 1.0 as a cheap hack for the shaders to know that this is omnidirectional rather than a spotlight + // we use specular.z = 1.0 as a cheap hack for the shaders to know that this is omnidirectional rather than a spotlight const LLColor4 specular(0.f, 0.f, 1.f, 0.f); light_state->setSpecular(specular); } -- cgit v1.2.3 From 721df1f942ba7c5d78c7f974ed564aac431844f7 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 19 Mar 2019 15:29:31 -0700 Subject: SL-10764 Fix the light_atten decsl for specular lighting too. --- .../app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl | 2 +- .../app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl index 3acf9fe883..8ca7db1814 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl @@ -34,7 +34,7 @@ vec3 atmosGetDiffuseSunlightColor(); vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl index e043ac873e..ce5855646c 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl @@ -32,7 +32,7 @@ vec3 atmosGetDiffuseSunlightColor(); vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) -- cgit v1.2.3 From 2d514e4b10025dc37c20db7db821e621dcdcaaf1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 19 Mar 2019 17:24:16 -0700 Subject: SL-10763 Fix broken logic for alpha drawpool when rendering with basic shaders off. Force unbind of 2nd tex unit that we use during water rendering. --- indra/newview/lldrawpoolalpha.cpp | 8 ++++---- indra/newview/lldrawpoolwater.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 2efa208017..9d80853ba3 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -388,7 +388,7 @@ bool LLDrawPoolAlpha::TexSetup(LLDrawInfo* draw, bool use_shaders, bool use_mate bool tex_setup = false; - if (use_shaders && use_material && current_shader) + if (deferred_render && use_material && current_shader) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); if (draw->mNormalMap) @@ -766,7 +766,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) F32 brightness = 1.0f; // We have a material. Supply the appropriate data here. - if (use_shaders && mat && LLPipeline::sRenderDeferred) + if (use_shaders && mat && deferred_render) { spec_color = params.mSpecColor; env_intensity = params.mEnvIntensity; @@ -785,7 +785,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) params.mGroup->rebuildMesh(); } - bool tex_setup = TexSetup(¶ms, use_shaders, mat != nullptr, current_shader); + bool tex_setup = TexSetup(¶ms, use_shaders, use_shaders && (mat != nullptr), current_shader); { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); @@ -802,7 +802,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } - // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. + // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls is expensive, but glow must be drawn Z-sorted with alpha. if (current_shader && draw_glow_for_this_partition && params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp index abda2d45fb..4c95fb0a0f 100644 --- a/indra/newview/lldrawpoolwater.cpp +++ b/indra/newview/lldrawpoolwater.cpp @@ -271,9 +271,9 @@ void LLDrawPoolWater::render(S32 pass) glDisable(GL_TEXTURE_GEN_S); //texture unit 1 glDisable(GL_TEXTURE_GEN_T); //texture unit 1 - gGL.getTexUnit(1)->activate(); - gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE); - gGL.getTexUnit(1)->disable(); + gGL.getTexUnit(2)->activate(); + gGL.getTexUnit(2)->unbind(LLTexUnit::TT_TEXTURE); + gGL.getTexUnit(2)->disable(); glDisable(GL_TEXTURE_GEN_S); //texture unit 1 glDisable(GL_TEXTURE_GEN_T); //texture unit 1 -- cgit v1.2.3