scatterSky.h

Engine/source/environment/scatterSky.h

More...

Classes:

Public Defines

define

Detailed Description

Public Defines

CURVE_COUNT() 5
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SCATTERSKY_H_
 25#define _SCATTERSKY_H_
 26
 27#ifndef _SCENEOBJECT_H_
 28#include "scene/sceneObject.h"
 29#endif
 30#ifndef _GFXPRIMITIVEBUFFER_H_
 31#include "gfx/gfxPrimitiveBuffer.h"
 32#endif
 33#ifndef _GFXVERTEXBUFFER_H_
 34#include "gfx/gfxVertexBuffer.h"
 35#endif
 36#ifndef _GFXSTATEBLOCK_H_
 37#include "gfx/gfxStateBlock.h"
 38#endif
 39#ifndef _RENDERPASSMANAGER_H_
 40#include "renderInstance/renderPassManager.h"
 41#endif
 42#ifndef _PRIMBUILDER_H_
 43#include "gfx/primBuilder.h"
 44#endif
 45#ifndef _LIGHTINFO_H_
 46#include "lighting/lightInfo.h"
 47#endif
 48#ifndef _LIGHTFLAREDATA_H_
 49#include "T3D/lightFlareData.h"
 50#endif
 51#ifndef _TRESPONSECURVE_H_
 52#include "math/util/tResponseCurve.h"
 53#endif
 54
 55class LightInfo;
 56class SphereMesh;
 57class TimeOfDay;
 58class CubemapData;
 59class MatrixSet;
 60
 61class ScatterSky : public SceneObject, public ISceneLight
 62{
 63   typedef SceneObject Parent;
 64
 65public:
 66
 67   enum MaskBits
 68   {
 69      UpdateMask = Parent::NextFreeMask,
 70      TimeMask = Parent::NextFreeMask << 1,
 71      NextFreeMask = Parent::NextFreeMask << 2
 72   };
 73
 74   ScatterSky();
 75   ~ScatterSky();
 76
 77   // SimObject
 78   bool onAdd();
 79   void onRemove();
 80
 81   // ISceneLight
 82   virtual void submitLights( LightManager *lm, bool staticLighting );
 83   virtual LightInfo* getLight() { return mLight; }
 84
 85   // ConsoleObject
 86   DECLARE_CONOBJECT(ScatterSky);
 87   void inspectPostApply();
 88   static void initPersistFields();
 89
 90   // Network
 91   U32  packUpdate  ( NetConnection *conn, U32 mask, BitStream *stream );
 92   void unpackUpdate( NetConnection *conn,           BitStream *stream );
 93
 94   void prepRenderImage( SceneRenderState* state );
 95  
 96   ///
 97   void setAzimuth( F32 azimuth );
 98   ///
 99   void setElevation( F32 elevation );
100
101   ///
102   F32 getAzimuth() const { return mSunAzimuth; }
103   ///
104   F32 getElevation() const { return mSunElevation; }
105
106protected:
107
108   void _render( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
109   void _debugRender( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
110   void _renderMoon( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
111
112   void _initVBIB();
113   bool _initShader();
114   void _initMoon();
115   void _initCurves();
116
117   F32 _getRayleighPhase( F32 fCos2 );
118   F32 _getMiePhase( F32 fCos, F32 fCos2, F32 g, F32 g2 );
119   F32 _vernierScale( F32 fCos );
120
121   void _generateSkyPoints();
122
123   void _getColor( const Point3F &pos, LinearColorF *outColor );
124   void _getFogColor( LinearColorF *outColor );
125   void _getAmbientColor( LinearColorF *outColor );
126   void _getSunColor( LinearColorF *outColor );
127   void _interpolateColors();
128
129   void _conformLights();
130
131   void _updateTimeOfDay( TimeOfDay *timeofDay, F32 time );
132
133   // static protected field set methods
134   static bool ptSetElevation( void *object, const char *index, const char *data );
135   static bool ptSetAzimuth( void *object, const char *index, const char *data );
136
137   // SimObject.
138   virtual void _onSelected();
139   virtual void _onUnselected();
140
141protected:
142
143   static const F32 smEarthRadius;
144   static const F32 smAtmosphereRadius;
145   static const F32 smViewerHeight;
146
147#define CURVE_COUNT 5
148
149   FloatCurve mCurves[CURVE_COUNT];
150
151   U32 mVertCount;
152   U32 mPrimCount;
153
154   F32 mRayleighScattering;
155   F32 mRayleighScattering4PI;
156   F32 mSunSize;
157   F32 mMieScattering;
158   F32 mMieScattering4PI;
159
160   F32 mSkyBrightness;
161   F32 mMiePhaseAssymetry;
162
163   F32 mOuterRadius;
164   F32 mScale;
165   LinearColorF mWavelength;
166   F32 mWavelength4[3];
167   F32 mRayleighScaleDepth;
168   F32 mMieScaleDepth;
169
170   F32 mSphereInnerRadius;
171   F32 mSphereOuterRadius;
172
173   F32 mExposure;
174   F32 mNightInterpolant;
175   F32 mZOffset;
176
177   VectorF mLightDir;
178   VectorF mSunDir;
179
180   F32 mSunAzimuth;
181   F32 mSunElevation;
182   F32 mMoonAzimuth;
183   F32 mMoonElevation;
184
185   F32 mTimeOfDay;
186
187   F32 mBrightness;
188
189   LinearColorF mNightColor;
190   LinearColorF mNightFogColor;
191
192   LinearColorF mAmbientColor;   ///< Not a field
193   LinearColorF mSunColor;       ///< Not a field
194   LinearColorF mFogColor;       ///< Not a field
195
196   LinearColorF mAmbientScale;
197   LinearColorF mSunScale;
198   LinearColorF mFogScale;
199
200   LightInfo *mLight;
201
202   bool mCastShadows;
203   S32 mStaticRefreshFreq;
204   S32 mDynamicRefreshFreq;
205   bool mDirty;
206
207   LightFlareData *mFlareData;
208   LightFlareState mFlareState;
209   F32 mFlareScale;
210
211   bool mMoonEnabled;
212   String mMoonMatName;
213   BaseMatInstance *mMoonMatInst;
214   F32 mMoonScale;
215   LinearColorF mMoonTint;
216   VectorF mMoonLightDir;
217   CubemapData *mNightCubemap;
218   String mNightCubemapName;
219   bool mUseNightCubemap;
220   MatrixSet *mMatrixSet;
221
222   Vector<Point3F> mSkyPoints;
223
224   // Prim buffer, vertex buffer and shader for rendering.
225   GFXPrimitiveBufferHandle mPrimBuffer;
226   GFXVertexBufferHandle<GFXVertexP> mVB;
227   GFXShaderRef mShader;
228
229   GFXStateBlockRef mStateBlock;
230
231   // Shared shader constant blocks
232   GFXShaderConstBufferRef mShaderConsts;
233   GFXShaderConstHandle *mModelViewProjSC;
234   GFXShaderConstHandle *mMiscSC;                     // Camera height, cam height squared, scale and scale over depth.
235   GFXShaderConstHandle *mSphereRadiiSC;              // Inner and out radius, and inner and outer radius squared.
236   GFXShaderConstHandle *mScatteringCoefficientsSC;   // Rayleigh sun brightness, mie sun brightness and 4 * PI * coefficients.
237   GFXShaderConstHandle *mCamPosSC;
238   GFXShaderConstHandle *mLightDirSC;
239   GFXShaderConstHandle *mSunDirSC;
240   GFXShaderConstHandle *mNightColorSC;
241   GFXShaderConstHandle *mInverseWavelengthSC;
242   GFXShaderConstHandle *mNightInterpolantAndExposureSC;
243   GFXShaderConstHandle *mUseCubemapSC;
244   F32 mColorizeAmt;
245   LinearColorF mColorize;
246   GFXShaderConstHandle *mColorizeSC;
247
248};
249
250#endif // _SCATTERSKY_H_
251