Torque3D Documentation / _generateds / renderDeferredMgr.h

renderDeferredMgr.h

Engine/source/renderInstance/renderDeferredMgr.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23#ifndef _DEFERRED_MGR_H_
 24#define _DEFERRED_MGR_H_
 25
 26#include "renderInstance/renderTexTargetBinManager.h"
 27#include "materials/matInstance.h"
 28#include "materials/processedShaderMaterial.h"
 29#include "shaderGen/conditionerFeature.h"
 30#include "core/util/autoPtr.h"
 31
 32// Forward declare
 33class DeferredMatInstance;
 34
 35// This render manager renders opaque objects to the z-buffer as a z-fill pass.
 36// It can optionally accumulate data from this opaque render pass into a render
 37// target for later use.
 38class RenderDeferredMgr : public RenderTexTargetBinManager
 39{
 40   typedef RenderTexTargetBinManager Parent;
 41
 42public:
 43
 44   // registered buffer name
 45   static const String BufferName;
 46
 47   // andremwac: Deferred Rendering
 48   static const String ColorBufferName;
 49   static const String MatInfoBufferName;
 50
 51   // Generic Deferred Render Instance Type
 52   static const RenderInstType RIT_Deferred;
 53
 54   RenderDeferredMgr( bool gatherDepth = true, 
 55                     GFXFormat format = GFXFormatR16G16B16A16 );
 56
 57   virtual ~RenderDeferredMgr();
 58
 59   virtual void setDeferredMaterial( DeferredMatInstance *mat );
 60
 61   // RenderBinManager interface
 62   virtual void render(SceneRenderState * state);
 63   virtual void sort();
 64   virtual void clear();
 65   virtual void addElement( RenderInst *inst );
 66
 67   // ConsoleObject
 68   DECLARE_CONOBJECT(RenderDeferredMgr);
 69
 70
 71   typedef Signal<void(const SceneRenderState*, RenderDeferredMgr*, bool)> RenderSignal;
 72
 73   static RenderSignal& getRenderSignal();  
 74
 75   static const U32 OpaqueStaticLitMask = BIT(1);     ///< Stencil mask for opaque, lightmapped pixels
 76   static const U32 OpaqueDynamicLitMask = BIT(0);    ///< Stencil mask for opaque, dynamic lit pixels
 77
 78   static const GFXStateBlockDesc &getOpaqueStencilTestDesc();
 79   static const GFXStateBlockDesc &getOpaqueStenciWriteDesc(bool lightmappedGeometry = true);
 80
 81   virtual bool setTargetSize(const Point2I &newTargetSize);
 82
 83   inline BaseMatInstance* getDeferredMaterial( BaseMatInstance *mat );
 84
 85protected:
 86
 87   /// The terrain render instance elements.
 88   Vector< MainSortElem> mTerrainElementList;
 89
 90   /// The object render instance elements.
 91   Vector< MainSortElem> mObjectElementList;
 92
 93   DeferredMatInstance *mDeferredMatInstance;
 94
 95   ///
 96   Vector< MainSortElem> mProbeElementList;
 97
 98   virtual void _registerFeatures();
 99   virtual void _unregisterFeatures();
100   virtual bool _updateTargets();
101   virtual void _createDeferredMaterial();
102
103   bool _lightManagerActivate(bool active);
104
105   // Deferred Shading
106   NamedTexTarget                      mColorTarget;
107   NamedTexTarget                      mMatInfoTarget;
108   GFXTexHandle                        mColorTex;
109   GFXTexHandle                        mMatInfoTex;
110   GFXTexHandle                        mDiffuseLightTex;
111   GFXTexHandle                        mSpecularLightTex;
112   GFXShaderConstBufferRef             mShaderConsts; 
113};
114
115//------------------------------------------------------------------------------
116
117class ProcessedDeferredMaterial : public ProcessedShaderMaterial
118{
119   typedef ProcessedShaderMaterial Parent;
120   
121public:   
122   ProcessedDeferredMaterial(Material& mat, const RenderDeferredMgr *deferredMgr);
123
124   virtual U32 getNumStages();
125
126   virtual void addStateBlockDesc(const GFXStateBlockDesc& desc);
127
128protected:
129   virtual void _determineFeatures( U32 stageNum, MaterialFeatureData &fd, const FeatureSet &features );
130
131   const RenderDeferredMgr *mDeferredMgr;
132   bool mIsLightmappedGeometry;
133};
134
135//------------------------------------------------------------------------------
136
137class DeferredMatInstance : public MatInstance
138{
139   typedef MatInstance Parent;
140
141public:   
142   DeferredMatInstance(MatInstance* root, const RenderDeferredMgr *deferredMgr);
143   virtual ~DeferredMatInstance();
144
145   bool init()
146   {
147      return init( mFeatureList, mVertexFormat );
148   }   
149
150   // MatInstance
151   virtual bool init(   const FeatureSet &features, 
152                        const GFXVertexFormat *vertexFormat );
153
154protected:      
155   virtual ProcessedMaterial* getShaderMaterial();
156
157   const RenderDeferredMgr *mDeferredMgr;
158};
159
160//------------------------------------------------------------------------------
161
162class DeferredMatInstanceHook : public MatInstanceHook
163{
164public:
165   DeferredMatInstanceHook(MatInstance *baseMatInst, const RenderDeferredMgr *deferredMgr);
166   virtual ~DeferredMatInstanceHook();
167
168   virtual DeferredMatInstance *getDeferredMatInstance() { return mHookedDeferredMatInst; }
169
170   virtual const MatInstanceHookType& getType() const { return Type; }
171
172   /// The type for deferred material hooks.
173   static const MatInstanceHookType Type;
174
175protected:
176   DeferredMatInstance *mHookedDeferredMatInst; 
177   const RenderDeferredMgr *mDeferredManager;
178};
179
180//------------------------------------------------------------------------------
181
182// A very simple, default depth conditioner feature
183class LinearEyeDepthConditioner : public ConditionerFeature
184{
185   typedef ConditionerFeature Parent;
186
187public:
188   LinearEyeDepthConditioner(const GFXFormat bufferFormat) 
189      : Parent(bufferFormat)
190   {
191
192   }
193
194   virtual String getName()
195   {
196      return "Linear Eye-Space Depth Conditioner";
197   }
198
199   virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
200protected:
201   virtual Var *_conditionOutput( Var *unconditionedOutput, MultiLine *meta );
202   virtual Var *_unconditionInput( Var *conditionedInput, MultiLine *meta );
203
204   virtual Var *printMethodHeader( MethodType methodType, const String &methodName, Stream &stream, MultiLine *meta );
205};
206
207
208inline BaseMatInstance* RenderDeferredMgr::getDeferredMaterial( BaseMatInstance *mat )
209{
210   DeferredMatInstanceHook *hook = static_cast<DeferredMatInstanceHook*>( mat->getHook( DeferredMatInstanceHook::Type ) );
211   if ( !hook )
212   {
213      hook = new DeferredMatInstanceHook( static_cast<MatInstance*>( mat ), this );
214      mat->addHook( hook );
215   }
216
217   return hook->getDeferredMatInstance();
218}
219
220#endif // _DEFERRED_MGR_H_
221
222