Torque3D Documentation / _generateds / renderPrePassMgr.h

renderPrePassMgr.h

Engine/source/renderInstance/renderPrePassMgr.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 _PREPASS_MGR_H_
 24#define _PREPASS_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 PrePassMatInstance;
 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 RenderPrePassMgr : 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 PrePass Render Instance Type
 52   static const RenderInstType RIT_PrePass;
 53
 54   RenderPrePassMgr( bool gatherDepth = true, 
 55                     GFXFormat format = GFXFormatR16G16B16A16 );
 56
 57   virtual ~RenderPrePassMgr();
 58
 59   virtual void setPrePassMaterial( PrePassMatInstance *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(RenderPrePassMgr);
 69
 70
 71   typedef Signal<void(const SceneRenderState*, RenderPrePassMgr*, 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* getPrePassMaterial( 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   PrePassMatInstance *mPrePassMatInstance;
 94
 95   virtual void _registerFeatures();
 96   virtual void _unregisterFeatures();
 97   virtual bool _updateTargets();
 98   virtual void _createPrePassMaterial();
 99
100   bool _lightManagerActivate(bool active);
101
102   // Deferred Shading
103   GFXVertexBufferHandle<GFXVertexPC>  mClearGBufferVerts;
104   GFXShaderRef                        mClearGBufferShader;
105   GFXStateBlockRef                    mStateblock;
106   NamedTexTarget                      mColorTarget;
107   NamedTexTarget                      mMatInfoTarget;
108   GFXTexHandle                        mColorTex;
109   GFXTexHandle                        mMatInfoTex;
110   GFXShaderConstBufferRef             mShaderConsts;
111   GFXShaderConstHandle                *mSpecularStrengthSC;  
112   GFXShaderConstHandle                *mSpecularPowerSC;
113
114public:
115   void clearBuffers();
116   void _initShaders();
117};
118
119//------------------------------------------------------------------------------
120
121class ProcessedPrePassMaterial : public ProcessedShaderMaterial
122{
123   typedef ProcessedShaderMaterial Parent;
124   
125public:   
126   ProcessedPrePassMaterial(Material& mat, const RenderPrePassMgr *prePassMgr);
127
128   virtual U32 getNumStages();
129
130   virtual void addStateBlockDesc(const GFXStateBlockDesc& desc);
131
132protected:
133   virtual void _determineFeatures( U32 stageNum, MaterialFeatureData &fd, const FeatureSet &features );
134
135   const RenderPrePassMgr *mPrePassMgr;
136   bool mIsLightmappedGeometry;
137};
138
139//------------------------------------------------------------------------------
140
141class PrePassMatInstance : public MatInstance
142{
143   typedef MatInstance Parent;
144
145public:   
146   PrePassMatInstance(MatInstance* root, const RenderPrePassMgr *prePassMgr);
147   virtual ~PrePassMatInstance();
148
149   bool init()
150   {
151      return init( mFeatureList, mVertexFormat );
152   }   
153
154   // MatInstance
155   virtual bool init(   const FeatureSet &features, 
156                        const GFXVertexFormat *vertexFormat );
157
158protected:      
159   virtual ProcessedMaterial* getShaderMaterial();
160
161   const RenderPrePassMgr *mPrePassMgr;
162};
163
164//------------------------------------------------------------------------------
165
166class PrePassMatInstanceHook : public MatInstanceHook
167{
168public:
169   PrePassMatInstanceHook(MatInstance *baseMatInst, const RenderPrePassMgr *prePassMgr);
170   virtual ~PrePassMatInstanceHook();
171
172   virtual PrePassMatInstance *getPrePassMatInstance() { return mHookedPrePassMatInst; }
173
174   virtual const MatInstanceHookType& getType() const { return Type; }
175
176   /// The type for prepass material hooks.
177   static const MatInstanceHookType Type;
178
179protected:
180   PrePassMatInstance *mHookedPrePassMatInst; 
181   const RenderPrePassMgr *mPrePassManager;
182};
183
184//------------------------------------------------------------------------------
185
186// A very simple, default depth conditioner feature
187class LinearEyeDepthConditioner : public ConditionerFeature
188{
189   typedef ConditionerFeature Parent;
190
191public:
192   LinearEyeDepthConditioner(const GFXFormat bufferFormat) 
193      : Parent(bufferFormat)
194   {
195
196   }
197
198   virtual String getName()
199   {
200      return "Linear Eye-Space Depth Conditioner";
201   }
202
203   virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
204protected:
205   virtual Var *_conditionOutput( Var *unconditionedOutput, MultiLine *meta );
206   virtual Var *_unconditionInput( Var *conditionedInput, MultiLine *meta );
207
208   virtual Var *printMethodHeader( MethodType methodType, const String &methodName, Stream &stream, MultiLine *meta );
209};
210
211
212inline BaseMatInstance* RenderPrePassMgr::getPrePassMaterial( BaseMatInstance *mat )
213{
214   PrePassMatInstanceHook *hook = static_cast<PrePassMatInstanceHook*>( mat->getHook( PrePassMatInstanceHook::Type ) );
215   if ( !hook )
216   {
217      hook = new PrePassMatInstanceHook( static_cast<MatInstance*>( mat ), this );
218      mat->addHook( hook );
219   }
220
221   return hook->getPrePassMatInstance();
222}
223
224#endif // _PREPASS_MGR_H_
225
226