mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 11:43:49 +00:00
Fix for Issue #132 for RenderOcclusionMgr Rendering
This commit is contained in:
parent
74cbcb3e85
commit
6637948067
2 changed files with 66 additions and 71 deletions
|
|
@ -29,7 +29,11 @@
|
|||
#include "gfx/gfxDrawUtil.h"
|
||||
#include "gfx/gfxTransformSaver.h"
|
||||
#include "math/util/sphereMesh.h"
|
||||
#include "materials/materialManager.h"
|
||||
#include "materials/sceneData.h"
|
||||
#include "math/util/matrixSet.h"
|
||||
#include "gfx/gfxDebugEvent.h"
|
||||
#include "materials/materialFeatureTypes.h"
|
||||
|
||||
|
||||
IMPLEMENT_CONOBJECT(RenderOcclusionMgr);
|
||||
|
|
@ -48,14 +52,14 @@ bool RenderOcclusionMgr::smDebugRender = false;
|
|||
RenderOcclusionMgr::RenderOcclusionMgr()
|
||||
: RenderBinManager(RenderPassManager::RIT_Occluder, 1.0f, 1.0f)
|
||||
{
|
||||
mOverrideMat = NULL;
|
||||
mSpherePrimCount = 0;
|
||||
mMatInstance = NULL;
|
||||
}
|
||||
|
||||
RenderOcclusionMgr::RenderOcclusionMgr(RenderInstType riType, F32 renderOrder, F32 processAddOrder)
|
||||
: RenderBinManager(riType, renderOrder, processAddOrder)
|
||||
{
|
||||
mOverrideMat = NULL;
|
||||
delete mMatInstance;
|
||||
}
|
||||
|
||||
static const Point3F cubePoints[8] =
|
||||
|
|
@ -72,25 +76,33 @@ static const U32 cubeFaces[6][4] =
|
|||
|
||||
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.cullDefined = true;
|
||||
d.cullMode = GFXCullCCW;
|
||||
d.setZReadWrite( true, false );
|
||||
|
||||
mDebugSB = GFX->createStateBlock(d);
|
||||
|
||||
d.setColorWrites( false, false, false, false );
|
||||
|
||||
mNormalSB = GFX->createStateBlock(d);
|
||||
mRenderSB = GFX->createStateBlock(d);
|
||||
|
||||
d.setZReadWrite( false, false );
|
||||
|
||||
mTestSB = GFX->createStateBlock(d);
|
||||
|
||||
mBoxBuff.set( GFX, 36, GFXBufferTypeStatic );
|
||||
GFXVertexPC *verts = mBoxBuff.lock();
|
||||
GFXVertexP *verts = mBoxBuff.lock();
|
||||
|
||||
U32 vertexIndex = 0;
|
||||
U32 idx;
|
||||
|
|
@ -98,32 +110,26 @@ void RenderOcclusionMgr::init()
|
|||
{
|
||||
idx = cubeFaces[i][0];
|
||||
verts[vertexIndex].point = cubePoints[idx];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
|
||||
idx = cubeFaces[i][1];
|
||||
verts[vertexIndex].point = cubePoints[idx];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
|
||||
idx = cubeFaces[i][3];
|
||||
verts[vertexIndex].point = cubePoints[idx];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
|
||||
idx = cubeFaces[i][1];
|
||||
verts[vertexIndex].point = cubePoints[idx];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
|
||||
idx = cubeFaces[i][3];
|
||||
verts[vertexIndex].point = cubePoints[idx];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
|
||||
idx = cubeFaces[i][2];
|
||||
verts[vertexIndex].point = cubePoints[idx];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
}
|
||||
|
||||
|
|
@ -139,15 +145,12 @@ void RenderOcclusionMgr::init()
|
|||
for ( S32 i = 0; i < mSpherePrimCount; i++ )
|
||||
{
|
||||
verts[vertexIndex].point = sphereMesh->poly[i].pnt[0];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
|
||||
verts[vertexIndex].point = sphereMesh->poly[i].pnt[1];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
|
||||
verts[vertexIndex].point = sphereMesh->poly[i].pnt[2];
|
||||
verts[vertexIndex].color.set( 1,0,1,1 );
|
||||
vertexIndex++;
|
||||
}
|
||||
mSphereBuff.unlock();
|
||||
|
|
@ -177,62 +180,52 @@ void RenderOcclusionMgr::render( SceneRenderState *state )
|
|||
if ( !mElementList.size() )
|
||||
return;
|
||||
|
||||
GFXTransformSaver saver;
|
||||
|
||||
GFXDEBUGEVENT_SCOPE(RenderOcclusionMgr_Render, ColorI::BLUE);
|
||||
|
||||
if ( mNormalSB.isNull() )
|
||||
if ( mMatInstance == NULL )
|
||||
init();
|
||||
|
||||
GFX->disableShaders();
|
||||
GFX->setupGenericShaders( GFXDevice::GSColor );
|
||||
SceneData sgData;
|
||||
sgData.init( state );
|
||||
|
||||
// Restore transforms
|
||||
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
|
||||
matrixSet.restoreSceneViewProjection();
|
||||
|
||||
OccluderRenderInst *firstEl = static_cast<OccluderRenderInst*>(mElementList[0].inst);
|
||||
|
||||
if ( firstEl->isSphere )
|
||||
GFX->setVertexBuffer( mSphereBuff );
|
||||
else
|
||||
GFX->setVertexBuffer( mBoxBuff );
|
||||
|
||||
bool wasSphere = firstEl->isSphere;
|
||||
|
||||
// The material is single pass... just setup once here.
|
||||
mMatInstance->setupPass( state, sgData );
|
||||
|
||||
U32 primCount;
|
||||
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" );
|
||||
|
||||
if ( ri->isSphere != wasSphere )
|
||||
{
|
||||
if ( ri->isSphere )
|
||||
GFX->setVertexBuffer( mSphereBuff );
|
||||
else
|
||||
GFX->setVertexBuffer( mBoxBuff );
|
||||
if ( ri->isSphere )
|
||||
{
|
||||
GFX->setVertexBuffer( mSphereBuff );
|
||||
primCount = mSpherePrimCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
GFX->setVertexBuffer( mBoxBuff );
|
||||
primCount = 12;
|
||||
}
|
||||
|
||||
wasSphere = ri->isSphere;
|
||||
}
|
||||
|
||||
GFX->pushWorldMatrix();
|
||||
|
||||
MatrixF xfm( *ri->orientation );
|
||||
xfm.setPosition( ri->position );
|
||||
xfm.scale( ri->scale );
|
||||
|
||||
//GFXTransformSaver saver;
|
||||
GFX->multWorld( xfm );
|
||||
matrixSet.setWorld(xfm);
|
||||
mMatInstance->setTransforms(matrixSet, state);
|
||||
|
||||
if ( smDebugRender )
|
||||
GFX->setStateBlock( mDebugSB );
|
||||
else
|
||||
GFX->setStateBlock( mNormalSB );
|
||||
|
||||
ri->query->begin();
|
||||
|
||||
if ( wasSphere )
|
||||
GFX->drawPrimitive( GFXTriangleList, 0, mSpherePrimCount );
|
||||
else
|
||||
GFX->drawPrimitive( GFXTriangleList, 0, 12 );
|
||||
if ( !smDebugRender )
|
||||
GFX->setStateBlock( mRenderSB );
|
||||
|
||||
ri->query->begin();
|
||||
GFX->drawPrimitive( GFXTriangleList, 0, primCount );
|
||||
ri->query->end();
|
||||
|
||||
if ( ri->query2 )
|
||||
|
|
@ -240,15 +233,11 @@ void RenderOcclusionMgr::render( SceneRenderState *state )
|
|||
GFX->setStateBlock( mTestSB );
|
||||
|
||||
ri->query2->begin();
|
||||
|
||||
if ( wasSphere )
|
||||
GFX->drawPrimitive( GFXTriangleList, 0, mSpherePrimCount );
|
||||
else
|
||||
GFX->drawPrimitive( GFXTriangleList, 0, 12 );
|
||||
|
||||
GFX->drawPrimitive( GFXTriangleList, 0, primCount );
|
||||
ri->query2->end();
|
||||
}
|
||||
}
|
||||
|
||||
GFX->popWorldMatrix();
|
||||
}
|
||||
// Call setup one more time to end the pass.
|
||||
mMatInstance->setupPass( state, sgData );
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue