aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llvosky.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llvosky.cpp82
1 files changed, 41 insertions, 41 deletions
diff --git a/linden/indra/newview/llvosky.cpp b/linden/indra/newview/llvosky.cpp
index 60f674e..336d409 100644
--- a/linden/indra/newview/llvosky.cpp
+++ b/linden/indra/newview/llvosky.cpp
@@ -4,7 +4,7 @@
4 * 4 *
5 * $LicenseInfo:firstyear=2001&license=viewergpl$ 5 * $LicenseInfo:firstyear=2001&license=viewergpl$
6 * 6 *
7 * Copyright (c) 2001-2008, Linden Research, Inc. 7 * Copyright (c) 2001-2009, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code 9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
@@ -294,7 +294,7 @@ void LLSkyTex::createGLImage(S32 which)
294 294
295void LLSkyTex::bindTexture(BOOL curr) 295void LLSkyTex::bindTexture(BOOL curr)
296{ 296{
297 mImageGL[getWhich(curr)]->bind(); 297 gGL.getTexUnit(0)->bind(mImageGL[getWhich(curr)]);
298} 298}
299 299
300/*************************************** 300/***************************************
@@ -308,7 +308,7 @@ S32 LLVOSky::sTileResX = sResolution/NUM_TILES_X;
308S32 LLVOSky::sTileResY = sResolution/NUM_TILES_Y; 308S32 LLVOSky::sTileResY = sResolution/NUM_TILES_Y;
309 309
310LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) 310LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
311: LLStaticViewerObject(id, pcode, regionp), 311: LLStaticViewerObject(id, pcode, regionp, TRUE),
312 mSun(SUN_DISK_RADIUS), mMoon(MOON_DISK_RADIUS), 312 mSun(SUN_DISK_RADIUS), mMoon(MOON_DISK_RADIUS),
313 mBrightnessScale(1.f), 313 mBrightnessScale(1.f),
314 mBrightnessScaleNew(0.f), 314 mBrightnessScaleNew(0.f),
@@ -528,7 +528,7 @@ void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile)
528 coeff[x_coef] = F32((x<<1) + 1) * inv_res - 1.f; 528 coeff[x_coef] = F32((x<<1) + 1) * inv_res - 1.f;
529 coeff[y_coef] = F32((y<<1) + 1) * inv_res - 1.f; 529 coeff[y_coef] = F32((y<<1) + 1) * inv_res - 1.f;
530 LLVector3 dir(coeff[0], coeff[1], coeff[2]); 530 LLVector3 dir(coeff[0], coeff[1], coeff[2]);
531 dir.normVec(); 531 dir.normalize();
532 mSkyTex[side].setDir(dir, x, y); 532 mSkyTex[side].setDir(dir, x, y);
533 mShinyTex[side].setDir(dir, x, y); 533 mShinyTex[side].setDir(dir, x, y);
534 } 534 }
@@ -762,7 +762,7 @@ void LLVOSky::calcSkyColorWLVert(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLCo
762 Pn *= (-32000.f / Pn[1]); 762 Pn *= (-32000.f / Pn[1]);
763 } 763 }
764 764
765 Plen = Pn.magVec(); 765 Plen = Pn.length();
766 Pn /= Plen; 766 Pn /= Plen;
767 767
768 // Initialize temp variables 768 // Initialize temp variables
@@ -1082,7 +1082,7 @@ BOOL LLVOSky::updateSky()
1082 const static F32 COLOR_CHANGE_THRESHOLD = 0.01f; 1082 const static F32 COLOR_CHANGE_THRESHOLD = 0.01f;
1083 1083
1084 LLVector3 direction = mSun.getDirection(); 1084 LLVector3 direction = mSun.getDirection();
1085 direction.normVec(); 1085 direction.normalize();
1086 const F32 dot_lighting = direction * mLastLightingDirection; 1086 const F32 dot_lighting = direction * mLastLightingDirection;
1087 1087
1088 LLColor3 delta_color; 1088 LLColor3 delta_color;
@@ -1092,7 +1092,7 @@ BOOL LLVOSky::updateSky()
1092 1092
1093 if ( mForceUpdate 1093 if ( mForceUpdate
1094 || ((dot_lighting < LIGHT_DIRECTION_THRESHOLD) 1094 || ((dot_lighting < LIGHT_DIRECTION_THRESHOLD)
1095 || (delta_color.magVec() > COLOR_CHANGE_THRESHOLD) 1095 || (delta_color.length() > COLOR_CHANGE_THRESHOLD)
1096 || !mInitialized) 1096 || !mInitialized)
1097 && !direction.isExactlyZero()) 1097 && !direction.isExactlyZero())
1098 { 1098 {
@@ -1336,8 +1336,8 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable)
1336 const LLVector3 &look_at = LLViewerCamera::getInstance()->getAtAxis(); 1336 const LLVector3 &look_at = LLViewerCamera::getInstance()->getAtAxis();
1337 LLVector3 right = look_at % LLVector3::z_axis; 1337 LLVector3 right = look_at % LLVector3::z_axis;
1338 LLVector3 up = right % look_at; 1338 LLVector3 up = right % look_at;
1339 right.normVec(); 1339 right.normalize();
1340 up.normVec(); 1340 up.normalize();
1341 1341
1342 const static F32 elevation_factor = 0.0f/sResolution; 1342 const static F32 elevation_factor = 0.0f/sResolution;
1343 const F32 cos_max_angle = cosHorizon(elevation_factor); 1343 const F32 cos_max_angle = cosHorizon(elevation_factor);
@@ -1417,8 +1417,8 @@ BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, cons
1417 1417
1418 LLVector3 hb_right = to_dir % LLVector3::z_axis; 1418 LLVector3 hb_right = to_dir % LLVector3::z_axis;
1419 LLVector3 hb_up = hb_right % to_dir; 1419 LLVector3 hb_up = hb_right % to_dir;
1420 hb_right.normVec(); 1420 hb_right.normalize();
1421 hb_up.normVec(); 1421 hb_up.normalize();
1422 1422
1423 //const static F32 cos_max_turn = sqrt(3.f) / 2; // 30 degrees 1423 //const static F32 cos_max_turn = sqrt(3.f) / 2; // 30 degrees
1424 //const F32 cos_turn_right = 1. / (llmax(cos_max_turn, hb_right * right)); 1424 //const F32 cos_turn_right = 1. / (llmax(cos_max_turn, hb_right * right));
@@ -1601,8 +1601,8 @@ void LLVOSky::updateSunHaloGeometry(LLDrawable *drawable )
1601 1601
1602 const LLVector3 right = 2 * (v_corner[2] - v_corner[0]); 1602 const LLVector3 right = 2 * (v_corner[2] - v_corner[0]);
1603 LLVector3 up = 2 * (v_corner[2] - v_corner[3]); 1603 LLVector3 up = 2 * (v_corner[2] - v_corner[3]);
1604 up.normVec(); 1604 up.normalize();
1605 F32 size = right.magVec(); 1605 F32 size = right.length();
1606 up = size * up; 1606 up = size * up;
1607 const LLVector3 draw_pos = 0.25 * (v_corner[0] + v_corner[1] + v_corner[2] + v_corner[3]); 1607 const LLVector3 draw_pos = 0.25 * (v_corner[0] + v_corner[1] + v_corner[2] + v_corner[3]);
1608 1608
@@ -1654,7 +1654,7 @@ void LLVOSky::updateSunHaloGeometry(LLDrawable *drawable )
1654F32 dtReflection(const LLVector3& p, F32 cos_dir_from_top, F32 sin_dir_from_top, F32 diff_angl_dir) 1654F32 dtReflection(const LLVector3& p, F32 cos_dir_from_top, F32 sin_dir_from_top, F32 diff_angl_dir)
1655{ 1655{
1656 LLVector3 P = p; 1656 LLVector3 P = p;
1657 P.normVec(); 1657 P.normalize();
1658 1658
1659 const F32 cos_dir_angle = -P.mV[VZ]; 1659 const F32 cos_dir_angle = -P.mV[VZ];
1660 const F32 sin_dir_angle = sqrt(1 - cos_dir_angle * cos_dir_angle); 1660 const F32 sin_dir_angle = sqrt(1 - cos_dir_angle * cos_dir_angle);
@@ -1679,9 +1679,9 @@ F32 dtClip(const LLVector3& v0, const LLVector3& v1, F32 far_clip2)
1679{ 1679{
1680 F32 dt_clip; 1680 F32 dt_clip;
1681 const LLVector3 otrezok = v1 - v0; 1681 const LLVector3 otrezok = v1 - v0;
1682 const F32 A = otrezok.magVecSquared(); 1682 const F32 A = otrezok.lengthSquared();
1683 const F32 B = v0 * otrezok; 1683 const F32 B = v0 * otrezok;
1684 const F32 C = v0.magVecSquared() - far_clip2; 1684 const F32 C = v0.lengthSquared() - far_clip2;
1685 const F32 det = sqrt(B*B - A*C); 1685 const F32 det = sqrt(B*B - A*C);
1686 dt_clip = (-B - det) / A; 1686 dt_clip = (-B - det) / A;
1687 if ((dt_clip < 0) || (dt_clip > 1)) 1687 if ((dt_clip < 0) || (dt_clip > 1))
@@ -1701,16 +1701,16 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
1701 LLVector3 hb_pos = to_dir * (HORIZON_DIST - 10); 1701 LLVector3 hb_pos = to_dir * (HORIZON_DIST - 10);
1702 LLVector3 to_dir_proj = to_dir; 1702 LLVector3 to_dir_proj = to_dir;
1703 to_dir_proj.mV[VZ] = 0; 1703 to_dir_proj.mV[VZ] = 0;
1704 to_dir_proj.normVec(); 1704 to_dir_proj.normalize();
1705 1705
1706 LLVector3 Right = to_dir % LLVector3::z_axis; 1706 LLVector3 Right = to_dir % LLVector3::z_axis;
1707 LLVector3 Up = Right % to_dir; 1707 LLVector3 Up = Right % to_dir;
1708 Right.normVec(); 1708 Right.normalize();
1709 Up.normVec(); 1709 Up.normalize();
1710 1710
1711 // finding angle between look direction and sprite. 1711 // finding angle between look direction and sprite.
1712 LLVector3 look_at_right = look_at % LLVector3::z_axis; 1712 LLVector3 look_at_right = look_at % LLVector3::z_axis;
1713 look_at_right.normVec(); 1713 look_at_right.normalize();
1714 1714
1715 const static F32 cos_horizon_angle = cosHorizon(0.0f/sResolution); 1715 const static F32 cos_horizon_angle = cosHorizon(0.0f/sResolution);
1716 //const static F32 horizon_angle = acos(cos_horizon_angle); 1716 //const static F32 horizon_angle = acos(cos_horizon_angle);
@@ -1745,7 +1745,7 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
1745 else 1745 else
1746 dt_hor = llmax(0.0f, llmin(1.0f, dt_hor)); 1746 dt_hor = llmax(0.0f, llmin(1.0f, dt_hor));
1747 1747
1748 top_hb.normVec(); 1748 top_hb.normalize();
1749 const F32 cos_angle_of_view = fabs(top_hb.mV[VZ]); 1749 const F32 cos_angle_of_view = fabs(top_hb.mV[VZ]);
1750 const F32 extension = llmin (5.0f, 1.0f / cos_angle_of_view); 1750 const F32 extension = llmin (5.0f, 1.0f / cos_angle_of_view);
1751 1751
@@ -1762,11 +1762,11 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
1762 F32 cos_dir_from_top[2]; 1762 F32 cos_dir_from_top[2];
1763 1763
1764 LLVector3 dir = stretch_corner[0]; 1764 LLVector3 dir = stretch_corner[0];
1765 dir.normVec(); 1765 dir.normalize();
1766 cos_dir_from_top[0] = dir.mV[VZ]; 1766 cos_dir_from_top[0] = dir.mV[VZ];
1767 1767
1768 dir = stretch_corner[1]; 1768 dir = stretch_corner[1];
1769 dir.normVec(); 1769 dir.normalize();
1770 cos_dir_from_top[1] = dir.mV[VZ]; 1770 cos_dir_from_top[1] = dir.mV[VZ];
1771 1771
1772 const F32 sin_dir_from_top = sqrt(1 - cos_dir_from_top[0] * cos_dir_from_top[0]); 1772 const F32 sin_dir_from_top = sqrt(1 - cos_dir_from_top[0] * cos_dir_from_top[0]);
@@ -1789,7 +1789,7 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
1789 for (vtx = 0; vtx < 2; ++vtx) 1789 for (vtx = 0; vtx < 2; ++vtx)
1790 { 1790 {
1791 LLVector3 light_proj = v_corner[vtx]; 1791 LLVector3 light_proj = v_corner[vtx];
1792 light_proj.normVec(); 1792 light_proj.normalize();
1793 1793
1794 const F32 z = light_proj.mV[VZ]; 1794 const F32 z = light_proj.mV[VZ];
1795 const F32 sin_angle = sqrt(1 - z * z); 1795 const F32 sin_angle = sqrt(1 - z * z);
@@ -1813,9 +1813,9 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
1813 S32 side = 0; 1813 S32 side = 0;
1814 LLVector3 refl_corn_norm[2]; 1814 LLVector3 refl_corn_norm[2];
1815 refl_corn_norm[0] = v_refl_corner[1]; 1815 refl_corn_norm[0] = v_refl_corner[1];
1816 refl_corn_norm[0].normVec(); 1816 refl_corn_norm[0].normalize();
1817 refl_corn_norm[1] = v_refl_corner[3]; 1817 refl_corn_norm[1] = v_refl_corner[3];
1818 refl_corn_norm[1].normVec(); 1818 refl_corn_norm[1].normalize();
1819 1819
1820 F32 cos_refl_look_at[2]; 1820 F32 cos_refl_look_at[2];
1821 cos_refl_look_at[0] = refl_corn_norm[0] * look_at; 1821 cos_refl_look_at[0] = refl_corn_norm[0] * look_at;
@@ -1833,13 +1833,13 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
1833 F32 dt_clip; 1833 F32 dt_clip;
1834 F32 vtx_near2, vtx_far2; 1834 F32 vtx_near2, vtx_far2;
1835 1835
1836 if ((vtx_far2 = v_refl_corner[side].magVecSquared()) > far_clip2) 1836 if ((vtx_far2 = v_refl_corner[side].lengthSquared()) > far_clip2)
1837 { 1837 {
1838 // whole thing is sprite: reflection is beyond far clip plane. 1838 // whole thing is sprite: reflection is beyond far clip plane.
1839 dt_clip = 1.1f; 1839 dt_clip = 1.1f;
1840 quads = 1; 1840 quads = 1;
1841 } 1841 }
1842 else if ((vtx_near2 = v_refl_corner[side+1].magVecSquared()) > far_clip2) 1842 else if ((vtx_near2 = v_refl_corner[side+1].lengthSquared()) > far_clip2)
1843 { 1843 {
1844 // part is reflection, the rest is sprite. 1844 // part is reflection, the rest is sprite.
1845 dt_clip = dtClip(v_refl_corner[side + 1], v_refl_corner[side], far_clip2); 1845 dt_clip = dtClip(v_refl_corner[side + 1], v_refl_corner[side], far_clip2);
@@ -1903,7 +1903,7 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
1903 { 1903 {
1904 for (S32 vtx = 0; vtx < 4; ++vtx) 1904 for (S32 vtx = 0; vtx < 4; ++vtx)
1905 { 1905 {
1906 F32 ratio = far_clip / v_refl_corner[vtx].magVec(); 1906 F32 ratio = far_clip / v_refl_corner[vtx].length();
1907 *(verticesp++) = v_refl_corner[vtx] = ratio * v_refl_corner[vtx] + mCameraPosAgent; 1907 *(verticesp++) = v_refl_corner[vtx] = ratio * v_refl_corner[vtx] + mCameraPosAgent;
1908 } 1908 }
1909 const LLVector3 draw_pos = 0.25 * 1909 const LLVector3 draw_pos = 0.25 *
@@ -1912,10 +1912,10 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
1912 } 1912 }
1913 else 1913 else
1914 { 1914 {
1915 F32 ratio = far_clip / v_refl_corner[1].magVec(); 1915 F32 ratio = far_clip / v_refl_corner[1].length();
1916 v_sprite_corner[1] = v_refl_corner[1] * ratio; 1916 v_sprite_corner[1] = v_refl_corner[1] * ratio;
1917 1917
1918 ratio = far_clip / v_refl_corner[3].magVec(); 1918 ratio = far_clip / v_refl_corner[3].length();
1919 v_sprite_corner[3] = v_refl_corner[3] * ratio; 1919 v_sprite_corner[3] = v_refl_corner[3] * ratio;
1920 1920
1921 v_refl_corner[1] = (1 - dt_clip) * v_refl_corner[1] + dt_clip * v_refl_corner[0]; 1921 v_refl_corner[1] = (1 - dt_clip) * v_refl_corner[1] + dt_clip * v_refl_corner[0];
@@ -2039,20 +2039,20 @@ void LLVOSky::updateFog(const F32 distance)
2039 LLVector3 tosun = getToSunLast(); 2039 LLVector3 tosun = getToSunLast();
2040 const F32 tosun_z = tosun.mV[VZ]; 2040 const F32 tosun_z = tosun.mV[VZ];
2041 tosun.mV[VZ] = 0.f; 2041 tosun.mV[VZ] = 0.f;
2042 tosun.normVec(); 2042 tosun.normalize();
2043 LLVector3 perp_tosun; 2043 LLVector3 perp_tosun;
2044 perp_tosun.mV[VX] = -tosun.mV[VY]; 2044 perp_tosun.mV[VX] = -tosun.mV[VY];
2045 perp_tosun.mV[VY] = tosun.mV[VX]; 2045 perp_tosun.mV[VY] = tosun.mV[VX];
2046 LLVector3 tosun_45 = tosun + perp_tosun; 2046 LLVector3 tosun_45 = tosun + perp_tosun;
2047 tosun_45.normVec(); 2047 tosun_45.normalize();
2048 2048
2049 F32 delta = 0.06f; 2049 F32 delta = 0.06f;
2050 tosun.mV[VZ] = delta; 2050 tosun.mV[VZ] = delta;
2051 perp_tosun.mV[VZ] = delta; 2051 perp_tosun.mV[VZ] = delta;
2052 tosun_45.mV[VZ] = delta; 2052 tosun_45.mV[VZ] = delta;
2053 tosun.normVec(); 2053 tosun.normalize();
2054 perp_tosun.normVec(); 2054 perp_tosun.normalize();
2055 tosun_45.normVec(); 2055 tosun_45.normalize();
2056 2056
2057 // Sky colors, just slightly above the horizon in the direction of the sun, perpendicular to the sun, and at a 45 degree angle to the sun. 2057 // Sky colors, just slightly above the horizon in the direction of the sun, perpendicular to the sun, and at a 45 degree angle to the sun.
2058 initAtmospherics(); 2058 initAtmospherics();
@@ -2202,8 +2202,8 @@ F32 azimuth(const LLVector3 &v)
2202 2202
2203void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity) 2203void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity)
2204{ 2204{
2205 LLVector3 sun_direction = (sun_dir.magVec() == 0) ? LLVector3::x_axis : sun_dir; 2205 LLVector3 sun_direction = (sun_dir.length() == 0) ? LLVector3::x_axis : sun_dir;
2206 sun_direction.normVec(); 2206 sun_direction.normalize();
2207 mSun.setDirection(sun_direction); 2207 mSun.setDirection(sun_direction);
2208 mSun.renewDirection(); 2208 mSun.renewDirection();
2209 mSun.setAngularVelocity(sun_ang_velocity); 2209 mSun.setAngularVelocity(sun_ang_velocity);
@@ -2222,8 +2222,8 @@ void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_an
2222 2222
2223void LLVOSky::setSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity) 2223void LLVOSky::setSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity)
2224{ 2224{
2225 LLVector3 sun_direction = (sun_dir.magVec() == 0) ? LLVector3::x_axis : sun_dir; 2225 LLVector3 sun_direction = (sun_dir.length() == 0) ? LLVector3::x_axis : sun_dir;
2226 sun_direction.normVec(); 2226 sun_direction.normalize();
2227 2227
2228 // Push the sun "South" as it approaches directly overhead so that we can always see bump mapping 2228 // Push the sun "South" as it approaches directly overhead so that we can always see bump mapping
2229 // on the upward facing faces of cubes. 2229 // on the upward facing faces of cubes.
@@ -2239,7 +2239,7 @@ void LLVOSky::setSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang
2239 // Blend between normal sun dir and adjusted sun dir based on how close we are 2239 // Blend between normal sun dir and adjusted sun dir based on how close we are
2240 // to having the sun overhead. 2240 // to having the sun overhead.
2241 mBumpSunDir = adjustedDir * sunDot + newDir * (1.0f - sunDot); 2241 mBumpSunDir = adjustedDir * sunDot + newDir * (1.0f - sunDot);
2242 mBumpSunDir.normVec(); 2242 mBumpSunDir.normalize();
2243 2243
2244 F32 dp = mLastLightingDirection * sun_direction; 2244 F32 dp = mLastLightingDirection * sun_direction;
2245 mSun.setDirection(sun_direction); 2245 mSun.setDirection(sun_direction);