2012-09-19 15:15:01 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// 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.
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-14 23:28:17 +00:00
|
|
|
#ifndef _DEFERRED_MGR_H_
|
|
|
|
|
#define _DEFERRED_MGR_H_
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
#include "renderInstance/renderTexTargetBinManager.h"
|
|
|
|
|
#include "materials/matInstance.h"
|
|
|
|
|
#include "materials/processedShaderMaterial.h"
|
|
|
|
|
#include "shaderGen/conditionerFeature.h"
|
|
|
|
|
#include "core/util/autoPtr.h"
|
|
|
|
|
|
|
|
|
|
// Forward declare
|
2017-04-11 05:23:14 +00:00
|
|
|
class DeferredMatInstance;
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
// This render manager renders opaque objects to the z-buffer as a z-fill pass.
|
|
|
|
|
// It can optionally accumulate data from this opaque render pass into a render
|
|
|
|
|
// target for later use.
|
2017-04-11 05:23:14 +00:00
|
|
|
class RenderDeferredMgr : public RenderTexTargetBinManager
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
typedef RenderTexTargetBinManager Parent;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
// registered buffer name
|
|
|
|
|
static const String BufferName;
|
|
|
|
|
|
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.
2016-02-16 07:50:58 +00:00
|
|
|
// andremwac: Deferred Rendering
|
|
|
|
|
static const String ColorBufferName;
|
|
|
|
|
static const String MatInfoBufferName;
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
// Generic Deferred Render Instance Type
|
|
|
|
|
static const RenderInstType RIT_Deferred;
|
2012-09-19 15:15:01 +00:00
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
RenderDeferredMgr( bool gatherDepth = true,
|
2012-09-19 15:15:01 +00:00
|
|
|
GFXFormat format = GFXFormatR16G16B16A16 );
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
virtual ~RenderDeferredMgr();
|
2012-09-19 15:15:01 +00:00
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
virtual void setDeferredMaterial( DeferredMatInstance *mat );
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
// RenderBinManager interface
|
|
|
|
|
virtual void render(SceneRenderState * state);
|
|
|
|
|
virtual void sort();
|
|
|
|
|
virtual void clear();
|
|
|
|
|
virtual void addElement( RenderInst *inst );
|
|
|
|
|
|
|
|
|
|
// ConsoleObject
|
2017-04-11 05:23:14 +00:00
|
|
|
DECLARE_CONOBJECT(RenderDeferredMgr);
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
typedef Signal<void(const SceneRenderState*, RenderDeferredMgr*, bool)> RenderSignal;
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
static RenderSignal& getRenderSignal();
|
|
|
|
|
|
|
|
|
|
static const U32 OpaqueStaticLitMask = BIT(1); ///< Stencil mask for opaque, lightmapped pixels
|
|
|
|
|
static const U32 OpaqueDynamicLitMask = BIT(0); ///< Stencil mask for opaque, dynamic lit pixels
|
|
|
|
|
|
|
|
|
|
static const GFXStateBlockDesc &getOpaqueStencilTestDesc();
|
|
|
|
|
static const GFXStateBlockDesc &getOpaqueStenciWriteDesc(bool lightmappedGeometry = true);
|
|
|
|
|
|
|
|
|
|
virtual bool setTargetSize(const Point2I &newTargetSize);
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
inline BaseMatInstance* getDeferredMaterial( BaseMatInstance *mat );
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
/// The terrain render instance elements.
|
|
|
|
|
Vector< MainSortElem > mTerrainElementList;
|
|
|
|
|
|
|
|
|
|
/// The object render instance elements.
|
|
|
|
|
Vector< MainSortElem > mObjectElementList;
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
DeferredMatInstance *mDeferredMatInstance;
|
2012-09-19 15:15:01 +00:00
|
|
|
|
2018-09-17 03:15:07 +00:00
|
|
|
///
|
|
|
|
|
Vector< MainSortElem > mProbeElementList;
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
virtual void _registerFeatures();
|
|
|
|
|
virtual void _unregisterFeatures();
|
|
|
|
|
virtual bool _updateTargets();
|
2017-04-11 05:23:14 +00:00
|
|
|
virtual void _createDeferredMaterial();
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
bool _lightManagerActivate(bool active);
|
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.
2016-02-16 07:50:58 +00:00
|
|
|
|
|
|
|
|
// Deferred Shading
|
|
|
|
|
NamedTexTarget mColorTarget;
|
|
|
|
|
NamedTexTarget mMatInfoTarget;
|
|
|
|
|
GFXTexHandle mColorTex;
|
|
|
|
|
GFXTexHandle mMatInfoTex;
|
2018-10-25 04:43:12 +00:00
|
|
|
GFXTexHandle mDiffuseLightTex;
|
|
|
|
|
GFXTexHandle mSpecularLightTex;
|
2018-09-16 01:19:57 +00:00
|
|
|
GFXShaderConstBufferRef mShaderConsts;
|
2012-09-19 15:15:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
class ProcessedDeferredMaterial : public ProcessedShaderMaterial
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
typedef ProcessedShaderMaterial Parent;
|
|
|
|
|
|
|
|
|
|
public:
|
2017-05-14 23:28:17 +00:00
|
|
|
ProcessedDeferredMaterial(Material& mat, const RenderDeferredMgr *deferredMgr);
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
virtual U32 getNumStages();
|
|
|
|
|
|
|
|
|
|
virtual void addStateBlockDesc(const GFXStateBlockDesc& desc);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void _determineFeatures( U32 stageNum, MaterialFeatureData &fd, const FeatureSet &features );
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
const RenderDeferredMgr *mDeferredMgr;
|
2012-09-19 15:15:01 +00:00
|
|
|
bool mIsLightmappedGeometry;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
class DeferredMatInstance : public MatInstance
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
typedef MatInstance Parent;
|
|
|
|
|
|
|
|
|
|
public:
|
2017-05-14 23:28:17 +00:00
|
|
|
DeferredMatInstance(MatInstance* root, const RenderDeferredMgr *deferredMgr);
|
2017-04-11 05:23:14 +00:00
|
|
|
virtual ~DeferredMatInstance();
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
bool init()
|
|
|
|
|
{
|
|
|
|
|
return init( mFeatureList, mVertexFormat );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MatInstance
|
|
|
|
|
virtual bool init( const FeatureSet &features,
|
|
|
|
|
const GFXVertexFormat *vertexFormat );
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ProcessedMaterial* getShaderMaterial();
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
const RenderDeferredMgr *mDeferredMgr;
|
2012-09-19 15:15:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
class DeferredMatInstanceHook : public MatInstanceHook
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2017-05-14 23:28:17 +00:00
|
|
|
DeferredMatInstanceHook(MatInstance *baseMatInst, const RenderDeferredMgr *deferredMgr);
|
2017-04-11 05:23:14 +00:00
|
|
|
virtual ~DeferredMatInstanceHook();
|
2012-09-19 15:15:01 +00:00
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
virtual DeferredMatInstance *getDeferredMatInstance() { return mHookedDeferredMatInst; }
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
virtual const MatInstanceHookType& getType() const { return Type; }
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
/// The type for deferred material hooks.
|
2012-09-19 15:15:01 +00:00
|
|
|
static const MatInstanceHookType Type;
|
|
|
|
|
|
|
|
|
|
protected:
|
2017-04-11 05:23:14 +00:00
|
|
|
DeferredMatInstance *mHookedDeferredMatInst;
|
|
|
|
|
const RenderDeferredMgr *mDeferredManager;
|
2012-09-19 15:15:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// A very simple, default depth conditioner feature
|
|
|
|
|
class LinearEyeDepthConditioner : public ConditionerFeature
|
|
|
|
|
{
|
|
|
|
|
typedef ConditionerFeature Parent;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
LinearEyeDepthConditioner(const GFXFormat bufferFormat)
|
|
|
|
|
: Parent(bufferFormat)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual String getName()
|
|
|
|
|
{
|
|
|
|
|
return "Linear Eye-Space Depth Conditioner";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
|
|
|
|
|
protected:
|
|
|
|
|
virtual Var *_conditionOutput( Var *unconditionedOutput, MultiLine *meta );
|
|
|
|
|
virtual Var *_unconditionInput( Var *conditionedInput, MultiLine *meta );
|
|
|
|
|
|
|
|
|
|
virtual Var *printMethodHeader( MethodType methodType, const String &methodName, Stream &stream, MultiLine *meta );
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
inline BaseMatInstance* RenderDeferredMgr::getDeferredMaterial( BaseMatInstance *mat )
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2017-04-11 05:23:14 +00:00
|
|
|
DeferredMatInstanceHook *hook = static_cast<DeferredMatInstanceHook*>( mat->getHook( DeferredMatInstanceHook::Type ) );
|
2012-09-19 15:15:01 +00:00
|
|
|
if ( !hook )
|
|
|
|
|
{
|
2017-04-11 05:23:14 +00:00
|
|
|
hook = new DeferredMatInstanceHook( static_cast<MatInstance*>( mat ), this );
|
2012-09-19 15:15:01 +00:00
|
|
|
mat->addHook( hook );
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-11 05:23:14 +00:00
|
|
|
return hook->getDeferredMatInstance();
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-14 23:28:17 +00:00
|
|
|
#endif // _DEFERRED_MGR_H_
|
2012-09-19 15:15:01 +00:00
|
|
|
|