diff options
Diffstat (limited to 'indra/newview/lldrawpoolwlsky.cpp')
-rw-r--r-- | indra/newview/lldrawpoolwlsky.cpp | 234 |
1 files changed, 132 insertions, 102 deletions
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index 309f535c39..4b77e18c15 100644 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -33,7 +33,6 @@ #include "pipeline.h" #include "llviewercamera.h" #include "llimage.h" -#include "llwlparammanager.h" #include "llviewershadermgr.h" #include "llglslshader.h" #include "llsky.h" @@ -42,53 +41,22 @@ #include "llface.h" #include "llrender.h" -LLPointer<LLViewerTexture> LLDrawPoolWLSky::sCloudNoiseTexture = NULL; +#include "llenvironment.h" +#include "llatmosphere.h" -LLPointer<LLImageRaw> LLDrawPoolWLSky::sCloudNoiseRawImage = NULL; +static LLStaticHashedString sCamPosLocal("camPosLocal"); static LLGLSLShader* cloud_shader = NULL; static LLGLSLShader* sky_shader = NULL; - +static LLGLSLShader* moon_shader = NULL; LLDrawPoolWLSky::LLDrawPoolWLSky(void) : LLDrawPool(POOL_WL_SKY) { - const std::string cloudNoiseFilename(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight", "clouds2.tga")); - LL_INFOS() << "loading WindLight cloud noise from " << cloudNoiseFilename << LL_ENDL; - - LLPointer<LLImageFormatted> cloudNoiseFile(LLImageFormatted::createFromExtension(cloudNoiseFilename)); - - if(cloudNoiseFile.isNull()) { - LL_ERRS() << "Error: Failed to load cloud noise image " << cloudNoiseFilename << LL_ENDL; - } - - if(cloudNoiseFile->load(cloudNoiseFilename)) - { - sCloudNoiseRawImage = new LLImageRaw(); - - if(cloudNoiseFile->decode(sCloudNoiseRawImage, 0.0f)) - { - //debug use - LL_DEBUGS() << "cloud noise raw image width: " << sCloudNoiseRawImage->getWidth() << " : height: " << sCloudNoiseRawImage->getHeight() << " : components: " << - (S32)sCloudNoiseRawImage->getComponents() << " : data size: " << sCloudNoiseRawImage->getDataSize() << LL_ENDL ; - llassert_always(sCloudNoiseRawImage->getData()) ; - - sCloudNoiseTexture = LLViewerTextureManager::getLocalTexture(sCloudNoiseRawImage.get(), TRUE); - } - else - { - sCloudNoiseRawImage = NULL ; - } - } - - LLWLParamManager::getInstance()->propagateParameters(); } LLDrawPoolWLSky::~LLDrawPoolWLSky() { - //LL_INFOS() << "destructing wlsky draw pool." << LL_ENDL; - sCloudNoiseTexture = NULL; - sCloudNoiseRawImage = NULL; } LLViewerTexture *LLDrawPoolWLSky::getDebugTexture() @@ -107,6 +75,11 @@ void LLDrawPoolWLSky::beginRenderPass( S32 pass ) LLPipeline::sUnderWaterRender ? &gObjectFullbrightNoColorWaterProgram : &gWLCloudProgram; + + moon_shader = + LLPipeline::sUnderWaterRender ? + &gObjectFullbrightNoColorWaterProgram : + &gWLMoonProgram; } void LLDrawPoolWLSky::endRenderPass( S32 pass ) @@ -124,22 +97,28 @@ void LLDrawPoolWLSky::endDeferredPass(S32 pass) } -void LLDrawPoolWLSky::renderDome(F32 camHeightLocal, LLGLSLShader * shader) const +void LLDrawPoolWLSky::renderFsSky(const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader * shader) const { - LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin(); + // Draw WL Sky w/ normal cam pos (where you are) for adv atmo sky + //gGL.syncMatrices(); + sky_shader->uniform3f(sCamPosLocal, camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]); + gSky.mVOWLSkyp->drawFsSky(); +} - llassert_always(NULL != shader); +void LLDrawPoolWLSky::renderDome(const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader * shader) const +{ + llassert_always(NULL != shader); gGL.pushMatrix(); //chop off translation - if (LLPipeline::sReflectionRender && origin.mV[2] > 256.f) + if (LLPipeline::sReflectionRender && camPosLocal.mV[2] > 256.f) { - gGL.translatef(origin.mV[0], origin.mV[1], 256.f-origin.mV[2]*0.5f); + gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], 256.f-camPosLocal.mV[2]*0.5f); } else { - gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]); + gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]); } @@ -151,30 +130,64 @@ void LLDrawPoolWLSky::renderDome(F32 camHeightLocal, LLGLSLShader * shader) cons gGL.translatef(0.f,-camHeightLocal, 0.f); - // Draw WL Sky - static LLStaticHashedString sCamPosLocal("camPosLocal"); + // Draw WL Sky shader->uniform3f(sCamPosLocal, 0.f, camHeightLocal, 0.f); - gSky.mVOWLSkyp->drawDome(); + gSky.mVOWLSkyp->drawDome(); gGL.popMatrix(); } -void LLDrawPoolWLSky::renderSkyHaze(F32 camHeightLocal) const +void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 camHeightLocal) const { - if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY)) - { - LLGLDisable blend(GL_BLEND); - + if (gPipeline.useAdvancedAtmospherics() && gPipeline.canUseWindLightShaders() && gAtmosphere) + { sky_shader->bind(); - /// Render the skydome - renderDome(camHeightLocal, sky_shader); + // bind precomputed textures necessary for calculating sun and sky luminance + sky_shader->bindTexture(LLShaderMgr::TRANSMITTANCE_TEX, gAtmosphere->getTransmittance()); + sky_shader->bindTexture(LLShaderMgr::SCATTER_TEX, gAtmosphere->getScattering()); + sky_shader->bindTexture(LLShaderMgr::SINGLE_MIE_SCATTER_TEX, gAtmosphere->getMieScattering()); + sky_shader->bindTexture(LLShaderMgr::ILLUMINANCE_TEX, gAtmosphere->getIlluminance()); + + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + LLVector4 sun_dir = LLEnvironment::instance().getClampedSunNorm(); + LLVector4 moon_dir = LLEnvironment::instance().getClampedMoonNorm(); + + F32 sunSize = (float)cosf(psky->getSunArcRadians()); + sky_shader->uniform1f(LLShaderMgr::SUN_SIZE, sunSize); + sky_shader->uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1, sun_dir.mV); + sky_shader->uniform3fv(LLShaderMgr::DEFERRED_MOON_DIR, 1, moon_dir.mV); + + // clouds are rendered along with sky in adv atmo + if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && gSky.mVOSkyp->getCloudNoiseTex()) + { + sky_shader->bindTexture(LLShaderMgr::CLOUD_NOISE_MAP, gSky.mVOSkyp->getCloudNoiseTex()); + sky_shader->bindTexture(LLShaderMgr::CLOUD_NOISE_MAP_NEXT, gSky.mVOSkyp->getCloudNoiseTexNext()); + } + + renderFsSky(camPosLocal, camHeightLocal, sky_shader); sky_shader->unbind(); } } +void LLDrawPoolWLSky::renderSkyHaze(const LLVector3& camPosLocal, F32 camHeightLocal) const +{ + LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin(); + + if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY)) + { + LLGLDisable blend(GL_BLEND); + sky_shader->bind(); + + /// Render the skydome + renderDome(origin, camHeightLocal, sky_shader); + + sky_shader->unbind(); + } +} + void LLDrawPoolWLSky::renderStars(void) const { LLGLSPipelineSkyBox gls_sky; @@ -190,14 +203,15 @@ void LLDrawPoolWLSky::renderStars(void) const // *NOTE: we divide by two here and GL_ALPHA_SCALE by two below to avoid // clamping and allow the star_alpha param to brighten the stars. - bool error; LLColor4 star_alpha(LLColor4::black); - star_alpha.mV[3] = LLWLParamManager::getInstance()->mCurParams.getFloat("star_brightness", error) / 2.f; + + // *LAPRAS + star_alpha.mV[3] = LLEnvironment::instance().getCurrentSky()->getStarBrightness() / (2.f + ((rand() >> 16)/65535.0f)); // twinkle twinkle // If start_brightness is not set, exit - if( error ) + if( star_alpha.mV[3] < 0.001 ) { - LL_WARNS() << "star_brightness missing in mCurParams" << LL_ENDL; + LL_DEBUGS("SKY") << "star_brightness below threshold." << LL_ENDL; return; } @@ -233,19 +247,22 @@ void LLDrawPoolWLSky::renderStars(void) const } } -void LLDrawPoolWLSky::renderSkyClouds(F32 camHeightLocal) const +void LLDrawPoolWLSky::renderSkyClouds(const LLVector3& camPosLocal, F32 camHeightLocal) const { - if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && sCloudNoiseTexture.notNull()) + if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && gSky.mVOSkyp->getCloudNoiseTex()) { LLGLEnable blend(GL_BLEND); gGL.setSceneBlendType(LLRender::BT_ALPHA); - gGL.getTexUnit(0)->bind(sCloudNoiseTexture); + gGL.getTexUnit(0)->bind(gSky.mVOSkyp->getCloudNoiseTex()); + gGL.getTexUnit(1)->bind(gSky.mVOSkyp->getCloudNoiseTexNext()); cloud_shader->bind(); + F32 blend_factor = LLEnvironment::instance().getCurrentSky()->getBlendFactor(); + cloud_shader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor); /// Render the skydome - renderDome(camHeightLocal, cloud_shader); + renderDome(camPosLocal, camHeightLocal, cloud_shader); cloud_shader->unbind(); } @@ -271,24 +288,28 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() LLFace * face = gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]; - if (gSky.mVOSkyp->getMoon().getDraw() && face->getGeomCount()) + if (gSky.mVOSkyp->getMoon().getDraw() && face->getGeomCount() && moon_shader) { // *NOTE: even though we already bound this texture above for the // stars register combiners, we bind again here for defensive reasons, // since LLImageGL::bind detects that it's a noop, and optimizes it out. gGL.getTexUnit(0)->bind(face->getTexture()); LLColor4 color(gSky.mVOSkyp->getMoon().getInterpColor()); - F32 a = gSky.mVOSkyp->getMoon().getDirection().mV[2]; + + /*F32 a = gSky.mVOSkyp->getMoon().getDirection().mV[2]; if (a > 0.f) { a = a*a*4.f; - } - - color.mV[3] = llclamp(a, 0.f, 1.f); + } + color.mV[3] = llclamp(a, 0.f, 1.f);*/ if (gPipeline.canUseVertexShaders()) { - gHighlightProgram.bind(); + moon_shader->bind(); + moon_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + moon_shader->uniform3fv(LLShaderMgr::GLOW_LUM_WEIGHTS, 1, LLPipeline::RenderGlowLumWeights.mV); + F32 blend_factor = LLEnvironment::instance().getCurrentSky()->getBlendFactor(); + moon_shader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor); } LLFacePool::LLOverrideFaceColor color_override(this, color); @@ -297,7 +318,7 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() if (gPipeline.canUseVertexShaders()) { - gHighlightProgram.unbind(); + moon_shader->unbind(); } } } @@ -310,7 +331,8 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass) } LL_RECORD_BLOCK_TIME(FTM_RENDER_WL_SKY); - const F32 camHeightLocal = LLWLParamManager::getInstance()->getDomeOffset() * LLWLParamManager::getInstance()->getDomeRadius(); + + const F32 camHeightLocal = LLEnvironment::instance().getCamHeight(); LLGLSNoFog disableFog; LLGLDepthTest depth(GL_TRUE, GL_FALSE); @@ -318,35 +340,44 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass) gGL.setColorMask(true, false); - LLGLSquashToFarClip far_clip(glh_get_current_projection()); + LLGLSquashToFarClip far_clip(get_current_projection()); - renderSkyHaze(camHeightLocal); + LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin(); - LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin(); - gGL.pushMatrix(); + if (gPipeline.canUseWindLightShaders()) + { + if (gPipeline.useAdvancedAtmospherics()) + { + renderSkyHazeDeferred(origin, camHeightLocal); + } + else + { + renderSkyHaze(origin, camHeightLocal); + + LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin(); + gGL.pushMatrix(); - - gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]); + gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]); - gDeferredStarProgram.bind(); - // *NOTE: have to bind a texture here since register combiners blending in - // renderStars() requires something to be bound and we might as well only - // bind the moon's texture once. - gGL.getTexUnit(0)->bind(gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]->getTexture()); + gDeferredStarProgram.bind(); + // *NOTE: have to bind moon textures here since register combiners blending in + // renderStars() requires something to be bound and we might as well only + // bind the moon textures once. + gGL.getTexUnit(0)->bind(gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]->getTexture(LLRender::DIFFUSE_MAP)); + gGL.getTexUnit(1)->bind(gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]->getTexture(LLRender::ALTERNATE_DIFFUSE_MAP)); - renderHeavenlyBodies(); + renderHeavenlyBodies(); - renderStars(); + renderStars(); - gDeferredStarProgram.unbind(); - - gGL.popMatrix(); - - renderSkyClouds(camHeightLocal); + gDeferredStarProgram.unbind(); - gGL.setColorMask(true, true); - //gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + gGL.popMatrix(); + renderSkyClouds(origin, camHeightLocal); + } + } + gGL.setColorMask(true, true); } void LLDrawPoolWLSky::render(S32 pass) @@ -357,18 +388,23 @@ void LLDrawPoolWLSky::render(S32 pass) } LL_RECORD_BLOCK_TIME(FTM_RENDER_WL_SKY); - const F32 camHeightLocal = LLWLParamManager::getInstance()->getDomeOffset() * LLWLParamManager::getInstance()->getDomeRadius(); + const F32 camHeightLocal = LLEnvironment::instance().getCamHeight(); LLGLSNoFog disableFog; LLGLDepthTest depth(GL_TRUE, GL_FALSE); LLGLDisable clip(GL_CLIP_PLANE0); - LLGLSquashToFarClip far_clip(glh_get_current_projection()); + LLGLSquashToFarClip far_clip(get_current_projection()); - renderSkyHaze(camHeightLocal); + LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin(); - LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin(); - gGL.pushMatrix(); + renderSkyHaze(origin, camHeightLocal); + + bool use_advanced = gPipeline.useAdvancedAtmospherics(); + + if (!use_advanced) + { + gGL.pushMatrix(); gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]); @@ -380,11 +416,11 @@ void LLDrawPoolWLSky::render(S32 pass) renderHeavenlyBodies(); renderStars(); - - gGL.popMatrix(); + gGL.popMatrix(); + } - renderSkyClouds(camHeightLocal); + renderSkyClouds(origin, camHeightLocal); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); } @@ -411,15 +447,9 @@ void LLDrawPoolWLSky::resetDrawOrders() //static void LLDrawPoolWLSky::cleanupGL() { - sCloudNoiseTexture = NULL; } //static void LLDrawPoolWLSky::restoreGL() { - if(sCloudNoiseRawImage.notNull()) - { - sCloudNoiseTexture = LLViewerTextureManager::getLocalTexture(sCloudNoiseRawImage.get(), TRUE); - } } - |