diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 5f5b76d4251fae9ccdf2d291661d26b81345bd87..f0d59d0eaf64a41d1546b18469b4e228f301fde7 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1114,6 +1114,7 @@ void LLRender::syncLightState() shader->uniform3fv("light_direction", 8, direction[0].mV); shader->uniform3fv("light_attenuation", 8, attenuation[0].mV); shader->uniform3fv("light_diffuse", 8, diffuse[0].mV); + shader->uniform4fv("light_ambient", 1, mAmbientLightColor.mV); } } @@ -1638,6 +1639,19 @@ LLLightState* LLRender::getLight(U32 index) return NULL; } +void LLRender::setAmbientLightColor(const LLColor4& color) +{ + if (color != mAmbientLightColor) + { + ++mLightHash; + mAmbientLightColor = color; + if (!LLGLSLShader::sNoFixedFunction) + { + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.mV); + } + } +} + bool LLRender::verifyTexUnitActive(U32 unitToVerify) { if (mCurrTextureUnitIndex == unitToVerify) diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 3f319022f69729d855eef0d7a5fdae1d8ead00ff..7d636060f59470d306afb788f2b2f7a8c4ac59b5 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -406,7 +406,8 @@ class LLRender eBlendFactor alpha_sfactor, eBlendFactor alpha_dfactor); LLLightState* getLight(U32 index); - + void setAmbientLightColor(const LLColor4& color); + LLTexUnit* getTexUnit(U32 index); U32 getCurrentTexUnitIndex(void) const { return mCurrTextureUnitIndex; } @@ -437,6 +438,7 @@ class LLRender glh::matrix4f mMatrix[NUM_MATRIX_MODES][LL_MATRIX_STACK_DEPTH]; U32 mCurMatHash[NUM_MATRIX_MODES]; U32 mLightHash; + LLColor4 mAmbientLightColor; bool mDirty; U32 mCount; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl index 15781bc92d7e6613d8189de0acc0e775fa705ec1..b07c1fda9b4089be7fc3e47f57895e9b8e417db8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl @@ -105,7 +105,7 @@ void main() vec4 frag_pos = projection_matrix * pos; gl_Position = frag_pos; - + GL vary_position = pos.xyz; vary_normal = norm; diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl index bf6ed5988e5808f9c49eda5eae937b8afe2927f6..265d548ce9a1ce6a2d4d02a468dfea2c64298eb8 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl @@ -26,6 +26,7 @@ uniform vec4 light_position[8]; uniform vec3 light_diffuse[8]; +uniform vec4 light_ambient; float calcDirectionalLight(vec3 n, vec3 l); @@ -36,7 +37,7 @@ vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularCo vec4 col; col.a = color.a; - col.rgb = baseCol.rgb; //need ambient? + col.rgb = baseCol.rgb + light_ambient.rgb; col.rgb += light_diffuse[0].rgb*calcDirectionalLight(norm, light_position[0].xyz); col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index 79e220793220a0390d1feca330f3520ca1368453..b886f9774390466fbd6e89ad47cd91bf7addb331 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -26,6 +26,7 @@ uniform vec4 light_position[8]; uniform vec3 light_diffuse[8]; +uniform vec4 light_ambient; float calcDirectionalLight(vec3 n, vec3 l); @@ -34,7 +35,7 @@ vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) vec4 col; col.a = color.a; - col.rgb = baseLight.rgb; //need ambient? + col.rgb = baseLight.rgb+light_ambient.rgb; col.rgb += light_diffuse[0].rgb*calcDirectionalLight(norm, light_position[0].xyz); col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 9aa583afa1d1587b4aed82a9e4a342664fe54801..ed0249330ea81508d79b2fd7121a01025525e7eb 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -24,10 +24,11 @@ */ uniform vec3 light_diffuse[8]; +uniform vec4 light_ambient; vec3 atmosAmbient(vec3 light) { - return light; //need ambient? + return light + light_ambient.rgb; } vec3 atmosAffectDirectionalLight(float lightIntensity) diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index 22f4db56ddc20dfc15f400f3b68656e884683178..4f3127805f804adb11bfaa3a96cdebd1281b4eee 100644 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -522,14 +522,10 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) // Slam lighting parameters back to our defaults. // Note that these are not the same as GL defaults... - if (!LLGLSLShader::sNoFixedFunction) - { - stop_glerror(); - F32 one[4] = {1.f, 1.f, 1.f, 1.f}; - glLightModelfv (GL_LIGHT_MODEL_AMBIENT,one); - stop_glerror(); - } - + stop_glerror(); + gGL.setAmbientLightColor(LLColor4::white); + stop_glerror(); + ///////////////////////////////////// // // Render diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index cd9dc461d565d613cccfddd25a532b0badb8c0eb..cfdbfd3f03ea645f1157b22aac1ed41240ac2fb9 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -1712,10 +1712,8 @@ void LLViewerWindow::initGLDefaults() gGL.setSceneBlendType(LLRender::BT_ALPHA); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); - F32 ambient[4] = {0.f,0.f,0.f,0.f }; - F32 diffuse[4] = {1.f,1.f,1.f,1.f }; - glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,ambient); - glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,diffuse); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,LLColor4::black.mV); + glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,LLColor4::white.mV); glPixelStorei(GL_PACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_ALIGNMENT,1); @@ -1725,10 +1723,7 @@ void LLViewerWindow::initGLDefaults() // lights for objects glShadeModel( GL_SMOOTH ); - if (!LLGLSLShader::sNoFixedFunction) - { - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); - } + gGL.setAmbientLightColor(LLColor4::black); gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT); diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index ebad1f77c4c0e1de5a58fdf19fd58dc4ab11c7fd..db614388f43de0a0a8e79ab440243a6aa5b9953d 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -5057,7 +5057,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) if (!LLGLSLShader::sNoFixedFunction) { LLColor4 ambient = gSky.getTotalAmbientColor(); - glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient.mV); + gGL.setAmbientLightColor(ambient); } // Light 0 = Sun or Moon (All objects) @@ -5285,12 +5285,8 @@ void LLPipeline::enableLights(U32 mask) mLightMask = mask; stop_glerror(); - if (!LLGLSLShader::sNoFixedFunction) - { - LLColor4 ambient = gSky.getTotalAmbientColor(); - glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient.mV); - } - + LLColor4 ambient = gSky.getTotalAmbientColor(); + gGL.setAmbientLightColor(ambient); } } @@ -5342,10 +5338,10 @@ void LLPipeline::enableLightsPreview() if (!LLGLSLShader::sNoFixedFunction) { glEnable(GL_LIGHTING); - LLColor4 ambient = gSavedSettings.getColor4("PreviewAmbientColor"); - glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient.mV); } + LLColor4 ambient = gSavedSettings.getColor4("PreviewAmbientColor"); + gGL.setAmbientLightColor(ambient); LLColor4 diffuse0 = gSavedSettings.getColor4("PreviewDiffuse0"); LLColor4 specular0 = gSavedSettings.getColor4("PreviewSpecular0"); @@ -5403,10 +5399,7 @@ void LLPipeline::enableLightsAvatarEdit(const LLColor4& color) setupAvatarLights(TRUE); enableLights(mask); - if (!LLGLSLShader::sNoFixedFunction) - { - glLightModelfv(GL_LIGHT_MODEL_AMBIENT,color.mV); - } + gGL.setAmbientLightColor(color); } void LLPipeline::enableLightsFullbright(const LLColor4& color) @@ -5415,10 +5408,7 @@ void LLPipeline::enableLightsFullbright(const LLColor4& color) U32 mask = 0x1000; // Non-0 mask, set ambient enableLights(mask); - if (!LLGLSLShader::sNoFixedFunction) - { - glLightModelfv(GL_LIGHT_MODEL_AMBIENT,color.mV); - } + gGL.setAmbientLightColor(color); } void LLPipeline::disableLights()