Merge branch 'PBR_PR' of https://github.com/rextimmy/Torque3D into PBR_PR

This commit is contained in:
Azaezel 2018-10-24 20:48:45 -05:00
commit 2cd03ab765
8 changed files with 46 additions and 265 deletions

View file

@ -940,15 +940,22 @@ void GFXD3D11Device::clear(U32 flags, const LinearColorF& color, F32 z, U32 sten
UINT depthstencilFlag = 0;
ID3D11RenderTargetView* rtView = NULL;
//TODO: current support is 5 render targets, clean this up
ID3D11RenderTargetView* rtView[5] = { NULL };
ID3D11DepthStencilView* dsView = NULL;
mD3DDeviceContext->OMGetRenderTargets(1, &rtView, &dsView);
mD3DDeviceContext->OMGetRenderTargets(5, rtView, &dsView);
const FLOAT clearColor[4] = { color.red, color.green, color.blue, color.alpha };
if (flags & GFXClearTarget && rtView)
mD3DDeviceContext->ClearRenderTargetView(rtView, clearColor);
{
for (U32 i = 0; i < 5; i++)
{
if(rtView[i])
mD3DDeviceContext->ClearRenderTargetView(rtView[i], clearColor);
}
}
if (flags & GFXClearZBuffer)
depthstencilFlag |= D3D11_CLEAR_DEPTH;
@ -959,7 +966,9 @@ void GFXD3D11Device::clear(U32 flags, const LinearColorF& color, F32 z, U32 sten
if (depthstencilFlag && dsView)
mD3DDeviceContext->ClearDepthStencilView(dsView, depthstencilFlag, z, stencil);
SAFE_RELEASE(rtView);
for (U32 i = 0; i < 5; i++)
SAFE_RELEASE(rtView[i]);
SAFE_RELEASE(dsView);
}

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

@ -26,13 +26,20 @@ new GFXStateBlockData( AL_VectorLightState )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha;
blendSrc = GFXBlendOne;
blendDest = GFXBlendOne;
blendOp = GFXBlendOpAdd;
colorWriteDefined = true;
colorWriteRed = true;
colorWriteBlue = true;
colorWriteGreen = true;
colorWriteAlpha = false; //disable alpha write
zDefined = true;
zEnable = false;
zWriteEnable = false;
zWriteEnable = true;
zFunc = GFXCmpGreater;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint; // G-buffer
@ -49,12 +56,7 @@ new GFXStateBlockData( AL_VectorLightState )
cullMode = GFXCullNone;
stencilDefined = true;
stencilEnable = true;
stencilFailOp = GFXStencilOpKeep;
stencilZFailOp = GFXStencilOpKeep;
stencilPassOp = GFXStencilOpKeep;
stencilFunc = GFXCmpLess;
stencilRef = 0;
stencilEnable = false;
};
// Vector Light Material
@ -102,14 +104,20 @@ new GFXStateBlockData( AL_ConvexLightState )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha;
blendSrc = GFXBlendOne;
blendDest = GFXBlendOne;
blendOp = GFXBlendOpAdd;
colorWriteDefined = true;
colorWriteRed = true;
colorWriteBlue = true;
colorWriteGreen = true;
colorWriteAlpha = false; //disable alpha write
zDefined = true;
zEnable = true;
zWriteEnable = false;
zFunc = GFXCmpGreaterEqual;
zFunc = GFXCmpGreater;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint; // G-buffer
@ -125,12 +133,7 @@ new GFXStateBlockData( AL_ConvexLightState )
cullMode = GFXCullCW;
stencilDefined = true;
stencilEnable = true;
stencilFailOp = GFXStencilOpKeep;
stencilZFailOp = GFXStencilOpKeep;
stencilPassOp = GFXStencilOpKeep;
stencilFunc = GFXCmpLess;
stencilRef = 0;
stencilEnable = false;
};
// Point Light Material
@ -297,10 +300,16 @@ new GFXStateBlockData( AL_ProbeState )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha;
blendSrc = GFXBlendSrcAlpha; //TODO change this to GFXBlendOne once probes are done in one pass!
blendDest = GFXBlendOne;
blendOp = GFXBlendOpAdd;
colorWriteDefined = true;
colorWriteRed = true;
colorWriteBlue = true;
colorWriteGreen = true;
colorWriteAlpha = true;
zDefined = true;
zEnable = true;
zWriteEnable = false;

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);
}