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