123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- //-----------------------------------------------------------------------------
- // 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 _REFLECTOR_H_
- #define _REFLECTOR_H_
- #ifndef _GFXCUBEMAP_H_
- #include "gfx/gfxCubemap.h"
- #endif
- #ifndef _GFXTARGET_H_
- #include "gfx/gfxTarget.h"
- #endif
- #ifndef _SIMDATABLOCK_H_
- #include "console/simDatablock.h"
- #endif
- #ifndef _MMATH_H_
- #include "math/mMath.h"
- #endif
- #ifndef _MATHUTIL_FRUSTUM_H_
- #include "math/util/frustum.h"
- #endif
- struct CameraQuery;
- class Point2I;
- class Frustum;
- class SceneManager;
- class SceneObject;
- class GFXOcclusionQuery;
- struct ReflectParams
- {
- const CameraQuery *query;
- Point2I viewportExtent;
- Frustum culler;
- U32 startOfUpdateMs;
- S8 eyeId;
- };
- class ReflectorDesc : public SimDataBlock
- {
- typedef SimDataBlock Parent;
- public:
- ReflectorDesc();
- virtual ~ReflectorDesc();
- DECLARE_CONOBJECT( ReflectorDesc );
- static void initPersistFields();
- virtual void packData( BitStream *stream );
- virtual void unpackData( BitStream* stream );
- virtual bool preload( bool server, String &errorStr );
- U32 texSize;
- F32 nearDist;
- F32 farDist;
- U32 objectTypeMask;
- F32 detailAdjust;
- F32 priority;
- U32 maxRateMs;
- bool useOcclusionQuery;
- //U32 lastLodSize;
- };
- class ReflectorBase
- {
- public:
- ReflectorBase();
- virtual ~ReflectorBase();
- bool isEnabled() const { return mEnabled; }
- virtual void unregisterReflector();
- virtual F32 calcScore( const ReflectParams ¶ms );
- virtual void updateReflection( const ReflectParams ¶ms ) {}
- GFXOcclusionQuery* getOcclusionQuery() const { return mOcclusionQuery; }
- bool isOccluded() const { return mOccluded; }
- /// Returns true if this reflector is in the process of rendering.
- bool isRendering() const { return mIsRendering; }
- /// Signifies that the query has not finished yet and a new query
- /// does not need to be submitted.
- bool mQueryPending;
- protected:
- bool mEnabled;
- bool mIsRendering;
- GFXOcclusionQuery *mOcclusionQuery;
- bool mOccluded;
- SceneObject *mObject;
- ReflectorDesc *mDesc;
- public:
- // These are public because some of them
- // are exposed as fields.
- F32 score;
- U32 lastUpdateMs;
-
- };
- typedef Vector<ReflectorBase*> ReflectorList;
- class CubeReflector : public ReflectorBase
- {
- typedef ReflectorBase Parent;
- public:
- CubeReflector();
- virtual ~CubeReflector() {}
- void registerReflector( SceneObject *inObject,
- ReflectorDesc *inDesc );
- virtual void unregisterReflector();
- virtual void updateReflection( const ReflectParams ¶ms, Point3F explicitPostion = Point3F::Max);
- GFXCubemap* getCubemap() const { return mCubemap; }
- void updateFace( const ReflectParams ¶ms, U32 faceidx, Point3F explicitPostion = Point3F::Max);
- F32 calcFaceScore( const ReflectParams ¶ms, U32 faceidx );
- protected:
- GFXTexHandle mDepthBuff;
- GFXTextureTargetRef mRenderTarget;
- GFXCubemapHandle mCubemap;
- U32 mLastTexSize;
- class CubeFaceReflector : public ReflectorBase
- {
- typedef ReflectorBase Parent;
- friend class CubeReflector;
- public:
- U32 faceIdx;
- CubeReflector *cube;
- virtual void updateReflection( const ReflectParams ¶ms ) { cube->updateFace( params, faceIdx ); }
- virtual F32 calcScore( const ReflectParams ¶ms );
- };
- CubeFaceReflector mFaces[6];
- };
- class PlaneReflector : public ReflectorBase
- {
- typedef ReflectorBase Parent;
- public:
- PlaneReflector()
- {
- refplane.set( Point3F(0,0,0), Point3F(0,0,1) );
- objectSpace = false;
- mLastTexSize = Point2I(0,0);
- }
- virtual ~PlaneReflector() {}
- void registerReflector( SceneObject *inObject,
- ReflectorDesc *inDesc );
- virtual F32 calcScore( const ReflectParams ¶ms );
- virtual void updateReflection( const ReflectParams ¶ms );
- /// Set up the GFX matrices
- void setGFXMatrices( const MatrixF &camTrans );
- /// Set up camera matrix for a reflection on the plane
- MatrixF getCameraReflection( const MatrixF &camTrans );
- /// Oblique frustum clipping - use near plane of zbuffer as a clip plane
- MatrixF getFrustumClipProj( MatrixF &modelview );
- protected:
- Point2I mLastTexSize;
- // The camera position at the last update.
- Point3F mLastPos;
- // The camera direction at the last update.
- VectorF mLastDir;
- public:
- GFXTextureTargetRef reflectTarget;
- GFXTexHandle innerReflectTex[2]; /// < Textures we actually render to
- GFXTexHandle reflectTex; ///< Last texture we rendered to
- GFXTexHandle depthBuff;
- PlaneF refplane;
- bool objectSpace;
- };
- #endif // _REFLECTOR_H_
|