mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 09:04:38 +00:00
Merge pull request #133 from DavidWyand-GG/issue132-RenderOcclusionMgrRendering
Fix for Issue #132 for RenderOcclusionMgr Rendering
This commit is contained in:
commit
34db24a3e8
2 changed files with 66 additions and 71 deletions
|
|
@ -29,7 +29,11 @@
|
||||||
#include "gfx/gfxDrawUtil.h"
|
#include "gfx/gfxDrawUtil.h"
|
||||||
#include "gfx/gfxTransformSaver.h"
|
#include "gfx/gfxTransformSaver.h"
|
||||||
#include "math/util/sphereMesh.h"
|
#include "math/util/sphereMesh.h"
|
||||||
|
#include "materials/materialManager.h"
|
||||||
|
#include "materials/sceneData.h"
|
||||||
|
#include "math/util/matrixSet.h"
|
||||||
#include "gfx/gfxDebugEvent.h"
|
#include "gfx/gfxDebugEvent.h"
|
||||||
|
#include "materials/materialFeatureTypes.h"
|
||||||
|
|
||||||
|
|
||||||
IMPLEMENT_CONOBJECT(RenderOcclusionMgr);
|
IMPLEMENT_CONOBJECT(RenderOcclusionMgr);
|
||||||
|
|
@ -48,14 +52,14 @@ bool RenderOcclusionMgr::smDebugRender = false;
|
||||||
RenderOcclusionMgr::RenderOcclusionMgr()
|
RenderOcclusionMgr::RenderOcclusionMgr()
|
||||||
: RenderBinManager(RenderPassManager::RIT_Occluder, 1.0f, 1.0f)
|
: RenderBinManager(RenderPassManager::RIT_Occluder, 1.0f, 1.0f)
|
||||||
{
|
{
|
||||||
mOverrideMat = NULL;
|
|
||||||
mSpherePrimCount = 0;
|
mSpherePrimCount = 0;
|
||||||
|
mMatInstance = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderOcclusionMgr::RenderOcclusionMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder)
|
RenderOcclusionMgr::RenderOcclusionMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder)
|
||||||
: RenderBinManager(riType, renderOrder, processAddOrder)
|
: RenderBinManager(riType, renderOrder, processAddOrder)
|
||||||
{
|
{
|
||||||
mOverrideMat = NULL;
|
delete mMatInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Point3F cubePoints[8] =
|
static const Point3F cubePoints[8] =
|
||||||
|
|
@ -72,25 +76,33 @@ static const U32 cubeFaces[6][4] =
|
||||||
|
|
||||||
void RenderOcclusionMgr::init()
|
void RenderOcclusionMgr::init()
|
||||||
{
|
{
|
||||||
GFXStateBlockDesc d;
|
delete mMatInstance;
|
||||||
|
|
||||||
|
mMaterial = MATMGR->allocateAndRegister( String::EmptyString );
|
||||||
|
mMaterial->mDiffuse[0] = ColorF( 1, 0, 1, 1 );
|
||||||
|
mMaterial->mEmissive[0] = true;
|
||||||
|
mMaterial->mAutoGenerated = true;
|
||||||
|
|
||||||
|
mMatInstance = mMaterial->createMatInstance();
|
||||||
|
FeatureSet features = MATMGR->getDefaultFeatures();
|
||||||
|
features.removeFeature( MFT_Visibility );
|
||||||
|
features.removeFeature( MFT_Fog );
|
||||||
|
features.removeFeature( MFT_HDROut );
|
||||||
|
mMatInstance->init( features, getGFXVertexFormat<GFXVertexP>() );
|
||||||
|
|
||||||
|
GFXStateBlockDesc d;
|
||||||
d.setBlend( false );
|
d.setBlend( false );
|
||||||
d.cullDefined = true;
|
d.cullDefined = true;
|
||||||
d.cullMode = GFXCullCCW;
|
d.cullMode = GFXCullCCW;
|
||||||
d.setZReadWrite( true, false );
|
d.setZReadWrite( true, false );
|
||||||
|
|
||||||
mDebugSB = GFX->createStateBlock(d);
|
|
||||||
|
|
||||||
d.setColorWrites( false, false, false, false );
|
d.setColorWrites( false, false, false, false );
|
||||||
|
mRenderSB = GFX->createStateBlock(d);
|
||||||
mNormalSB = GFX->createStateBlock(d);
|
|
||||||
|
|
||||||
d.setZReadWrite( false, false );
|
d.setZReadWrite( false, false );
|
||||||
|
|
||||||
mTestSB = GFX->createStateBlock(d);
|
mTestSB = GFX->createStateBlock(d);
|
||||||
|
|
||||||
mBoxBuff.set( GFX, 36, GFXBufferTypeStatic );
|
mBoxBuff.set( GFX, 36, GFXBufferTypeStatic );
|
||||||
GFXVertexPC *verts = mBoxBuff.lock();
|
GFXVertexP *verts = mBoxBuff.lock();
|
||||||
|
|
||||||
U32 vertexIndex = 0;
|
U32 vertexIndex = 0;
|
||||||
U32 idx;
|
U32 idx;
|
||||||
|
|
@ -98,32 +110,26 @@ void RenderOcclusionMgr::init()
|
||||||
{
|
{
|
||||||
idx = cubeFaces[i][0];
|
idx = cubeFaces[i][0];
|
||||||
verts[vertexIndex].point = cubePoints[idx];
|
verts[vertexIndex].point = cubePoints[idx];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
|
|
||||||
idx = cubeFaces[i][1];
|
idx = cubeFaces[i][1];
|
||||||
verts[vertexIndex].point = cubePoints[idx];
|
verts[vertexIndex].point = cubePoints[idx];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
|
|
||||||
idx = cubeFaces[i][3];
|
idx = cubeFaces[i][3];
|
||||||
verts[vertexIndex].point = cubePoints[idx];
|
verts[vertexIndex].point = cubePoints[idx];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
|
|
||||||
idx = cubeFaces[i][1];
|
idx = cubeFaces[i][1];
|
||||||
verts[vertexIndex].point = cubePoints[idx];
|
verts[vertexIndex].point = cubePoints[idx];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
|
|
||||||
idx = cubeFaces[i][3];
|
idx = cubeFaces[i][3];
|
||||||
verts[vertexIndex].point = cubePoints[idx];
|
verts[vertexIndex].point = cubePoints[idx];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
|
|
||||||
idx = cubeFaces[i][2];
|
idx = cubeFaces[i][2];
|
||||||
verts[vertexIndex].point = cubePoints[idx];
|
verts[vertexIndex].point = cubePoints[idx];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,15 +145,12 @@ void RenderOcclusionMgr::init()
|
||||||
for ( S32 i = 0; i < mSpherePrimCount; i++ )
|
for ( S32 i = 0; i < mSpherePrimCount; i++ )
|
||||||
{
|
{
|
||||||
verts[vertexIndex].point = sphereMesh->poly[i].pnt[0];
|
verts[vertexIndex].point = sphereMesh->poly[i].pnt[0];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
|
|
||||||
verts[vertexIndex].point = sphereMesh->poly[i].pnt[1];
|
verts[vertexIndex].point = sphereMesh->poly[i].pnt[1];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
|
|
||||||
verts[vertexIndex].point = sphereMesh->poly[i].pnt[2];
|
verts[vertexIndex].point = sphereMesh->poly[i].pnt[2];
|
||||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
}
|
}
|
||||||
mSphereBuff.unlock();
|
mSphereBuff.unlock();
|
||||||
|
|
@ -177,62 +180,52 @@ void RenderOcclusionMgr::render( SceneRenderState *state )
|
||||||
if ( !mElementList.size() )
|
if ( !mElementList.size() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
GFXTransformSaver saver;
|
||||||
|
|
||||||
GFXDEBUGEVENT_SCOPE(RenderOcclusionMgr_Render, ColorI::BLUE);
|
GFXDEBUGEVENT_SCOPE(RenderOcclusionMgr_Render, ColorI::BLUE);
|
||||||
|
|
||||||
if ( mNormalSB.isNull() )
|
if ( mMatInstance == NULL )
|
||||||
init();
|
init();
|
||||||
|
|
||||||
GFX->disableShaders();
|
SceneData sgData;
|
||||||
GFX->setupGenericShaders( GFXDevice::GSColor );
|
sgData.init( state );
|
||||||
|
|
||||||
|
// Restore transforms
|
||||||
|
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
|
||||||
|
matrixSet.restoreSceneViewProjection();
|
||||||
|
|
||||||
OccluderRenderInst *firstEl = static_cast<OccluderRenderInst*>(mElementList[0].inst);
|
// The material is single pass... just setup once here.
|
||||||
|
mMatInstance->setupPass( state, sgData );
|
||||||
if ( firstEl->isSphere )
|
|
||||||
GFX->setVertexBuffer( mSphereBuff );
|
|
||||||
else
|
|
||||||
GFX->setVertexBuffer( mBoxBuff );
|
|
||||||
|
|
||||||
bool wasSphere = firstEl->isSphere;
|
|
||||||
|
|
||||||
|
|
||||||
|
U32 primCount;
|
||||||
for( U32 i=0; i<mElementList.size(); i++ )
|
for( U32 i=0; i<mElementList.size(); i++ )
|
||||||
{
|
{
|
||||||
OccluderRenderInst *ri = static_cast<OccluderRenderInst*>(mElementList[i].inst);
|
OccluderRenderInst *ri = static_cast<OccluderRenderInst*>(mElementList[i].inst);
|
||||||
|
|
||||||
AssertFatal( ri->query != NULL, "RenderOcclusionMgr::render, OcclusionRenderInst has NULL GFXOcclusionQuery" );
|
AssertFatal( ri->query != NULL, "RenderOcclusionMgr::render, OcclusionRenderInst has NULL GFXOcclusionQuery" );
|
||||||
|
|
||||||
if ( ri->isSphere != wasSphere )
|
if ( ri->isSphere )
|
||||||
{
|
{
|
||||||
if ( ri->isSphere )
|
GFX->setVertexBuffer( mSphereBuff );
|
||||||
GFX->setVertexBuffer( mSphereBuff );
|
primCount = mSpherePrimCount;
|
||||||
else
|
}
|
||||||
GFX->setVertexBuffer( mBoxBuff );
|
else
|
||||||
|
{
|
||||||
wasSphere = ri->isSphere;
|
GFX->setVertexBuffer( mBoxBuff );
|
||||||
}
|
primCount = 12;
|
||||||
|
}
|
||||||
GFX->pushWorldMatrix();
|
|
||||||
|
|
||||||
MatrixF xfm( *ri->orientation );
|
MatrixF xfm( *ri->orientation );
|
||||||
xfm.setPosition( ri->position );
|
xfm.setPosition( ri->position );
|
||||||
xfm.scale( ri->scale );
|
xfm.scale( ri->scale );
|
||||||
|
|
||||||
//GFXTransformSaver saver;
|
matrixSet.setWorld(xfm);
|
||||||
GFX->multWorld( xfm );
|
mMatInstance->setTransforms(matrixSet, state);
|
||||||
|
|
||||||
if ( smDebugRender )
|
if ( !smDebugRender )
|
||||||
GFX->setStateBlock( mDebugSB );
|
GFX->setStateBlock( mRenderSB );
|
||||||
else
|
|
||||||
GFX->setStateBlock( mNormalSB );
|
|
||||||
|
|
||||||
ri->query->begin();
|
ri->query->begin();
|
||||||
|
GFX->drawPrimitive( GFXTriangleList, 0, primCount );
|
||||||
if ( wasSphere )
|
|
||||||
GFX->drawPrimitive( GFXTriangleList, 0, mSpherePrimCount );
|
|
||||||
else
|
|
||||||
GFX->drawPrimitive( GFXTriangleList, 0, 12 );
|
|
||||||
|
|
||||||
ri->query->end();
|
ri->query->end();
|
||||||
|
|
||||||
if ( ri->query2 )
|
if ( ri->query2 )
|
||||||
|
|
@ -240,15 +233,11 @@ void RenderOcclusionMgr::render( SceneRenderState *state )
|
||||||
GFX->setStateBlock( mTestSB );
|
GFX->setStateBlock( mTestSB );
|
||||||
|
|
||||||
ri->query2->begin();
|
ri->query2->begin();
|
||||||
|
GFX->drawPrimitive( GFXTriangleList, 0, primCount );
|
||||||
if ( wasSphere )
|
|
||||||
GFX->drawPrimitive( GFXTriangleList, 0, mSpherePrimCount );
|
|
||||||
else
|
|
||||||
GFX->drawPrimitive( GFXTriangleList, 0, 12 );
|
|
||||||
|
|
||||||
ri->query2->end();
|
ri->query2->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
GFX->popWorldMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call setup one more time to end the pass.
|
||||||
|
mMatInstance->setupPass( state, sgData );
|
||||||
}
|
}
|
||||||
|
|
@ -26,6 +26,10 @@
|
||||||
#include "renderInstance/renderBinManager.h"
|
#include "renderInstance/renderBinManager.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class Material;
|
||||||
|
class BaseMatInstance;
|
||||||
|
|
||||||
|
|
||||||
//**************************************************************************
|
//**************************************************************************
|
||||||
// RenderOcclusionMgr
|
// RenderOcclusionMgr
|
||||||
//**************************************************************************
|
//**************************************************************************
|
||||||
|
|
@ -46,15 +50,17 @@ public:
|
||||||
DECLARE_CONOBJECT(RenderOcclusionMgr);
|
DECLARE_CONOBJECT(RenderOcclusionMgr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BaseMatInstance* mOverrideMat;
|
GFXStateBlockRef mRenderSB;
|
||||||
GFXStateBlockRef mNormalSB;
|
|
||||||
GFXStateBlockRef mTestSB;
|
GFXStateBlockRef mTestSB;
|
||||||
|
|
||||||
GFXStateBlockRef mDebugSB;
|
/// The material for rendering occluders.
|
||||||
|
SimObjectPtr<Material> mMaterial;
|
||||||
|
BaseMatInstance *mMatInstance;
|
||||||
|
|
||||||
static bool smDebugRender;
|
static bool smDebugRender;
|
||||||
|
|
||||||
GFXVertexBufferHandle<GFXVertexPC> mBoxBuff;
|
GFXVertexBufferHandle<GFXVertexP> mBoxBuff;
|
||||||
GFXVertexBufferHandle<GFXVertexPC> mSphereBuff;
|
GFXVertexBufferHandle<GFXVertexP> mSphereBuff;
|
||||||
U32 mSpherePrimCount;
|
U32 mSpherePrimCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue