123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- /**
- * @file llsky.cpp
- * @brief IndraWorld sky class
- *
- * $LicenseInfo:firstyear=2000&license=viewergpl$
- *
- * Copyright (c) 2000-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- // Ideas:
- // -haze should be controlled by global query from sims
- // -need secondary optical effects on sun (flare)
- // -stars should be brought down from sims
- // -star intensity should be driven by global ambient level from sims,
- // so that eclipses, etc can be easily done.
- //
- #include "llviewerprecompiledheaders.h"
- #include "llsky.h"
- #include "llcubemap.h"
- #include "llrenderutils.h"
- #include "lldrawpool.h"
- #include "llpipeline.h"
- #include "llviewercamera.h"
- #include "llviewercontrol.h"
- #include "llviewerobjectlist.h"
- #include "llvoavatarself.h"
- #include "llvowlsky.h"
- LLSky gSky;
- LLSky::LLSky()
- : mLightingGeneration(0),
- mUpdatedThisFrame(true),
- mOverrideSimSunPosition(false)
- {
- }
- void LLSky::cleanup()
- {
- mVOSkyp = NULL;
- mVOWLSkyp = NULL;
- }
- void LLSky::destroyGL()
- {
- if (mVOSkyp.notNull() && mVOSkyp->getCubeMap())
- {
- mVOSkyp->cleanupGL();
- }
- if (mVOWLSkyp.notNull())
- {
- mVOWLSkyp->cleanupGL();
- }
- }
- void LLSky::restoreGL()
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->restoreGL();
- }
- if (mVOWLSkyp.notNull())
- {
- mVOWLSkyp->restoreGL();
- }
- }
- void LLSky::resetVertexBuffers()
- {
- if (gSky.mVOWLSkyp.notNull())
- {
- gSky.mVOWLSkyp->resetVertexBuffers();
- gPipeline.resetVertexBuffers(gSky.mVOWLSkyp->mDrawable);
- gPipeline.markRebuild(gSky.mVOWLSkyp->mDrawable);
- }
- if (gSky.mVOSkyp.notNull())
- {
- gPipeline.resetVertexBuffers(gSky.mVOSkyp->mDrawable);
- gPipeline.markRebuild(gSky.mVOSkyp->mDrawable);
- }
- }
- void LLSky::init()
- {
- mVOWLSkyp =
- (LLVOWLSky*)gObjectList.createObjectViewer(LLViewerObject::LL_VO_WL_SKY,
- NULL);
- gPipeline.createObject(mVOWLSkyp.get());
- mVOSkyp =
- (LLVOSky*)gObjectList.createObjectViewer(LLViewerObject::LL_VO_SKY,
- NULL);
- mVOSkyp->initSunDirection(LLVector3::x_axis);
- gPipeline.createObject((LLViewerObject*)mVOSkyp);
- setSunDirection(LLVector3::x_axis, LLVector3::zero);
- mUpdatedThisFrame = true;
- }
- void LLSky::setCloudDensityAtAgent(F32 cloud_density)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setCloudDensity(cloud_density);
- }
- }
- void LLSky::setWind(const LLVector3& average_wind)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setWind(average_wind);
- }
- }
- void LLSky::updateFog(F32 distance)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->updateFog(distance);
- }
- }
- void LLSky::updateSky()
- {
- if (mVOSkyp.notNull() &&
- gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY))
- {
- mVOSkyp->updateSky();
- }
- }
- //-----------------------------------------------------------------------------
- // Windlight renderer specific methods
- //-----------------------------------------------------------------------------
- void LLSky::setOverrideSun(bool override_sun)
- {
- if (!mOverrideSimSunPosition && override_sun)
- {
- mLastSunDirection = getSunDirection();
- }
- else if (mOverrideSimSunPosition && !override_sun)
- {
- setSunDirection(mLastSunDirection, LLVector3::zero);
- }
- mOverrideSimSunPosition = override_sun;
- }
- void LLSky::setSunDirection(const LLVector3& sun_direction,
- const LLVector3& sun_ang_velocity)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setSunDirection(sun_direction, sun_ang_velocity);
- }
- }
- LLVector3 LLSky::getSunDirection() const
- {
- return mVOSkyp.notNull() ? mVOSkyp->getToSun() : LLVector3::z_axis;
- }
- LLVector3 LLSky::getMoonDirection() const
- {
- return mVOSkyp.notNull() ? mVOSkyp->getToMoon() : LLVector3::z_axis;
- }
- bool LLSky::sunUp() const
- {
- return getSunDirection().mV[2] >= NIGHTTIME_ELEVATION_COS;
- }
- void LLSky::propagateHeavenlyBodies(F32 dt)
- {
- if (!mOverrideSimSunPosition)
- {
- LLVector3 curr_dir = getSunDirection();
- LLVector3 diff = mSunTargDir - curr_dir;
- F32 dist = diff.normalize();
- if (dist > 0.f)
- {
- F32 step = llmin(dist, 0.00005f);
- diff *= step;
- curr_dir += diff;
- curr_dir.normalize();
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setSunDirection(curr_dir, LLVector3::zero);
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- // Extended environment specific methods
- //-----------------------------------------------------------------------------
- void LLSky::setSunScale(F32 sun_scale)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setSunScale(sun_scale);
- }
- }
- void LLSky::setMoonScale(F32 moon_scale)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setMoonScale(moon_scale);
- }
- }
- void LLSky::setSunTextures(const LLUUID& sun_tex1, const LLUUID& sun_tex2)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setSunTextures(sun_tex1, sun_tex2);
- }
- }
- void LLSky::setMoonTextures(const LLUUID& moon_tex1, const LLUUID& moon_tex2)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setMoonTextures(moon_tex1, moon_tex2);
- }
- }
- void LLSky::setCloudNoiseTextures(const LLUUID& noise_tex1,
- const LLUUID& noise_tex2)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setCloudNoiseTextures(noise_tex1, noise_tex2);
- }
- }
- void LLSky::setBloomTextures(const LLUUID& bloom_tex1,
- const LLUUID& bloom_tex2)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setBloomTextures(bloom_tex1, bloom_tex2);
- }
- }
- void LLSky::setSunAndMoonDirectionsCFR(const LLVector3& sun_direction,
- const LLVector3& moon_direction)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setSunAndMoonDirectionsCFR(sun_direction, moon_direction);
- }
- }
- void LLSky::setSunDirectionCFR(const LLVector3& sun_direction)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setSunDirectionCFR(sun_direction);
- }
- }
- void LLSky::setMoonDirectionCFR(const LLVector3& moon_direction)
- {
- if (mVOSkyp.notNull())
- {
- mVOSkyp->setMoonDirectionCFR(moon_direction);
- }
- }
- //-----------------------------------------------------------------------------
- static void render_sun_moon_beacons(const LLVector3& pos_agent,
- const LLVector3& direction,
- const LLColor4& color)
- {
- LLGLSUIDefault gls_ui;
- gUIProgram.bind();
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- LLVector3 pos_end;
- for (S32 i = 0; i < 3; ++i)
- {
- pos_end.mV[i] = pos_agent.mV[i] + (50 * direction.mV[i]);
- }
- gGL.lineWidth(LLPipeline::DebugBeaconLineWidth);
- gGL.begin(LLRender::LINES);
- gGL.color4fv(color.mV);
- gl_draw_3d_cross_lines(pos_agent, 0.5f, 0.5f, 0.5f);
- gl_draw_3d_cross_lines(pos_end, 2.f, 2.f, 2.f);
- gGL.vertex3fv(pos_agent.mV);
- gGL.vertex3fv(pos_end.mV);
- gGL.end(true);
- gGL.lineWidth(1.f);
- gUIProgram.unbind();
- stop_glerror();
- }
- void LLSky::addSunMoonBeacons()
- {
- if (!isAgentAvatarValid() || mVOSkyp.isNull()) return;
- static LLCachedControl<bool> show_sun(gSavedSettings, "sunbeacon");
- if (show_sun)
- {
- static LLColor4 sun_beacon_color(1.f, 0.5f, 0.f, 0.5f);
- render_sun_moon_beacons(gAgentAvatarp->getPositionAgent(),
- mVOSkyp->getSun().getDirection(),
- sun_beacon_color);
- }
- static LLCachedControl<bool> show_moon(gSavedSettings, "moonbeacon");
- if (show_moon)
- {
- static LLColor4 moon_beacon_color(1.f, 0.f, 0.8f, 0.5f);
- render_sun_moon_beacons(gAgentAvatarp->getPositionAgent(),
- mVOSkyp->getMoon().getDirection(),
- moon_beacon_color);
- }
- }
|