mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 19:53:48 +00:00
commit
908be4818f
112 changed files with 2645 additions and 680 deletions
|
|
@ -36,7 +36,8 @@ RenderBinManager::RenderBinManager( const RenderInstType& ritype, F32 renderOrde
|
|||
mRenderInstType( ritype ),
|
||||
mRenderOrder( renderOrder ),
|
||||
mProcessAddOrder( processAddOrder ),
|
||||
mRenderPass( NULL )
|
||||
mRenderPass( NULL ),
|
||||
mBasicOnly ( false )
|
||||
{
|
||||
VECTOR_SET_ASSOCIATION( mElementList );
|
||||
mElementList.reserve( 2048 );
|
||||
|
|
@ -60,6 +61,9 @@ void RenderBinManager::initPersistFields()
|
|||
addField("processAddOrder", TypeF32, Offset(mProcessAddOrder, RenderBinManager),
|
||||
"Defines the order for adding instances in relation to other bins." );
|
||||
|
||||
addField( "basicOnly", TypeBool, Offset(mBasicOnly, RenderBinManager),
|
||||
"Limites the render bin to basic lighting only." );
|
||||
|
||||
Parent::initPersistFields();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,8 @@ protected:
|
|||
/// RenderInst if available, otherwise, return NULL.
|
||||
inline BaseMatInstance* getMaterial( RenderInst *inst ) const;
|
||||
|
||||
// Limits bin to rendering in basic lighting only.
|
||||
bool mBasicOnly;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -160,6 +162,7 @@ inline BaseMatInstance* RenderBinManager::getMaterial( RenderInst *inst ) const
|
|||
{
|
||||
if ( inst->type == RenderPassManager::RIT_Mesh ||
|
||||
inst->type == RenderPassManager::RIT_Decal ||
|
||||
inst->type == RenderPassManager::RIT_DecalRoad ||
|
||||
inst->type == RenderPassManager::RIT_Translucent )
|
||||
return static_cast<MeshRenderInst*>(inst)->matInst;
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ void RenderGlowMgr::GlowMaterialHook::_overrideFeatures( ProcessedMaterial *mat,
|
|||
// the glow materials.
|
||||
fd.features.removeFeature( MFT_Fog );
|
||||
fd.features.removeFeature( MFT_HDROut );
|
||||
fd.features.addFeature( MFT_Imposter );
|
||||
}
|
||||
|
||||
RenderGlowMgr::RenderGlowMgr()
|
||||
|
|
@ -89,6 +90,7 @@ RenderGlowMgr::RenderGlowMgr()
|
|||
Point2I( 512, 512 ) )
|
||||
{
|
||||
notifyType( RenderPassManager::RIT_Decal );
|
||||
notifyType( RenderPassManager::RIT_DecalRoad );
|
||||
notifyType( RenderPassManager::RIT_Translucent );
|
||||
notifyType( RenderPassManager::RIT_Particle );
|
||||
|
||||
|
|
|
|||
|
|
@ -144,6 +144,14 @@ void RenderMeshMgr::render(SceneRenderState * state)
|
|||
if( !mat )
|
||||
mat = MATMGR->getWarningMatInstance();
|
||||
|
||||
// Check if bin is disabled in advanced lighting.
|
||||
// Allow forward rendering pass on custom materials.
|
||||
|
||||
if ( ( MATMGR->getPrePassEnabled() && mBasicOnly && !mat->isCustomMaterial() ) )
|
||||
{
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
|
||||
U32 matListEnd = j;
|
||||
lastMiscTex = sgData.miscTex;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
#include "renderObjectMgr.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#include "scene/sceneObject.h"
|
||||
#include "materials/materialManager.h"
|
||||
#include "scene/sceneRenderState.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(RenderObjectMgr);
|
||||
|
||||
|
|
@ -66,6 +68,10 @@ void RenderObjectMgr::render( SceneRenderState *state )
|
|||
if(!mElementList.size())
|
||||
return;
|
||||
|
||||
// Check if bin is disabled in advanced lighting.
|
||||
if ( MATMGR->getPrePassEnabled() && mBasicOnly )
|
||||
return;
|
||||
|
||||
for( U32 i=0; i<mElementList.size(); i++ )
|
||||
{
|
||||
ObjectRenderInst *ri = static_cast<ObjectRenderInst*>(mElementList[i].inst);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ const RenderInstType RenderPassManager::RIT_Terrain("Terrain");
|
|||
const RenderInstType RenderPassManager::RIT_Object("Object");
|
||||
const RenderInstType RenderPassManager::RIT_ObjectTranslucent("ObjectTranslucent");
|
||||
const RenderInstType RenderPassManager::RIT_Decal("Decal");
|
||||
const RenderInstType RenderPassManager::RIT_DecalRoad("DecalRoad");
|
||||
const RenderInstType RenderPassManager::RIT_Water("Water");
|
||||
const RenderInstType RenderPassManager::RIT_Foliage("Foliage");
|
||||
const RenderInstType RenderPassManager::RIT_VolumetricFog("ObjectVolumetricFog");
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ public:
|
|||
static const RenderInstType RIT_Object; // objects that do their own rendering
|
||||
static const RenderInstType RIT_ObjectTranslucent;// self rendering; but sorted with static const RenderInstType RIT_Translucent
|
||||
static const RenderInstType RIT_Decal;
|
||||
static const RenderInstType RIT_DecalRoad;
|
||||
static const RenderInstType RIT_Water;
|
||||
static const RenderInstType RIT_Foliage;
|
||||
static const RenderInstType RIT_VolumetricFog;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "scene/sceneRenderState.h"
|
||||
#include "gfx/gfxStringEnumTranslate.h"
|
||||
#include "gfx/gfxDebugEvent.h"
|
||||
#include "gfx/gfxCardProfile.h"
|
||||
#include "materials/customMaterialDefinition.h"
|
||||
#include "lighting/advanced/advancedLightManager.h"
|
||||
#include "lighting/advanced/advancedLightBinManager.h"
|
||||
|
|
@ -44,10 +45,17 @@
|
|||
#include "terrain/terrCellMaterial.h"
|
||||
#include "math/mathUtils.h"
|
||||
#include "math/util/matrixSet.h"
|
||||
#include "gfx/gfxTextureManager.h"
|
||||
#include "gfx/primBuilder.h"
|
||||
#include "gfx/gfxDrawUtil.h"
|
||||
#include "materials/shaderData.h"
|
||||
#include "gfx/sim/cubemapData.h"
|
||||
|
||||
const MatInstanceHookType PrePassMatInstanceHook::Type( "PrePass" );
|
||||
const String RenderPrePassMgr::BufferName("prepass");
|
||||
const RenderInstType RenderPrePassMgr::RIT_PrePass("PrePass");
|
||||
const String RenderPrePassMgr::ColorBufferName("color");
|
||||
const String RenderPrePassMgr::MatInfoBufferName("matinfo");
|
||||
|
||||
IMPLEMENT_CONOBJECT(RenderPrePassMgr);
|
||||
|
||||
|
|
@ -79,6 +87,7 @@ RenderPrePassMgr::RenderPrePassMgr( bool gatherDepth,
|
|||
mPrePassMatInstance( NULL )
|
||||
{
|
||||
notifyType( RenderPassManager::RIT_Decal );
|
||||
notifyType( RenderPassManager::RIT_DecalRoad );
|
||||
notifyType( RenderPassManager::RIT_Mesh );
|
||||
notifyType( RenderPassManager::RIT_Terrain );
|
||||
notifyType( RenderPassManager::RIT_Object );
|
||||
|
|
@ -90,6 +99,10 @@ RenderPrePassMgr::RenderPrePassMgr( bool gatherDepth,
|
|||
GFXShader::addGlobalMacro( "TORQUE_LINEAR_DEPTH" );
|
||||
|
||||
mNamedTarget.registerWithName( BufferName );
|
||||
mColorTarget.registerWithName( ColorBufferName );
|
||||
mMatInfoTarget.registerWithName( MatInfoBufferName );
|
||||
|
||||
mClearGBufferShader = NULL;
|
||||
|
||||
_registerFeatures();
|
||||
}
|
||||
|
|
@ -98,6 +111,8 @@ RenderPrePassMgr::~RenderPrePassMgr()
|
|||
{
|
||||
GFXShader::removeGlobalMacro( "TORQUE_LINEAR_DEPTH" );
|
||||
|
||||
mColorTarget.release();
|
||||
mMatInfoTarget.release();
|
||||
_unregisterFeatures();
|
||||
SAFE_DELETE( mPrePassMatInstance );
|
||||
}
|
||||
|
|
@ -119,6 +134,8 @@ bool RenderPrePassMgr::setTargetSize(const Point2I &newTargetSize)
|
|||
{
|
||||
bool ret = Parent::setTargetSize( newTargetSize );
|
||||
mNamedTarget.setViewport( GFX->getViewport() );
|
||||
mColorTarget.setViewport( GFX->getViewport() );
|
||||
mMatInfoTarget.setViewport( GFX->getViewport() );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -135,6 +152,40 @@ bool RenderPrePassMgr::_updateTargets()
|
|||
// reload materials, the conditioner needs to alter the generated shaders
|
||||
}
|
||||
|
||||
GFXFormat colorFormat = mTargetFormat;
|
||||
bool independentMrtBitDepth = GFX->getCardProfiler()->queryProfile("independentMrtBitDepth", false);
|
||||
//If independent bit depth on a MRT is supported than just use 8bit channels for the albedo color.
|
||||
if(independentMrtBitDepth)
|
||||
colorFormat = GFXFormatR8G8B8A8;
|
||||
|
||||
// andrewmac: Deferred Shading Color Buffer
|
||||
if (mColorTex.getFormat() != colorFormat || mColorTex.getWidthHeight() != mTargetSize || GFX->recentlyReset())
|
||||
{
|
||||
mColorTarget.release();
|
||||
mColorTex.set(mTargetSize.x, mTargetSize.y, colorFormat,
|
||||
&GFXDefaultRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__),
|
||||
1, GFXTextureManager::AA_MATCH_BACKBUFFER);
|
||||
mColorTarget.setTexture(mColorTex);
|
||||
|
||||
for (U32 i = 0; i < mTargetChainLength; i++)
|
||||
mTargetChain[i]->attachTexture(GFXTextureTarget::Color1, mColorTarget.getTexture());
|
||||
}
|
||||
|
||||
// andrewmac: Deferred Shading Material Info Buffer
|
||||
if (mMatInfoTex.getFormat() != colorFormat || mMatInfoTex.getWidthHeight() != mTargetSize || GFX->recentlyReset())
|
||||
{
|
||||
mMatInfoTarget.release();
|
||||
mMatInfoTex.set(mTargetSize.x, mTargetSize.y, colorFormat,
|
||||
&GFXDefaultRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__),
|
||||
1, GFXTextureManager::AA_MATCH_BACKBUFFER);
|
||||
mMatInfoTarget.setTexture(mMatInfoTex);
|
||||
|
||||
for (U32 i = 0; i < mTargetChainLength; i++)
|
||||
mTargetChain[i]->attachTexture(GFXTextureTarget::Color2, mMatInfoTarget.getTexture());
|
||||
}
|
||||
|
||||
GFX->finalizeReset();
|
||||
|
||||
// Attach the light info buffer as a second render target, if there is
|
||||
// lightmapped geometry in the scene.
|
||||
AdvancedLightBinManager *lightBin;
|
||||
|
|
@ -154,11 +205,13 @@ bool RenderPrePassMgr::_updateTargets()
|
|||
for ( U32 i = 0; i < mTargetChainLength; i++ )
|
||||
{
|
||||
GFXTexHandle lightInfoTex = lightBin->getTargetTexture(0, i);
|
||||
mTargetChain[i]->attachTexture(GFXTextureTarget::Color1, lightInfoTex);
|
||||
mTargetChain[i]->attachTexture(GFXTextureTarget::Color3, lightInfoTex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_initShaders();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +244,7 @@ void RenderPrePassMgr::addElement( RenderInst *inst )
|
|||
return;
|
||||
|
||||
// First what type of render instance is it?
|
||||
const bool isDecalMeshInst = inst->type == RenderPassManager::RIT_Decal;
|
||||
const bool isDecalMeshInst = ((inst->type == RenderPassManager::RIT_Decal)||(inst->type == RenderPassManager::RIT_DecalRoad));
|
||||
|
||||
const bool isMeshInst = inst->type == RenderPassManager::RIT_Mesh;
|
||||
|
||||
|
|
@ -280,9 +333,8 @@ void RenderPrePassMgr::render( SceneRenderState *state )
|
|||
// Tell the superclass we're about to render
|
||||
const bool isRenderingToTarget = _onPreRender(state);
|
||||
|
||||
// Clear all the buffers to white so that the
|
||||
// default depth is to the far plane.
|
||||
GFX->clear( GFXClearTarget | GFXClearZBuffer | GFXClearStencil, ColorI::WHITE, 1.0f, 0);
|
||||
// Clear all z-buffer, and g-buffer.
|
||||
clearBuffers();
|
||||
|
||||
// Restore transforms
|
||||
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
|
||||
|
|
@ -329,7 +381,13 @@ void RenderPrePassMgr::render( SceneRenderState *state )
|
|||
GFX->drawPrimitive( ri->prim );
|
||||
}
|
||||
|
||||
|
||||
// init loop data
|
||||
GFXTextureObject *lastLM = NULL;
|
||||
GFXCubemap *lastCubemap = NULL;
|
||||
GFXTextureObject *lastReflectTex = NULL;
|
||||
GFXTextureObject *lastMiscTex = NULL;
|
||||
GFXTextureObject *lastAccuTex = NULL;
|
||||
|
||||
// Next render all the meshes.
|
||||
itr = mElementList.begin();
|
||||
for ( ; itr != mElementList.end(); )
|
||||
|
|
@ -363,12 +421,11 @@ void RenderPrePassMgr::render( SceneRenderState *state )
|
|||
|
||||
// Set up SG data for this instance.
|
||||
setupSGData( passRI, sgData );
|
||||
mat->setSceneInfo(state, sgData);
|
||||
|
||||
matrixSet.setWorld(*passRI->objectToWorld);
|
||||
matrixSet.setView(*passRI->worldToCamera);
|
||||
matrixSet.setProjection(*passRI->projection);
|
||||
|
||||
mat->setSceneInfo(state, sgData);
|
||||
mat->setTransforms(matrixSet, state);
|
||||
|
||||
// If we're instanced then don't render yet.
|
||||
|
|
@ -385,6 +442,43 @@ void RenderPrePassMgr::render( SceneRenderState *state )
|
|||
continue;
|
||||
}
|
||||
|
||||
bool dirty = false;
|
||||
|
||||
// set the lightmaps if different
|
||||
if( passRI->lightmap && passRI->lightmap != lastLM )
|
||||
{
|
||||
sgData.lightmap = passRI->lightmap;
|
||||
lastLM = passRI->lightmap;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
// set the cubemap if different.
|
||||
if ( passRI->cubemap != lastCubemap )
|
||||
{
|
||||
sgData.cubemap = passRI->cubemap;
|
||||
lastCubemap = passRI->cubemap;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if ( passRI->reflectTex != lastReflectTex )
|
||||
{
|
||||
sgData.reflectTex = passRI->reflectTex;
|
||||
lastReflectTex = passRI->reflectTex;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
// Update accumulation texture if it changed.
|
||||
// Note: accumulation texture can be NULL, and must be updated.
|
||||
if (passRI->accuTex != lastAccuTex)
|
||||
{
|
||||
sgData.accuTex = passRI->accuTex;
|
||||
lastAccuTex = lastAccuTex;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if ( dirty )
|
||||
mat->setTextureStages( state, sgData );
|
||||
|
||||
// Setup the vertex and index buffers.
|
||||
mat->setBuffers( passRI->vertBuff, passRI->primBuff );
|
||||
|
||||
|
|
@ -525,6 +619,31 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum,
|
|||
|
||||
#ifndef TORQUE_DEDICATED
|
||||
|
||||
//tag all materials running through prepass as deferred
|
||||
newFeatures.addFeature(MFT_isDeferred);
|
||||
|
||||
// Deferred Shading : Diffuse
|
||||
if (mStages[stageNum].getTex( MFT_DiffuseMap ))
|
||||
{
|
||||
newFeatures.addFeature(MFT_DiffuseMap);
|
||||
}
|
||||
newFeatures.addFeature( MFT_DiffuseColor );
|
||||
|
||||
// Deferred Shading : Specular
|
||||
if( mStages[stageNum].getTex( MFT_SpecularMap ) )
|
||||
{
|
||||
newFeatures.addFeature( MFT_DeferredSpecMap );
|
||||
}
|
||||
else if ( mMaterial->mPixelSpecular[stageNum] )
|
||||
{
|
||||
newFeatures.addFeature( MFT_DeferredSpecVars );
|
||||
}
|
||||
else
|
||||
newFeatures.addFeature(MFT_DeferredEmptySpec);
|
||||
|
||||
// Deferred Shading : Material Info Flags
|
||||
newFeatures.addFeature( MFT_DeferredMatInfoFlags );
|
||||
|
||||
for ( U32 i=0; i < fd.features.getCount(); i++ )
|
||||
{
|
||||
const FeatureType &type = fd.features.getAt( i );
|
||||
|
|
@ -553,7 +672,10 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum,
|
|||
type == MFT_InterlacedPrePass ||
|
||||
type == MFT_Visibility ||
|
||||
type == MFT_UseInstancing ||
|
||||
type == MFT_DiffuseVertColor )
|
||||
type == MFT_DiffuseVertColor ||
|
||||
type == MFT_DetailMap ||
|
||||
type == MFT_DetailNormalMap ||
|
||||
type == MFT_DiffuseMapAtlas)
|
||||
newFeatures.addFeature( type );
|
||||
|
||||
// Add any transform features.
|
||||
|
|
@ -563,11 +685,39 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum,
|
|||
newFeatures.addFeature( type );
|
||||
}
|
||||
|
||||
if (mMaterial->mAccuEnabled[stageNum])
|
||||
{
|
||||
newFeatures.addFeature(MFT_AccuMap);
|
||||
mHasAccumulation = true;
|
||||
}
|
||||
|
||||
// we need both diffuse and normal maps + sm3 to have an accu map
|
||||
if (newFeatures[MFT_AccuMap] &&
|
||||
(!newFeatures[MFT_DiffuseMap] ||
|
||||
!newFeatures[MFT_NormalMap] ||
|
||||
GFX->getPixelShaderVersion() < 3.0f)) {
|
||||
AssertWarn(false, "SAHARA: Using an Accu Map requires SM 3.0 and a normal map.");
|
||||
newFeatures.removeFeature(MFT_AccuMap);
|
||||
mHasAccumulation = false;
|
||||
}
|
||||
|
||||
// if we still have the AccuMap feature, we add all accu constant features
|
||||
if (newFeatures[MFT_AccuMap]) {
|
||||
// add the dependencies of the accu map
|
||||
newFeatures.addFeature(MFT_AccuScale);
|
||||
newFeatures.addFeature(MFT_AccuDirection);
|
||||
newFeatures.addFeature(MFT_AccuStrength);
|
||||
newFeatures.addFeature(MFT_AccuCoverage);
|
||||
newFeatures.addFeature(MFT_AccuSpecular);
|
||||
// now remove some features that are not compatible with this
|
||||
newFeatures.removeFeature(MFT_UseInstancing);
|
||||
}
|
||||
|
||||
// If there is lightmapped geometry support, add the MRT light buffer features
|
||||
if(bEnableMRTLightmap)
|
||||
{
|
||||
// If this material has a lightmap, pass it through, and flag it to
|
||||
// send it's output to RenderTarget1
|
||||
// send it's output to RenderTarget3
|
||||
if( fd.features.hasFeature( MFT_ToneMap ) )
|
||||
{
|
||||
newFeatures.addFeature( MFT_ToneMap );
|
||||
|
|
@ -590,10 +740,16 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum,
|
|||
else
|
||||
{
|
||||
// If this object isn't lightmapped, add a zero-output feature to it
|
||||
newFeatures.addFeature( MFT_RenderTarget1_Zero );
|
||||
newFeatures.addFeature( MFT_RenderTarget3_Zero );
|
||||
}
|
||||
}
|
||||
|
||||
// cubemaps only available on stage 0 for now - bramage
|
||||
if ( stageNum < 1 &&
|
||||
( ( mMaterial->mCubemapData && mMaterial->mCubemapData->mCubemap ) ||
|
||||
mMaterial->mDynamicCubemap ) )
|
||||
newFeatures.addFeature( MFT_CubeMap );
|
||||
|
||||
#endif
|
||||
|
||||
// Set the new features.
|
||||
|
|
@ -602,8 +758,54 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum,
|
|||
|
||||
U32 ProcessedPrePassMaterial::getNumStages()
|
||||
{
|
||||
// Return 1 stage so this material gets processed for sure
|
||||
return 1;
|
||||
// Loops through all stages to determine how many
|
||||
// stages we actually use.
|
||||
//
|
||||
// The first stage is always active else we shouldn't be
|
||||
// creating the material to begin with.
|
||||
U32 numStages = 1;
|
||||
|
||||
U32 i;
|
||||
for( i=1; i<Material::MAX_STAGES; i++ )
|
||||
{
|
||||
// Assume stage is inactive
|
||||
bool stageActive = false;
|
||||
|
||||
// Cubemaps only on first stage
|
||||
if( i == 0 )
|
||||
{
|
||||
// If we have a cubemap the stage is active
|
||||
if( mMaterial->mCubemapData || mMaterial->mDynamicCubemap )
|
||||
{
|
||||
numStages++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a texture for the a feature the
|
||||
// stage is active.
|
||||
if ( mStages[i].hasValidTex() )
|
||||
stageActive = true;
|
||||
|
||||
// If this stage has specular lighting, it's active
|
||||
if ( mMaterial->mPixelSpecular[i] )
|
||||
stageActive = true;
|
||||
|
||||
// If this stage has diffuse color, it's active
|
||||
if ( mMaterial->mDiffuse[i].alpha > 0 &&
|
||||
mMaterial->mDiffuse[i] != ColorF::WHITE )
|
||||
stageActive = true;
|
||||
|
||||
// If we have a Material that is vertex lit
|
||||
// then it may not have a texture
|
||||
if( mMaterial->mVertLit[i] )
|
||||
stageActive = true;
|
||||
|
||||
// Increment the number of active stages
|
||||
numStages += stageActive;
|
||||
}
|
||||
|
||||
return numStages;
|
||||
}
|
||||
|
||||
void ProcessedPrePassMaterial::addStateBlockDesc(const GFXStateBlockDesc& desc)
|
||||
|
|
@ -633,7 +835,7 @@ void ProcessedPrePassMaterial::addStateBlockDesc(const GFXStateBlockDesc& desc)
|
|||
if ( isTranslucent )
|
||||
{
|
||||
prePassStateBlock.setBlend( true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha );
|
||||
prePassStateBlock.setColorWrites( true, true, false, false );
|
||||
prePassStateBlock.setColorWrites(false, false, false, true);
|
||||
}
|
||||
|
||||
// Enable z reads, but only enable zwrites if we're not translucent.
|
||||
|
|
@ -663,7 +865,22 @@ ProcessedMaterial* PrePassMatInstance::getShaderMaterial()
|
|||
bool PrePassMatInstance::init( const FeatureSet &features,
|
||||
const GFXVertexFormat *vertexFormat )
|
||||
{
|
||||
return Parent::init( features, vertexFormat );
|
||||
bool vaild = Parent::init(features, vertexFormat);
|
||||
|
||||
if (mMaterial && mMaterial->mDiffuseMapFilename[0].isNotEmpty() && mMaterial->mDiffuseMapFilename[0].substr(0, 1).equal("#"))
|
||||
{
|
||||
String texTargetBufferName = mMaterial->mDiffuseMapFilename[0].substr(1, mMaterial->mDiffuseMapFilename[0].length() - 1);
|
||||
NamedTexTarget *texTarget = NamedTexTarget::find(texTargetBufferName);
|
||||
RenderPassData* rpd = getPass(0);
|
||||
|
||||
if (rpd)
|
||||
{
|
||||
rpd->mTexSlot[0].texTarget = texTarget;
|
||||
rpd->mTexType[0] = Material::TexTarget;
|
||||
rpd->mSamplerNames[0] = "diffuseMap";
|
||||
}
|
||||
}
|
||||
return vaild;
|
||||
}
|
||||
|
||||
PrePassMatInstanceHook::PrePassMatInstanceHook( MatInstance *baseMatInst,
|
||||
|
|
@ -850,3 +1067,77 @@ Var* LinearEyeDepthConditioner::printMethodHeader( MethodType methodType, const
|
|||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void RenderPrePassMgr::_initShaders()
|
||||
{
|
||||
if ( mClearGBufferShader ) return;
|
||||
|
||||
// Find ShaderData
|
||||
ShaderData *shaderData;
|
||||
mClearGBufferShader = Sim::findObject( "ClearGBufferShader", shaderData ) ? shaderData->getShader() : NULL;
|
||||
if ( !mClearGBufferShader )
|
||||
Con::errorf( "RenderPrePassMgr::_initShaders - could not find ClearGBufferShader" );
|
||||
|
||||
// Create StateBlocks
|
||||
GFXStateBlockDesc desc;
|
||||
desc.setCullMode( GFXCullNone );
|
||||
desc.setBlend( true );
|
||||
desc.setZReadWrite( false, false );
|
||||
desc.samplersDefined = true;
|
||||
desc.samplers[0].addressModeU = GFXAddressWrap;
|
||||
desc.samplers[0].addressModeV = GFXAddressWrap;
|
||||
desc.samplers[0].addressModeW = GFXAddressWrap;
|
||||
desc.samplers[0].magFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].minFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].mipFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].textureColorOp = GFXTOPModulate;
|
||||
|
||||
mStateblock = GFX->createStateBlock( desc );
|
||||
|
||||
// Set up shader constants.
|
||||
mShaderConsts = mClearGBufferShader->allocConstBuffer();
|
||||
mSpecularStrengthSC = mClearGBufferShader->getShaderConstHandle( "$specularStrength" );
|
||||
mSpecularPowerSC = mClearGBufferShader->getShaderConstHandle( "$specularPower" );
|
||||
}
|
||||
|
||||
void RenderPrePassMgr::clearBuffers()
|
||||
{
|
||||
// Clear z-buffer.
|
||||
GFX->clear( GFXClearTarget | GFXClearZBuffer | GFXClearStencil, ColorI::ZERO, 1.0f, 0);
|
||||
|
||||
if ( !mClearGBufferShader )
|
||||
return;
|
||||
|
||||
GFXTransformSaver saver;
|
||||
|
||||
// Clear the g-buffer.
|
||||
RectI box(-1, -1, 3, 3);
|
||||
GFX->setWorldMatrix( MatrixF::Identity );
|
||||
GFX->setViewMatrix( MatrixF::Identity );
|
||||
GFX->setProjectionMatrix( MatrixF::Identity );
|
||||
|
||||
GFX->setShader(mClearGBufferShader);
|
||||
GFX->setStateBlock(mStateblock);
|
||||
|
||||
Point2F nw(-0.5,-0.5);
|
||||
Point2F ne(0.5,-0.5);
|
||||
|
||||
GFXVertexBufferHandle<GFXVertexPC> verts(GFX, 4, GFXBufferTypeVolatile);
|
||||
verts.lock();
|
||||
|
||||
F32 ulOffset = 0.5f - GFX->getFillConventionOffset();
|
||||
|
||||
Point2F upperLeft(-1.0, -1.0);
|
||||
Point2F lowerRight(1.0, 1.0);
|
||||
|
||||
verts[0].point.set( upperLeft.x+nw.x+ulOffset, upperLeft.y+nw.y+ulOffset, 0.0f );
|
||||
verts[1].point.set( lowerRight.x+ne.x, upperLeft.y+ne.y+ulOffset, 0.0f );
|
||||
verts[2].point.set( upperLeft.x-ne.x+ulOffset, lowerRight.y-ne.y, 0.0f );
|
||||
verts[3].point.set( lowerRight.x-nw.x, lowerRight.y-nw.y, 0.0f );
|
||||
|
||||
verts.unlock();
|
||||
|
||||
GFX->setVertexBuffer( verts );
|
||||
GFX->drawPrimitive( GFXTriangleStrip, 0, 2 );
|
||||
GFX->setShader(NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ public:
|
|||
// registered buffer name
|
||||
static const String BufferName;
|
||||
|
||||
// andremwac: Deferred Rendering
|
||||
static const String ColorBufferName;
|
||||
static const String MatInfoBufferName;
|
||||
|
||||
// Generic PrePass Render Instance Type
|
||||
static const RenderInstType RIT_PrePass;
|
||||
|
||||
|
|
@ -93,6 +97,22 @@ protected:
|
|||
virtual void _createPrePassMaterial();
|
||||
|
||||
bool _lightManagerActivate(bool active);
|
||||
|
||||
// Deferred Shading
|
||||
GFXVertexBufferHandle<GFXVertexPC> mClearGBufferVerts;
|
||||
GFXShaderRef mClearGBufferShader;
|
||||
GFXStateBlockRef mStateblock;
|
||||
NamedTexTarget mColorTarget;
|
||||
NamedTexTarget mMatInfoTarget;
|
||||
GFXTexHandle mColorTex;
|
||||
GFXTexHandle mMatInfoTex;
|
||||
GFXShaderConstBufferRef mShaderConsts;
|
||||
GFXShaderConstHandle *mSpecularStrengthSC;
|
||||
GFXShaderConstHandle *mSpecularPowerSC;
|
||||
|
||||
public:
|
||||
void clearBuffers();
|
||||
void _initShaders();
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "terrain/terrCell.h"
|
||||
#include "terrain/terrCellMaterial.h"
|
||||
#include "math/util/matrixSet.h"
|
||||
#include "materials/materialManager.h"
|
||||
|
||||
bool RenderTerrainMgr::smRenderWireframe = false;
|
||||
|
||||
|
|
@ -117,6 +118,10 @@ void RenderTerrainMgr::render( SceneRenderState *state )
|
|||
if ( mInstVector.empty() )
|
||||
return;
|
||||
|
||||
// Check if bin is disabled in advanced lighting.
|
||||
if ( MATMGR->getPrePassEnabled() && mBasicOnly )
|
||||
return;
|
||||
|
||||
PROFILE_SCOPE( RenderTerrainMgr_Render );
|
||||
|
||||
GFXTransformSaver saver;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue