mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 19:53:48 +00:00
Deferred Shading
Phase 1: buffers engine: provides the following hooks and methods A) render target "color", and "matinfo". these correspond to texture[0] = "#color"; texture[2] = "#matinfo"; entries in scripts B) utilizes the independentMrtBitDepth method added GarageGames#857 to set color to an 8RGBA if cards support it C) adds an RenderPrePassMgr::_initShaders() method to support void RenderPrePassMgr::clearBuffers(). This operates as a pseudo-postfx by rendering a veiwspace plane which fills the screen, then calls a shader which fills both the introduced rendertarget buffers and the prepass buffer to relevant defaults (white with full alpha for prepass, black with full alpha for color and material respectively) script: \game\tools\worldEditor\main.cs adds additional hooks similar to GarageGames#863 for colorbuffer, specular map, and backbuffer display \game\core\scripts\client\lighting\advanced\deferredShading.cs adds the clearbuffer shader, visualizers, and the ShaderData( AL_DeferredShader ) + PostEffect( AL_DeferredShading ) which combine the various buffers into the output which reaches the screen under normal conditions, as well as the extended debug visualizers. again, note the lines texture[0] = "#color"; texture[1] = "#lightinfo"; texture[2] = "#matinfo"; target = "$backBuffer"; in particular for the core tie-in. shader: \game\shaders\common\lighting\advanced\deferredColorShaderP.hlsl \game\shaders\common\lighting\advanced\gl\deferredClearGBufferP.glsl the previously mentioned shaders which clear the buffers to specified colors \game\shaders\common\lighting\advanced\deferredShadingP.hlsl \game\shaders\common\lighting\advanced\gl\deferredShadingP.glsl the tie-in shaders the rest are visualizers purpose: to expose methodology that allows one to render color, lighting and material information such as specular and gloss which effect the result of both when combined long term intent: the previous prepass lighting methodology while serviceable, unfortunately had the side effect of throwing out raw color information required by more modern pipelines and methodologies. This preserves that data while also allowing the manipulation to occur only on a screenspace (or reflected speudo-screenspace) basis.
This commit is contained in:
parent
cb22357eb2
commit
5b5c6b9907
13 changed files with 824 additions and 19 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue