Torque3D Documentation / _generateds / VolumetricFog.h

VolumetricFog.h

Engine/source/environment/VolumetricFog.h

More...

Classes:

Detailed Description

  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 _VolumetricFog_H_
 25#define _VolumetricFog_H_
 26   
 27#ifndef _SCENEOBJECT_H_
 28#include "scene/sceneObject.h"
 29#endif
 30#ifndef _MATTEXTURETARGET_H_
 31#include "materials/matTextureTarget.h"
 32#endif
 33#ifndef _GFXSHADER_H_
 34#include "gfx/gfxShader.h"
 35#endif
 36#ifndef _GFXTARGET_H_
 37#include "gfx/gfxTarget.h"
 38#endif
 39#ifndef _GFXVERTEXBUFFER_H_
 40#include "gfx/gfxVertexBuffer.h"
 41#endif
 42#ifndef _TSSHAPE_H_
 43#include "ts/tsShape.h"
 44#endif
 45#ifndef _POST_EFFECT_H_
 46#include "postFx/postEffect.h"
 47#endif
 48   
 49#include "gui/core/guiCanvas.h"
 50
 51#ifndef _ASSET_PTR_H_
 52#include "assets/assetPtr.h"
 53#endif 
 54#ifndef SHAPEASSET_H
 55#include "T3D/assets/ShapeAsset.h"
 56#endif 
 57   
 58class VolumetricFogRTManager;
 59   
 60class VolumetricFog : public SceneObject
 61{
 62   typedef SceneObject Parent;
 63   
 64   // Maskbits for updating
 65   enum
 66   {
 67      VolumetricFogMask = Parent::NextFreeMask,
 68      FogColorMask = Parent::NextFreeMask << 1,
 69      FogDensityMask = Parent::NextFreeMask << 2,
 70      FogModulationMask = Parent::NextFreeMask << 3,
 71      FogPostFXMask = Parent::NextFreeMask << 4,
 72      FogShapeMask = Parent::NextFreeMask << 5,
 73      NextFreeMask = Parent::NextFreeMask << 6
 74   };
 75   
 76// Struct which holds the shape details
 77   struct meshes
 78   {
 79      F32 det_size;
 80      S32 sub_shape;
 81      S32 obj_det;
 82      U32 num_verts;
 83      GFXVertexPNTT *verts;
 84      Vector <GFXPrimitive> *piArray;
 85      Vector <U32> *indices;
 86   };
 87   
 88   protected:
 89      // Rendertargets;
 90      GFXTextureTargetRef z_buf;
 91      NamedTexTargetRef mDeferredTarget;
 92      NamedTexTargetRef mDepthBufferTarget;
 93      NamedTexTargetRef mFrontBufferTarget;
 94   
 95      // Fog Modulation texture
 96      GFXTexHandle mTexture;
 97   
 98      // Shaders
 99      GFXShaderRef mShader;
100      GFXShaderRef mDeferredShader;
101      GFXShaderRef mReflectionShader;
102   
103      // Stateblocks
104      GFXStateBlockDesc descD;
105      GFXStateBlockDesc descF;
106      GFXStateBlockDesc desc_preD;
107      GFXStateBlockDesc desc_preF;
108      GFXStateBlockDesc desc_refl;
109   
110      GFXStateBlockRef mStateblockD;
111      GFXStateBlockRef mStateblockF;
112      GFXStateBlockRef mStateblock_preD;
113      GFXStateBlockRef mStateblock_preF;
114      GFXStateBlockRef mStateblock_refl;
115   
116      // Shaderconstants
117      GFXShaderConstBufferRef mShaderConsts;
118      GFXShaderConstHandle *mModelViewProjSC;
119      GFXShaderConstHandle *mFadeSizeSC;
120      GFXShaderConstHandle *mFogColorSC;
121      GFXShaderConstHandle *mFogDensitySC;
122      GFXShaderConstHandle *mPreBias;
123      GFXShaderConstHandle *mAccumTime;
124      GFXShaderConstHandle *mIsTexturedSC;
125      GFXShaderConstHandle *mModSpeedSC;
126      GFXShaderConstHandle *mModStrengthSC;
127      GFXShaderConstHandle *mViewPointSC;
128      GFXShaderConstHandle *mTexScaleSC;
129      GFXShaderConstHandle *mTexTilesSC;
130   
131      GFXShaderConstBufferRef mPPShaderConsts;
132      GFXShaderConstHandle *mPPModelViewProjSC;
133
134      GFXShaderConstHandle *mAmbientColorSC;
135   
136      GFXShaderConstBufferRef mReflShaderConsts;
137      GFXShaderConstHandle *mReflModelViewProjSC;
138      GFXShaderConstHandle *mReflFogColorSC;
139      GFXShaderConstHandle *mReflFogDensitySC;
140      GFXShaderConstHandle *mReflFogStrengthSC;
141   
142      // Vertex and Prim. Buffer
143      GFXVertexBufferHandle<GFXVertexPNTT> mVB;
144      GFXPrimitiveBufferHandle mPB;
145   
146      // Fog volume data;
147      AssetPtr<ShapeAsset> mShapeAsset;
148      StringTableEntry mShapeAssetId;
149
150      StringTableEntry mShapeName;
151      ColorI mFogColor;
152      F32 mFogDensity;
153      bool mIgnoreWater;
154      bool mReflect;
155      Vector<meshes> det_size;
156      bool mShapeLoaded;
157      F32 mPixelSize;
158      F32 mFadeSize;
159      U32 mCurDetailLevel;
160      U32 mNumDetailLevels;
161      F32 mObjSize;
162      F32 mRadius;
163      OrientedBox3F ColBox;
164      VectorF mObjScale;
165      F32 mMinDisplaySize;
166      F32 mInvScale;
167   
168      // Fog Modulation data
169      String mTextureName;
170      bool mIsTextured;
171      F32 mTexTiles;
172      F32 mStrength;
173      Point2F mSpeed1;
174      Point2F mSpeed2;
175      Point4F mSpeed;
176      Point2F mTexScale;
177   
178      // Fog Rendering data
179      Point3F camPos;
180      Point2F mViewPoint;
181      F32 mFOV;
182      F32 viewDist;
183      bool mIsVBDirty;
184      bool mIsPBDirty;
185      bool mCamInFog;
186      bool mResizing;
187      PlatformWindow *mPlatformWindow;
188   
189      // Reflections
190      F32 mFogReflStrength;
191   
192      // PostFX
193      PostEffect *glowFX;
194      bool mUseGlow;
195      F32 mGlowStrength;
196      U8 mGlowing;
197      F32 mCurGlow;
198   
199      bool mModifLightRays;
200      F32 mLightRayMod;
201      F32 mOldLightRayStrength;
202   
203      GameConnection* conn;
204      U32 mCounter;
205   
206      void ResizeRT(PlatformWindow *win, bool resize);
207   
208   protected:
209      // Protected methods
210      bool onAdd();
211      void onRemove();
212      void handleResize(VolumetricFogRTManager *RTM, bool resize);
213      void handleCanvasResize(GuiCanvas* canvas);
214   
215      bool LoadShape();
216      bool setupRenderer();
217      void InitTexture();
218      bool UpdateBuffers(U32 dl,bool force=true);
219   
220      void processTick(const Move *move);
221      void _enterFog(ShapeBase *control);
222      void _leaveFog(ShapeBase *control);
223
224      static bool _setShapeAsset(void* obj, const char* index, const char* data);
225   
226   public:
227      // Public methods
228      VolumetricFog();
229      ~VolumetricFog();
230   
231      static void initPersistFields();
232      virtual void inspectPostApply();
233   
234      U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
235      void unpackUpdate(NetConnection *conn, BitStream *stream);
236   
237      void prepRenderImage(SceneRenderState* state);
238      void render(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat);
239      void reflect_render(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat);
240   
241      // Methods for modifying & networking various fog elements
242      // Used in script
243      void setFogColor(LinearColorF color);
244      void setFogColor(ColorI color);
245      void setFogDensity(F32 density);
246      void setFogModulation(F32 strength, Point2F speed1, Point2F speed2);
247      void setFogGlow(bool on_off, F32 strength);
248      void setFogLightray(bool on_off, F32 strength);
249      bool isInsideFog();
250
251      bool setShapeAsset(const StringTableEntry shapeAssetId);
252   
253      DECLARE_CONOBJECT(VolumetricFog);
254   
255      DECLARE_CALLBACK(void, onEnterFog, (SimObjectId obj));
256      DECLARE_CALLBACK(void, onLeaveFog, (SimObjectId obj));
257};
258#endif
259