clear gbuffer from code and not from a shader

This commit is contained in:
Tim Barnes 2018-10-24 18:58:46 +10:00
parent 2810eac6b5
commit b182b0cf3b
6 changed files with 7 additions and 244 deletions

View file

@ -105,8 +105,6 @@ RenderDeferredMgr::RenderDeferredMgr( bool gatherDepth,
mMatInfoTarget.registerWithName( MatInfoBufferName );
mLightMapTarget.registerWithName( LightMapBufferName );
mClearGBufferShader = NULL;
_registerFeatures();
}
@ -199,7 +197,6 @@ bool RenderDeferredMgr::_updateTargets()
mTargetChain[i]->attachTexture(GFXTextureTarget::Color3, mLightMapTarget.getTexture());
}
GFX->finalizeReset();
_initShaders();
return ret;
}
@ -323,8 +320,12 @@ void RenderDeferredMgr::render( SceneRenderState *state )
// Tell the superclass we're about to render
const bool isRenderingToTarget = _onPreRender(state);
// Clear all z-buffer, and g-buffer.
clearBuffers();
// Clear z-buffer and g-buffer.
GFX->clear(GFXClearTarget | GFXClearZBuffer | GFXClearStencil, ColorI::ZERO, 1.0f, 0);
GFX->clearColorAttachment(0, LinearColorF::ONE);
GFX->clearColorAttachment(1, LinearColorF::ZERO);
GFX->clearColorAttachment(2, LinearColorF::ZERO);
GFX->clearColorAttachment(3, LinearColorF::ZERO);
// Restore transforms
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
@ -1088,78 +1089,3 @@ Var* LinearEyeDepthConditioner::printMethodHeader( MethodType methodType, const
return retVal;
}
void RenderDeferredMgr::_initShaders()
{
if ( mClearGBufferShader ) return;
// Find ShaderData
ShaderData *shaderData;
mClearGBufferShader = Sim::findObject( "ClearGBufferShader", shaderData ) ? shaderData->getShader() : NULL;
if ( !mClearGBufferShader )
Con::errorf( "RenderDeferredMgr::_initShaders - could not find ClearGBufferShader" );
// Create StateBlocks
GFXStateBlockDesc desc;
desc.setCullMode( GFXCullNone );
desc.setBlend( false );
desc.setZReadWrite( false, false );
desc.samplersDefined = true;
for (int i = 0; i < TEXTURE_STAGE_COUNT; i++)
{
desc.samplers[i].addressModeU = GFXAddressWrap;
desc.samplers[i].addressModeV = GFXAddressWrap;
desc.samplers[i].addressModeW = GFXAddressWrap;
desc.samplers[i].magFilter = GFXTextureFilterLinear;
desc.samplers[i].minFilter = GFXTextureFilterLinear;
desc.samplers[i].mipFilter = GFXTextureFilterLinear;
desc.samplers[i].textureColorOp = GFXTOPModulate;
}
mStateblock = GFX->createStateBlock( desc );
// Set up shader constants.
mShaderConsts = mClearGBufferShader->allocConstBuffer();
}
void RenderDeferredMgr::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);
}

View file

@ -103,20 +103,13 @@ protected:
bool _lightManagerActivate(bool active);
// Deferred Shading
GFXVertexBufferHandle<GFXVertexPC> mClearGBufferVerts;
GFXShaderRef mClearGBufferShader;
GFXStateBlockRef mStateblock;
NamedTexTarget mColorTarget;
NamedTexTarget mMatInfoTarget;
NamedTexTarget mLightMapTarget;
GFXTexHandle mColorTex;
GFXTexHandle mMatInfoTex;
GFXTexHandle mLightMapTex;
GFXShaderConstBufferRef mShaderConsts;
GFXTexHandle mLightMapTex;
public:
void clearBuffers();
void _initShaders();
};
//------------------------------------------------------------------------------

View file

@ -1,14 +1,3 @@
singleton ShaderData( ClearGBufferShader )
{
DXVertexShaderFile = "shaders/common/lighting/advanced/deferredClearGBufferV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/deferredClearGBufferP.hlsl";
OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/deferredClearGBufferP.glsl";
pixVersion = 2.0;
};
singleton ShaderData( DeferredColorShader )
{
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";

View file

@ -1,58 +0,0 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#include "../../shaderModel.hlsl"
struct Conn
{
float4 hpos : TORQUE_POSITION;
};
struct Fragout
{
float4 col : TORQUE_TARGET0;
float4 col1 : TORQUE_TARGET1;
float4 col2 : TORQUE_TARGET2;
float4 col3 : TORQUE_TARGET3;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main( Conn IN )
{
Fragout OUT;
// Clear Deferred Buffer ( Normals/Depth );
OUT.col = float4(1.0, 1.0, 1.0, 1.0);
// Clear Color Buffer.
OUT.col1 = float4(0.0, 0.0, 0.0, 0.0001);
// Clear Material Info Buffer.
OUT.col2 = float4(0.0, 0.0, 0.0, 0.0);
// Clear Light Info Buffer.
OUT.col3 = float4(0.0, 0.0, 0.0, 0.0);
return OUT;
}

View file

@ -1,43 +0,0 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#include "../../shaderModel.hlsl"
struct Appdata
{
float3 pos : POSITION;
float4 color : COLOR;
};
struct Conn
{
float4 hpos : TORQUE_POSITION;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.hpos = float4(In.pos,1.0);
return Out;
}

View file

@ -1,44 +0,0 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
out vec4 OUT_col;
out vec4 OUT_col1;
out vec4 OUT_col2;
out vec4 OUT_col3;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
// Clear Deferred Buffer ( Normals/Depth );
OUT_col = vec4(1.0, 1.0, 1.0, 1.0);
// Clear Color Buffer.
OUT_col1 = vec4(0.0, 0.0, 0.0, 0.0001);
// Clear Material Info Buffer.
OUT_col2 = vec4(0.0, 0.0, 0.0, 0.0);
// Clear Light Info Buffer.
OUT_col3 = vec4(0.0, 0.0, 0.0, 0.0);
}