mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
Engine directory for ticket #1
This commit is contained in:
parent
352279af7a
commit
7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions
229
Engine/source/scene/reflector.h
Normal file
229
Engine/source/scene/reflector.h
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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;
|
||||
};
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
GFXCubemap* getCubemap() const { return cubemap; }
|
||||
|
||||
void updateFace( const ReflectParams ¶ms, U32 faceidx );
|
||||
F32 calcFaceScore( const ReflectParams ¶ms, U32 faceidx );
|
||||
|
||||
protected:
|
||||
|
||||
GFXTexHandle depthBuff;
|
||||
GFXTextureTargetRef renderTarget;
|
||||
GFXCubemapHandle cubemap;
|
||||
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 = 0;
|
||||
}
|
||||
|
||||
virtual ~PlaneReflector() {}
|
||||
|
||||
void registerReflector( SceneObject *inObject,
|
||||
ReflectorDesc *inDesc );
|
||||
|
||||
virtual F32 calcScore( const ReflectParams ¶ms );
|
||||
virtual void updateReflection( const ReflectParams ¶ms );
|
||||
|
||||
/// Set up camera matrix for a reflection on the plane
|
||||
MatrixF getCameraReflection( MatrixF &camTrans );
|
||||
|
||||
/// Oblique frustum clipping - use near plane of zbuffer as a clip plane
|
||||
MatrixF getFrustumClipProj( MatrixF &modelview );
|
||||
|
||||
protected:
|
||||
|
||||
U32 mLastTexSize;
|
||||
|
||||
// The camera position at the last update.
|
||||
Point3F mLastPos;
|
||||
|
||||
// The camera direction at the last update.
|
||||
VectorF mLastDir;
|
||||
|
||||
public:
|
||||
|
||||
GFXTextureTargetRef reflectTarget;
|
||||
GFXTexHandle reflectTex;
|
||||
PlaneF refplane;
|
||||
bool objectSpace;
|
||||
};
|
||||
|
||||
#endif // _REFLECTOR_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue