advancedLightBinManager.h
Engine/source/lighting/advanced/advancedLightBinManager.h
Classes:
class
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 24#ifndef _ADVANCEDLIGHTBINMANAGER_H_ 25#define _ADVANCEDLIGHTBINMANAGER_H_ 26 27#ifndef _TEXTARGETBIN_MGR_H_ 28#include "renderInstance/renderTexTargetBinManager.h" 29#endif 30#ifndef _TVECTOR_H_ 31#include "core/util/tVector.h" 32#endif 33#ifndef _LIGHTINFO_H_ 34#include "lighting/lightInfo.h" 35#endif 36#ifndef _MATHUTIL_FRUSTUM_H_ 37#include "math/util/frustum.h" 38#endif 39#ifndef _MATINSTANCE_H_ 40#include "materials/matInstance.h" 41#endif 42#ifndef _SHADOW_COMMON_H_ 43#include "lighting/shadowMap/shadowCommon.h" 44#endif 45 46 47class AdvancedLightManager; 48class ShadowMapManager; 49class LightShadowMap; 50class AdvancedLightBufferConditioner; 51class LightMapParams; 52 53 54class LightMatInstance : public MatInstance 55{ 56 typedef MatInstance Parent; 57protected: 58 MaterialParameterHandle *mLightMapParamsSC; 59 bool mInternalPass; 60 61 enum 62 { 63 DynamicLight = 0, 64 StaticLightNonLMGeometry, 65 StaticLightLMGeometry, 66 NUM_LIT_STATES 67 }; 68 GFXStateBlockRef mLitState[NUM_LIT_STATES]; 69 70public: 71 LightMatInstance(Material &mat) : Parent(mat), mLightMapParamsSC(NULL), mInternalPass(false) {} 72 73 virtual bool init( const FeatureSet &features, const GFXVertexFormat *vertexFormat ); 74 virtual bool setupPass( SceneRenderState *state, const SceneData &sgData ); 75}; 76 77 78class AdvancedLightBinManager : public RenderTexTargetBinManager 79{ 80 typedef RenderTexTargetBinManager Parent; 81 82public: 83 84 // Light info Render Inst Type 85 static const RenderInstType RIT_LightInfo; 86 87 // registered buffer name 88 static const String smBufferName; 89 90 /// The shadow filter mode to use on shadowed light materials. 91 static ShadowFilterMode smShadowFilterMode; 92 93 /// Used to toggle the PSSM debug rendering mode. 94 static bool smPSSMDebugRender; 95 96 /// Set by the SSAO post effect to tell the vector 97 /// light to compile in the SSAO mask. 98 static bool smUseSSAOMask; 99 100 // Used for console init 101 AdvancedLightBinManager( AdvancedLightManager *lm = NULL, 102 ShadowMapManager *sm = NULL, 103 GFXFormat lightBufferFormat = GFXFormatR8G8B8A8 ); 104 virtual ~AdvancedLightBinManager(); 105 106 // ConsoleObject 107 static void consoleInit(); 108 109 // RenderBinManager 110 virtual void render(SceneRenderState *); 111 virtual void clear() {} 112 virtual void sort() {} 113 114 // Add a light to the bins 115 void addLight( LightInfo *light ); 116 117 // Clear all lights from the bins 118 void clearAllLights(); 119 120 virtual bool setTargetSize(const Point2I &newTargetSize); 121 122 // ConsoleObject interface 123 DECLARE_CONOBJECT(AdvancedLightBinManager); 124 125 bool MRTLightmapsDuringPrePass() const { return mMRTLightmapsDuringPrePass; } 126 void MRTLightmapsDuringPrePass(bool val); 127 128 129 typedef Signal<void(SceneRenderState *, AdvancedLightBinManager *)> RenderSignal; 130 static RenderSignal &getRenderSignal(); 131 132 AdvancedLightManager *getManager() { return mLightManager; } 133 134protected: 135 136 /// Frees all the currently allocated light materials. 137 void _deleteLightMaterials(); 138 139 // Track a light material and associated data 140 struct LightMaterialInfo 141 { 142 LightMatInstance *matInstance; 143 144 // { zNear, zFar, 1/zNear, 1/zFar } 145 MaterialParameterHandle *zNearFarInvNearFar; 146 147 // Far frustum plane (World Space) 148 MaterialParameterHandle *farPlane; 149 150 // Far frustum plane (View Space) 151 MaterialParameterHandle *vsFarPlane; 152 153 // -dot( farPlane, eyePos ) 154 MaterialParameterHandle *negFarPlaneDotEye; 155 156 // Light Parameters 157 MaterialParameterHandle *lightPosition; 158 MaterialParameterHandle *lightDirection; 159 MaterialParameterHandle *lightColor; 160 MaterialParameterHandle *lightBrightness; 161 MaterialParameterHandle *lightAttenuation; 162 MaterialParameterHandle *lightRange; 163 MaterialParameterHandle *lightAmbient; 164 MaterialParameterHandle *lightTrilight; 165 MaterialParameterHandle *lightSpotParams; 166 167 LightMaterialInfo( const String &matName, 168 const GFXVertexFormat *vertexFormat, 169 const Vector<GFXShaderMacro> ¯os = Vector<GFXShaderMacro>() ); 170 171 virtual ~LightMaterialInfo(); 172 173 174 void setViewParameters( const F32 zNear, 175 const F32 zFar, 176 const Point3F &eyePos, 177 const PlaneF &farPlane, 178 const PlaneF &_vsFarPlane ); 179 180 void setLightParameters( const LightInfo *light, const SceneRenderState* renderState, const MatrixF &worldViewOnly ); 181 }; 182 183protected: 184 185 struct LightBinEntry 186 { 187 LightInfo* lightInfo; 188 LightShadowMap* shadowMap; 189 LightShadowMap* dynamicShadowMap; 190 LightMaterialInfo* lightMaterial; 191 GFXPrimitiveBuffer* primBuffer; 192 GFXVertexBuffer* vertBuffer; 193 U32 numPrims; 194 }; 195 196 Vector<LightBinEntry> mLightBin; 197 typedef Vector<LightBinEntry>::iterator LightBinIterator; 198 199 bool mMRTLightmapsDuringPrePass; 200 201 /// Used in setupSGData to set the object transform. 202 MatrixF mLightMat; 203 204 U32 mNumLightsCulled; 205 AdvancedLightManager *mLightManager; 206 ShadowMapManager *mShadowManager; 207 208 static const String smLightMatNames[LightInfo::Count]; 209 210 static const String smShadowTypeMacro[ShadowType_Count]; 211 212 static const GFXVertexFormat* smLightMatVertex[LightInfo::Count]; 213 214 typedef CompoundKey3<LightInfo::Type,ShadowType,bool> LightMatKey; 215 216 typedef HashTable<LightMatKey,LightMaterialInfo*> LightMatTable; 217 218 /// The fixed table of light material info. 219 LightMatTable mLightMaterials; 220 221 LightMaterialInfo* _getLightMaterial( LightInfo::Type lightType, ShadowType shadowType, bool useCookieTex ); 222 223 /// 224 void _onShadowFilterChanged(); 225 226 AdvancedLightBufferConditioner *mConditioner; 227 228 typedef GFXVertexPNTT FarFrustumQuadVert; 229 GFXVertexBufferHandle<FarFrustumQuadVert> mFarFrustumQuadVerts; 230 231 232 //void _createMaterials(); 233 234 void _setupPerFrameParameters( const SceneRenderState *state ); 235 236 void setupSGData( SceneData &data, const SceneRenderState* state, LightInfo *light ); 237}; 238 239#endif // _ADVANCEDLIGHTBINMANAGER_H_ 240
