123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
-
- #ifndef _VolumetricFog_H_
- #define _VolumetricFog_H_
-
- #ifndef _SCENEOBJECT_H_
- #include "scene/sceneObject.h"
- #endif
- #ifndef _MATTEXTURETARGET_H_
- #include "materials/matTextureTarget.h"
- #endif
- #ifndef _GFXSHADER_H_
- #include "gfx/gfxShader.h"
- #endif
- #ifndef _GFXTARGET_H_
- #include "gfx/gfxTarget.h"
- #endif
- #ifndef _GFXVERTEXBUFFER_H_
- #include "gfx/gfxVertexBuffer.h"
- #endif
- #ifndef _TSSHAPE_H_
- #include "ts/tsShape.h"
- #endif
- #ifndef _POST_EFFECT_H_
- #include "postFx/postEffect.h"
- #endif
-
- #include "gui/core/guiCanvas.h"
- #ifndef _ASSET_PTR_H_
- #include "assets/assetPtr.h"
- #endif
- #ifndef SHAPEASSET_H
- #include "T3D/assets/ShapeAsset.h"
- #endif
-
- class VolumetricFogRTManager;
-
- class VolumetricFog : public SceneObject
- {
- typedef SceneObject Parent;
-
- // Maskbits for updating
- enum
- {
- VolumetricFogMask = Parent::NextFreeMask,
- FogColorMask = Parent::NextFreeMask << 1,
- FogDensityMask = Parent::NextFreeMask << 2,
- FogModulationMask = Parent::NextFreeMask << 3,
- FogPostFXMask = Parent::NextFreeMask << 4,
- FogShapeMask = Parent::NextFreeMask << 5,
- NextFreeMask = Parent::NextFreeMask << 6
- };
-
- // Struct which holds the shape details
- struct meshes
- {
- F32 det_size;
- S32 sub_shape;
- S32 obj_det;
- U32 num_verts;
- GFXVertexPNTT *verts;
- Vector <GFXPrimitive> *piArray;
- Vector <U32> *indices;
- };
- DECLARE_SHAPEASSET(VolumetricFog, Shape, onShapeChanged);
- DECLARE_ASSET_NET_SETGET(VolumetricFog, Shape, FogShapeMask);
-
- protected:
- // Rendertargets;
- GFXTextureTargetRef z_buf;
- NamedTexTargetRef mDeferredTarget;
- NamedTexTargetRef mDepthBufferTarget;
- NamedTexTargetRef mFrontBufferTarget;
-
- // Shaders
- GFXShaderRef mShader;
- GFXShaderRef mDeferredShader;
- GFXShaderRef mReflectionShader;
-
- // Stateblocks
- GFXStateBlockDesc descD;
- GFXStateBlockDesc descF;
- GFXStateBlockDesc desc_preD;
- GFXStateBlockDesc desc_preF;
- GFXStateBlockDesc desc_refl;
-
- GFXStateBlockRef mStateblockD;
- GFXStateBlockRef mStateblockF;
- GFXStateBlockRef mStateblock_preD;
- GFXStateBlockRef mStateblock_preF;
- GFXStateBlockRef mStateblock_refl;
-
- // Shaderconstants
- GFXShaderConstBufferRef mShaderConsts;
- GFXShaderConstHandle *mModelViewProjSC;
- GFXShaderConstHandle *mFadeSizeSC;
- GFXShaderConstHandle *mFogColorSC;
- GFXShaderConstHandle *mFogDensitySC;
- GFXShaderConstHandle *mPreBias;
- GFXShaderConstHandle *mAccumTime;
- GFXShaderConstHandle *mIsTexturedSC;
- GFXShaderConstHandle *mModSpeedSC;
- GFXShaderConstHandle *mModStrengthSC;
- GFXShaderConstHandle *mViewPointSC;
- GFXShaderConstHandle *mTexScaleSC;
- GFXShaderConstHandle *mTexTilesSC;
-
- GFXShaderConstBufferRef mPPShaderConsts;
- GFXShaderConstHandle *mPPModelViewProjSC;
- GFXShaderConstHandle *mAmbientColorSC;
-
- GFXShaderConstBufferRef mReflShaderConsts;
- GFXShaderConstHandle *mReflModelViewProjSC;
- GFXShaderConstHandle *mReflFogColorSC;
- GFXShaderConstHandle *mReflFogDensitySC;
- GFXShaderConstHandle *mReflFogStrengthSC;
-
- // Vertex and Prim. Buffer
- GFXVertexBufferHandle<GFXVertexPNTT> mVB;
- GFXPrimitiveBufferHandle mPB;
-
- // Fog volume data;
-
- ColorI mFogColor;
- F32 mFogDensity;
- bool mIgnoreWater;
- bool mReflect;
- Vector<meshes> det_size;
- bool mShapeLoaded;
- F32 mPixelSize;
- F32 mFadeSize;
- U32 mCurDetailLevel;
- U32 mNumDetailLevels;
- F32 mObjSize;
- F32 mRadius;
- OrientedBox3F ColBox;
- VectorF mObjScale;
- F32 mMinDisplaySize;
- F32 mInvScale;
-
- // Fog Modulation data
- DECLARE_IMAGEASSET(VolumetricFog, Texture, onImageChanged, GFXStaticTextureSRGBProfile);
- DECLARE_ASSET_NET_SETGET(VolumetricFog, Texture, FogModulationMask);
- bool mIsTextured;
- F32 mTexTiles;
- F32 mStrength;
- Point2F mSpeed1;
- Point2F mSpeed2;
- Point4F mSpeed;
- Point2F mTexScale;
-
- // Fog Rendering data
- Point3F camPos;
- Point2F mViewPoint;
- F32 mFOV;
- F32 viewDist;
- bool mIsVBDirty;
- bool mIsPBDirty;
- bool mCamInFog;
- bool mResizing;
- PlatformWindow *mPlatformWindow;
-
- // Reflections
- F32 mFogReflStrength;
-
- // PostFX
- PostEffect *glowFX;
- bool mUseGlow;
- F32 mGlowStrength;
- U8 mGlowing;
- F32 mCurGlow;
-
- bool mModifLightRays;
- F32 mLightRayMod;
- F32 mOldLightRayStrength;
-
- GameConnection* conn;
- U32 mCounter;
-
- void ResizeRT(PlatformWindow *win, bool resize);
-
- protected:
- // Protected methods
- bool onAdd();
- void onRemove();
- void handleResize(VolumetricFogRTManager *RTM, bool resize);
- void handleCanvasResize(GuiCanvas* canvas);
-
- bool LoadShape();
- bool setupRenderer();
- void InitTexture();
- bool UpdateBuffers(U32 dl,bool force=true);
-
- void processTick(const Move *move);
- void _enterFog(ShapeBase *control);
- void _leaveFog(ShapeBase *control);
- static bool _setShapeAsset(void* obj, const char* index, const char* data);
- void onImageChanged() {}
-
- public:
- // Public methods
- VolumetricFog();
- ~VolumetricFog();
-
- static void initPersistFields();
- virtual void inspectPostApply();
-
- U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
- void unpackUpdate(NetConnection *conn, BitStream *stream);
-
- void prepRenderImage(SceneRenderState* state);
- void render(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat);
- void reflect_render(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat);
-
- // Methods for modifying & networking various fog elements
- // Used in script
- void setFogColor(LinearColorF color);
- void setFogColor(ColorI color);
- void setFogDensity(F32 density);
- void setFogModulation(F32 strength, Point2F speed1, Point2F speed2);
- void setFogGlow(bool on_off, F32 strength);
- void setFogLightray(bool on_off, F32 strength);
- bool isInsideFog();
- bool setShapeAsset(const StringTableEntry shapeAssetId);
- void onShapeChanged() {}
-
- DECLARE_CONOBJECT(VolumetricFog);
-
- DECLARE_CALLBACK(void, onEnterFog, (SimObjectId obj));
- DECLARE_CALLBACK(void, onLeaveFog, (SimObjectId obj));
- };
- #endif
|