aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llvosky.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/llvosky.h
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/llvosky.h')
-rw-r--r--linden/indra/newview/llvosky.h407
1 files changed, 72 insertions, 335 deletions
diff --git a/linden/indra/newview/llvosky.h b/linden/indra/newview/llvosky.h
index 2600541..70aa3af 100644
--- a/linden/indra/newview/llvosky.h
+++ b/linden/indra/newview/llvosky.h
@@ -48,6 +48,7 @@
48// 48//
49 49
50const F32 HORIZON_DIST = 1024.0f; 50const F32 HORIZON_DIST = 1024.0f;
51const F32 SKY_BOX_MULT = 16.0f;
51const F32 HEAVENLY_BODY_DIST = HORIZON_DIST - 10.f; 52const F32 HEAVENLY_BODY_DIST = HORIZON_DIST - 10.f;
52const F32 HEAVENLY_BODY_FACTOR = 0.1f; 53const F32 HEAVENLY_BODY_FACTOR = 0.1f;
53const F32 HEAVENLY_BODY_SCALE = HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR; 54const F32 HEAVENLY_BODY_SCALE = HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR;
@@ -85,7 +86,6 @@ LL_FORCE_INLINE LLColor3 color_div(const LLColor3 &col1, const LLColor3 &col2)
85} 86}
86 87
87LLColor3 color_norm(const LLColor3 &col); 88LLColor3 color_norm(const LLColor3 &col);
88LLVector3 move_vec (const LLVector3& v, F32 cos_max_angle);
89BOOL clip_quad_to_horizon(F32& t_left, F32& t_right, LLVector3 v_clipped[4], 89BOOL clip_quad_to_horizon(F32& t_left, F32& t_right, LLVector3 v_clipped[4],
90 const LLVector3 v_corner[4], const F32 cos_max_angle); 90 const LLVector3 v_corner[4], const F32 cos_max_angle);
91F32 clip_side_to_horizon(const LLVector3& v0, const LLVector3& v1, const F32 cos_max_angle); 91F32 clip_side_to_horizon(const LLVector3& v0, const LLVector3& v1, const F32 cos_max_angle);
@@ -111,18 +111,6 @@ inline F32 color_min(const LLColor3 &col)
111 return llmin(col.mV[0], col.mV[1], col.mV[2]); 111 return llmin(col.mV[0], col.mV[1], col.mV[2]);
112} 112}
113 113
114inline LLColor3 color_norm_abs(const LLColor3 &col)
115{
116 const F32 m = color_max(col);
117 if (m > 1e-6)
118 {
119 return 1.f/m * col;
120 }
121 else return col;
122}
123
124
125
126class LLFace; 114class LLFace;
127class LLHaze; 115class LLHaze;
128 116
@@ -135,7 +123,7 @@ private:
135 static S32 sComponents; 123 static S32 sComponents;
136 LLPointer<LLImageGL> mImageGL[2]; 124 LLPointer<LLImageGL> mImageGL[2];
137 LLPointer<LLImageRaw> mImageRaw[2]; 125 LLPointer<LLImageRaw> mImageRaw[2];
138 LLColor3 *mSkyData; 126 LLColor4 *mSkyData;
139 LLVector3 *mSkyDirs; // Cache of sky direction vectors 127 LLVector3 *mSkyDirs; // Cache of sky direction vectors
140 static S32 sCurrent; 128 static S32 sCurrent;
141 static F32 sInterpVal; 129 static F32 sInterpVal;
@@ -163,7 +151,8 @@ protected:
163 static S32 getWhich(const BOOL curr) { return curr ? sCurrent : getNext(); } 151 static S32 getWhich(const BOOL curr) { return curr ? sCurrent : getNext(); }
164 152
165 void initEmpty(const S32 tex); 153 void initEmpty(const S32 tex);
166 void create(F32 brightness_scale, const LLColor3& multiscatt); 154
155 void create(F32 brightness);
167 156
168 void setDir(const LLVector3 &dir, const S32 i, const S32 j) 157 void setDir(const LLVector3 &dir, const S32 i, const S32 j)
169 { 158 {
@@ -177,7 +166,7 @@ protected:
177 return mSkyDirs[offset]; 166 return mSkyDirs[offset];
178 } 167 }
179 168
180 void setPixel(const LLColor3 &col, const S32 i, const S32 j) 169 void setPixel(const LLColor4 &col, const S32 i, const S32 j)
181 { 170 {
182 S32 offset = i * sResolution + j; 171 S32 offset = i * sResolution + j;
183 mSkyData[offset] = col; 172 mSkyData[offset] = col;
@@ -203,7 +192,7 @@ protected:
203 void createGLImage(BOOL curr=TRUE); 192 void createGLImage(BOOL curr=TRUE);
204}; 193};
205 194
206 195/// TODO Move into the stars draw pool (and rename them appropriately).
207class LLHeavenBody 196class LLHeavenBody
208{ 197{
209protected: 198protected:
@@ -261,27 +250,6 @@ public:
261 return sInterpVal * mColor + (1 - sInterpVal) * mColorCached; 250 return sInterpVal * mColor + (1 - sInterpVal) * mColorCached;
262 } 251 }
263 252
264// LLColor3 getDiffuseColor() const
265// {
266// LLColor3 dif = mColorCached;
267// dif.clamp();
268// return 2 * dif;
269// }
270
271// LLColor4 getAmbientColor(const LLColor3& scatt, F32 scale) const
272// {
273// const F32 min_val = 0.05f;
274// LLColor4 col = LLColor4(scale * (0.8f * color_norm_abs(getDiffuseColor()) + 0.2f * scatt));
275// //F32 left = max(0, 1 - col.mV[0]);
276// if (col.mV[0] >= 0.9)
277// {
278// col.mV[1] = llmax(col.mV[1], 2.f * min_val);
279// col.mV[2] = llmax(col.mV[2], min_val);
280// }
281// col.setAlpha(1.f);
282// return col;
283// }
284
285 const F32& getHorizonVisibility() const { return mHorizonVisibility; } 253 const F32& getHorizonVisibility() const { return mHorizonVisibility; }
286 void setHorizonVisibility(const F32 c = 1) { mHorizonVisibility = c; } 254 void setHorizonVisibility(const F32 c = 1) { mHorizonVisibility = c; }
287 const F32& getVisibility() const { return mVisibility; } 255 const F32& getVisibility() const { return mVisibility; }
@@ -440,82 +408,55 @@ protected:
440 F32 mAbsCoef; 408 F32 mAbsCoef;
441}; 409};
442 410
443class LLTranspMap
444{
445public:
446 LLTranspMap() : mElevation(0), mMaxAngle(0), mStep(5), mHaze(NULL), mT(NULL) {}
447 ~LLTranspMap()
448 {
449 delete[] mT;
450 mT = NULL;
451 }
452
453 void init(const F32 elev, const F32 step, const F32 h, const LLHaze* const haze);
454
455 F32 calcHeight(const LLVector3& pos) const
456 {
457 return pos.magVec() - EARTH_RADIUS ;
458 }
459
460 BOOL hasHaze() const
461 {
462 return mHaze != NULL;
463 }
464 411
465 LLColor3 calcSigExt(const F32 h) const 412class LLCubeMap;
466 {
467 return LLHaze::calcAirSca(h) + (hasHaze() ? mHaze->calcSigExt(h) : LLColor3(0, 0, 0));
468 }
469 413
470 inline void calcAirTransp(const F32 cos_angle, LLColor3 &result) const; 414// turn on floating point precision
471 LLColor3 calcAirTranspDir(const F32 elevation, const LLVector3 &dir) const; 415// in vs2003 for this class. Otherwise
472 LLColor3 getHorizonAirTransp () const { return mT[mMapSize-1]; } 416// black dots go everywhere from 7:10 - 8:50
473 F32 hitsAtmEdge(const LLVector3& orig, const LLVector3& dir) const; 417#if LL_MSVC && __MSVC_VER__ < 8
418#pragma optimize("p", on)
419#endif
474 420
475protected:
476 F32 mAtmHeight;
477 F32 mElevation;
478 F32 mMaxAngle;
479 F32 mCosMaxAngle;
480 F32 mStep;
481 F32 mStepInv;
482 S32 mMapSize;
483 const LLHaze *mHaze;
484 LLColor3 *mT; // transparency values in all directions
485 //starting with mAngleBelowHorz at mElevation
486};
487 421
488class LLTranspMapSet 422class LLVOSky : public LLStaticViewerObject
489{ 423{
490protected:
491 F32 *mHeights;
492 LLTranspMap *mTransp;
493 S32 mSize;
494 F32 mMediaHeight;
495 const LLHaze *mHaze;
496 S32 lerp(F32& dt, S32& indx, const F32 h) const;
497public: 424public:
498 LLTranspMapSet() : mHeights(NULL), mTransp(NULL), mHaze(NULL) {} 425 /// WL PARAMS
499 ~LLTranspMapSet(); 426 F32 dome_radius;
500 427 F32 dome_offset_ratio;
501 void init (S32 size, F32 first_step, F32 media_height, const LLHaze* const haze); 428 LLColor3 sunlight_color;
502 S32 getSize() const { return mSize; } 429 LLColor3 ambient;
503 F32 getMediaHeight() const { return mMediaHeight; } 430 F32 gamma;
504 const LLTranspMap& getLastTransp() const { return mTransp[mSize-1]; } 431 LLVector4 lightnorm;
505 F32 getLastHeight() const { return mHeights[mSize-1]; } 432 LLVector4 unclamped_lightnorm;
506 const LLTranspMap& getMap(const S32 n) const { return mTransp[n]; } 433 LLColor3 blue_density;
507 F32 getHeight(const S32 n) const { return mHeights[n]; } 434 LLColor3 blue_horizon;
508 BOOL isReady() const { return mTransp != NULL; } 435 F32 haze_density;
509 436 LLColor3 haze_horizon;
510 inline LLColor3 calcTransp(const F32 cos_angle, const F32 h) const; 437 F32 density_multiplier;
511 inline void calcTransp(const F32 cos_angle, const F32 h, LLColor3 &result) const; 438 F32 max_y;
512}; 439 LLColor3 glow;
440 F32 cloud_shadow;
441 LLColor3 cloud_color;
442 F32 cloud_scale;
443 LLColor3 cloud_pos_density1;
444 LLColor3 cloud_pos_density2;
445
446public:
447 void initAtmospherics(void);
448 void calcAtmospherics(void);
449 LLColor3 createDiffuseFromWL(LLColor3 diffuse, LLColor3 ambient, LLColor3 sundiffuse, LLColor3 sunambient);
450 LLColor3 createAmbientFromWL(LLColor3 ambient, LLColor3 sundiffuse, LLColor3 sunambient);
513 451
514class LLCubeMap; 452 void calcSkyColorWLVert(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLColor3 & vary_CloudColorSun,
453 LLColor3 & vary_CloudColorAmbient, F32 & vary_CloudDensity,
454 LLVector2 vary_HorizontalProjection[2]);
515 455
456 LLColor3 calcSkyColorWLFrag(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLColor3 & vary_CloudColorSun,
457 LLColor3 & vary_CloudColorAmbient, F32 & vary_CloudDensity,
458 LLVector2 vary_HorizontalProjection[2]);
516 459
517class LLVOSky : public LLStaticViewerObject
518{
519public: 460public:
520 enum 461 enum
521 { 462 {
@@ -529,6 +470,7 @@ public:
529 FACE_MOON, // was 7 470 FACE_MOON, // was 7
530 FACE_BLOOM, // was 8 471 FACE_BLOOM, // was 8
531 FACE_REFLECTION, // was 10 472 FACE_REFLECTION, // was 10
473 FACE_DUMMY, //for an ATI bug --bao
532 FACE_COUNT 474 FACE_COUNT
533 }; 475 };
534 476
@@ -539,9 +481,7 @@ public:
539 void init(); 481 void init();
540 void initCubeMap(); 482 void initCubeMap();
541 void initEmpty(); 483 void initEmpty();
542 BOOL isReady() const { return mTransp.isReady(); } 484
543 const LLTranspMapSet& getTransp() const { return mTransp; }
544
545 void cleanupGL(); 485 void cleanupGL();
546 void restoreGL(); 486 void restoreGL();
547 487
@@ -557,26 +497,12 @@ public:
557 void initSkyTextureDirs(const S32 side, const S32 tile); 497 void initSkyTextureDirs(const S32 side, const S32 tile);
558 void createSkyTexture(const S32 side, const S32 tile); 498 void createSkyTexture(const S32 side, const S32 tile);
559 499
560 void updateBrightestDir(); 500 LLColor4 calcSkyColorInDir(const LLVector3& dir, bool isShiny = false);
561 void calcBrightnessScaleAndColors(); 501
562
563 LLColor3 calcSkyColorInDir(const LLVector3& dir);
564 void calcSkyColorInDir(LLColor3& res, LLColor3& transp,
565 const LLVector3& dir) const;
566 LLColor4 calcInScatter(LLColor4& transp, const LLVector3 &point, F32 exag) const;
567 void calcInScatter( LLColor3& res, LLColor3& transp,
568 const LLVector3& P, F32 exag) const;
569
570 // Not currently used.
571 //LLColor3 calcGroundFog(LLColor3& transp, const LLVector3 &view_dir, F32 obj_dist) const;
572 //void calcGroundFog(LLColor3& res, LLColor3& transp, const LLVector3 view_dir, F32 dist) const;
573
574 LLColor3 calcRadianceAtPoint(const LLVector3& pos) const 502 LLColor3 calcRadianceAtPoint(const LLVector3& pos) const
575 { 503 {
576 const F32 cos_angle = calcUpVec(pos) * getToSunLast(); 504 F32 radiance = mBrightnessScaleGuess * mSun.getIntensity();
577 LLColor3 tr; 505 return LLColor3(radiance, radiance, radiance);
578 mTransp.calcTransp(cos_angle, calcHeight(pos), tr);
579 return mBrightnessScaleGuess * mSun.getIntensity() * tr;
580 } 506 }
581 507
582 const LLHeavenBody& getSun() const { return mSun; } 508 const LLHeavenBody& getSun() const { return mSun; }
@@ -597,58 +523,16 @@ public:
597 LLColor4 getFogColor() const { return mFogColor; } 523 LLColor4 getFogColor() const { return mFogColor; }
598 LLColor4 getGLFogColor() const { return mGLFogCol; } 524 LLColor4 getGLFogColor() const { return mGLFogCol; }
599 525
600 LLVector3 calcUpVec(const LLVector3 &pos) const
601 {
602 LLVector3 v = pos - mEarthCenter;
603 v.normVec();
604 return v;
605 }
606
607 F32 calcHeight(const LLVector3& pos) const
608 {
609 return dist_vec(pos, mEarthCenter) - EARTH_RADIUS;
610 }
611
612 // Phase function for atmospheric scattering.
613 // co = cos ( theta )
614 F32 calcAirPhaseFunc(const F32 co) const
615 {
616 return (0.75f * (1.f + co*co));
617 }
618
619
620 BOOL isSameFace(S32 idx, const LLFace* face) const { return mFace[idx] == face; } 526 BOOL isSameFace(S32 idx, const LLFace* face) const { return mFace[idx] == face; }
621 527
622 void initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity) 528 void initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity);
623 {
624 LLVector3 sun_direction = (sun_dir.magVec() == 0) ? LLVector3::x_axis : sun_dir;
625 sun_direction.normVec();
626 mSun.setDirection(sun_direction);
627 mSun.renewDirection();
628 mSun.setAngularVelocity(sun_ang_velocity);
629 mMoon.setDirection(-mSun.getDirection());
630 mMoon.renewDirection();
631 mLastLightingDirection = mSun.getDirection();
632
633 if ( !isReady() )
634 {
635 init();
636 LLSkyTex::stepCurrent();
637 }
638 }
639 529
640 void setSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity); 530 void setSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity);
641 531
642 void updateHaze();
643
644 BOOL updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 side, const BOOL is_sun, 532 BOOL updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 side, const BOOL is_sun,
645 LLHeavenBody& hb, const F32 sin_max_angle, 533 LLHeavenBody& hb, const F32 sin_max_angle,
646 const LLVector3 &up, const LLVector3 &right); 534 const LLVector3 &up, const LLVector3 &right);
647 535
648 LLVector3 toHorizon(const LLVector3& dir, F32 delta = 0) const
649 {
650 return move_vec(dir, cosHorizon(delta));
651 }
652 F32 cosHorizon(const F32 delta = 0) const 536 F32 cosHorizon(const F32 delta = 0) const
653 { 537 {
654 const F32 sin_angle = EARTH_RADIUS/(EARTH_RADIUS + mCameraPosAgent.mV[2]); 538 const F32 sin_angle = EARTH_RADIUS/(EARTH_RADIUS + mCameraPosAgent.mV[2]);
@@ -681,18 +565,14 @@ public:
681 BOOL isReflFace(const LLFace* face) const { return face == mFace[FACE_REFLECTION]; } 565 BOOL isReflFace(const LLFace* face) const { return face == mFace[FACE_REFLECTION]; }
682 LLFace* getReflFace() const { return mFace[FACE_REFLECTION]; } 566 LLFace* getReflFace() const { return mFace[FACE_REFLECTION]; }
683 567
684 F32 calcHitsEarth(const LLVector3& orig, const LLVector3& dir) const;
685 F32 calcHitsAtmEdge(const LLVector3& orig, const LLVector3& dir) const;
686 LLViewerImage* getSunTex() const { return mSunTexturep; } 568 LLViewerImage* getSunTex() const { return mSunTexturep; }
687 LLViewerImage* getMoonTex() const { return mMoonTexturep; } 569 LLViewerImage* getMoonTex() const { return mMoonTexturep; }
688 LLViewerImage* getBloomTex() const { return mBloomTexturep; } 570 LLViewerImage* getBloomTex() const { return mBloomTexturep; }
689 571 void forceSkyUpdate(void) { mForceUpdate = TRUE; }
690 void generateScatterMap();
691 LLImageGL* getScatterMap() { return mScatterMap; }
692 572
693public: 573public:
694 static F32 sNighttimeBrightness; // [0,2] default = 1.0 574 LLFace *mFace[FACE_COUNT];
695 LLFace *mFace[FACE_COUNT]; 575 LLVector3 mBumpSunDir;
696 576
697protected: 577protected:
698 ~LLVOSky(); 578 ~LLVOSky();
@@ -705,6 +585,7 @@ protected:
705 static S32 sTileResX; 585 static S32 sTileResX;
706 static S32 sTileResY; 586 static S32 sTileResY;
707 LLSkyTex mSkyTex[6]; 587 LLSkyTex mSkyTex[6];
588 LLSkyTex mShinyTex[6];
708 LLHeavenBody mSun; 589 LLHeavenBody mSun;
709 LLHeavenBody mMoon; 590 LLHeavenBody mMoon;
710 LLVector3 mSunDefaultPosition; 591 LLVector3 mSunDefaultPosition;
@@ -718,7 +599,6 @@ protected:
718 LLColor3 mBrightestPointNew; 599 LLColor3 mBrightestPointNew;
719 F32 mBrightnessScaleGuess; 600 F32 mBrightnessScaleGuess;
720 LLColor3 mBrightestPointGuess; 601 LLColor3 mBrightestPointGuess;
721 LLTranspMapSet mTransp;
722 LLHaze mHaze; 602 LLHaze mHaze;
723 F32 mHazeConcentration; 603 F32 mHazeConcentration;
724 BOOL mWeatherChange; 604 BOOL mWeatherChange;
@@ -751,10 +631,23 @@ protected:
751 631
752 LLFrameTimer mUpdateTimer; 632 LLFrameTimer mUpdateTimer;
753 633
754 LLPointer<LLImageGL> mScatterMap; 634public:
755 LLPointer<LLImageRaw> mScatterMapRaw; 635 //by bao
636 //fake vertex buffer updating
637 //to guaranttee at least updating one VBO buffer every frame
638 //to walk around the bug caused by ATI card --> DEV-3855
639 //
640 void createDummyVertexBuffer() ;
641 void updateDummyVertexBuffer() ;
642
643 BOOL mHeavenlyBodyUpdated ;
756}; 644};
757 645
646// turn it off
647#if LL_MSVC && __MSVC_VER__ < 8
648#pragma optimize("p", off)
649#endif
650
758// Utility functions 651// Utility functions
759F32 azimuth(const LLVector3 &v); 652F32 azimuth(const LLVector3 &v);
760F32 color_norm_pow(LLColor3& col, F32 e, BOOL postmultiply = FALSE); 653F32 color_norm_pow(LLColor3& col, F32 e, BOOL postmultiply = FALSE);
@@ -776,161 +669,5 @@ inline void LLHaze::calcAirSca(const F32 h, LLColor3 &result)
776 result *= calcFalloff(h); 669 result *= calcFalloff(h);
777} 670}
778 671
779// Given cos of the angle between direction of interest and zenith,
780// compute transparency by interpolation of known values.
781inline void LLTranspMap::calcAirTransp(const F32 cos_angle, LLColor3 &result) const
782{
783 if (cos_angle > 1.f)
784 {
785 result = mT[0];
786 return;
787 }
788 if (cos_angle < mCosMaxAngle - 0.1f)
789 {
790 result.setVec(0.f, 0.f, 0.f);
791 return;
792 }
793 if (cos_angle < mCosMaxAngle)
794 {
795 result = mT[mMapSize-1];
796 return;
797 }
798
799
800 const F32 relative = (1 - cos_angle)*mStepInv;
801 const S32 index = llfloor(relative);
802 const F32 dt = relative - index;
803
804 if (index >= (mMapSize-1))
805 {
806 result = mT[0];
807 return;
808 }
809// result = mT[index];
810// LLColor3 res2(mT[index+1]);
811// result *= 1 - dt;
812// res2 *= dt;
813// result += res2;
814
815 const LLColor3& color1 = mT[index];
816 const LLColor3& color2 = mT[index + 1];
817
818 const F32 x1 = color1.mV[VX];
819 const F32 x2 = color2.mV[VX];
820 result.mV[VX] = x1 - dt * (x1 - x2);
821
822 const F32 y1 = color1.mV[VY];
823 const F32 y2 = color2.mV[VY];
824 result.mV[VY] = y1 - dt * (y1 - y2);
825
826 const F32 z1 = color1.mV[VZ];
827 const F32 z2 = color2.mV[VZ];
828 result.mV[VZ] = z1 - dt * (z1 - z2);
829}
830
831
832
833// Returns the translucency of the atmosphere along the ray in the sky.
834// dir is assumed to be normalized
835inline void LLTranspMapSet::calcTransp(const F32 cos_angle, const F32 h, LLColor3 &result) const
836{
837 S32 indx = 0;
838 F32 dt = 0.f;
839 const S32 status = lerp(dt, indx, h);
840
841 if (status < 0)
842 {
843 mTransp[0].calcAirTransp(cos_angle, result);
844 return;
845 }
846 if (status > 0)
847 {
848 mTransp[NO_STEPS].calcAirTransp(cos_angle, result);
849 return;
850 }
851
852 mTransp[indx].calcAirTransp(cos_angle, result);
853 result *= 1 - dt;
854
855 LLColor3 transp_above;
856
857 mTransp[indx + 1].calcAirTransp(cos_angle, transp_above);
858 transp_above *= dt;
859 result += transp_above;
860}
861
862
863inline LLColor3 LLTranspMapSet::calcTransp(const F32 cos_angle, const F32 h) const
864{
865 LLColor3 result;
866 S32 indx = 0;
867 F32 dt = 0;
868 const S32 status = lerp(dt, indx, h);
869
870 if (status < 0)
871 {
872 mTransp[0].calcAirTransp(cos_angle, result);
873 return result;
874 }
875 if (status > 0)
876 {
877 mTransp[NO_STEPS].calcAirTransp(cos_angle, result);
878 return result;
879 }
880
881 mTransp[indx].calcAirTransp(cos_angle, result);
882 result *= 1 - dt;
883
884 LLColor3 transp_above;
885
886 mTransp[indx + 1].calcAirTransp(cos_angle, transp_above);
887 transp_above *= dt;
888 result += transp_above;
889 return result;
890}
891
892
893// Returns -1 if height < 0; +1 if height > max height; 0 if within range
894inline S32 LLTranspMapSet::lerp(F32& dt, S32& indx, const F32 h) const
895{
896 static S32 last_indx = 0;
897
898 if (h < 0)
899 {
900 return -1;
901 }
902 if (h > getLastHeight())
903 {
904 return 1;
905 }
906
907 if (h < mHeights[last_indx])
908 {
909 indx = last_indx-1;
910 while (mHeights[indx] > h)
911 {
912 indx--;
913 }
914 last_indx = indx;
915 }
916 else if (h > mHeights[last_indx+1])
917 {
918 indx = last_indx+1;
919 while (mHeights[indx+1] < h)
920 {
921 indx++;
922 }
923 last_indx = indx;
924 }
925 else
926 {
927 indx = last_indx;
928 }
929
930 const F32 h_below = mHeights[indx];
931 const F32 h_above = mHeights[indx+1];
932 dt = (h - h_below) / (h_above - h_below);
933 return 0;
934}
935 672
936#endif 673#endif