advancedLightingFeatures.cpp
Engine/source/lighting/advanced/advancedLightingFeatures.cpp
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#include "platform/platform.h" 25#include "lighting/advanced/advancedLightingFeatures.h" 26 27#include "shaderGen/featureMgr.h" 28#include "gfx/gfxStringEnumTranslate.h" 29#include "materials/materialParameters.h" 30#include "materials/materialFeatureTypes.h" 31#include "materials/matTextureTarget.h" 32#include "gfx/gfxDevice.h" 33#include "core/util/safeDelete.h" 34 35#if defined( TORQUE_OS_WIN ) 36# include "lighting/advanced/hlsl/gBufferConditionerHLSL.h" 37# include "lighting/advanced/hlsl/advancedLightingFeaturesHLSL.h" 38#endif 39#if defined( TORQUE_OPENGL ) 40# include "lighting/advanced/glsl/gBufferConditionerGLSL.h" 41# include "lighting/advanced/glsl/advancedLightingFeaturesGLSL.h" 42#endif 43 44 45 46bool AdvancedLightingFeatures::smFeaturesRegistered = false; 47 48void AdvancedLightingFeatures::registerFeatures( const GFXFormat &deferredTargetFormat, const GFXFormat &lightInfoTargetFormat ) 49{ 50 AssertFatal( !smFeaturesRegistered, "AdvancedLightingFeatures::registerFeatures() - Features already registered. Bad!" ); 51 52 // If we ever need this... 53 TORQUE_UNUSED(lightInfoTargetFormat); 54 55 ConditionerFeature *cond = NULL; 56 57 if(GFX->getAdapterType() == OpenGL) 58 { 59#if defined( TORQUE_OPENGL ) 60 cond = new GBufferConditionerGLSL( deferredTargetFormat, GBufferConditionerGLSL::ViewSpace ); 61 FEATUREMGR->registerFeature(MFT_DeferredConditioner, cond); 62 FEATUREMGR->registerFeature(MFT_RTLighting, new DeferredRTLightingFeatGLSL()); 63 FEATUREMGR->registerFeature(MFT_NormalMap, new DeferredBumpFeatGLSL()); 64 FEATUREMGR->registerFeature(MFT_MinnaertShading, new DeferredMinnaertGLSL()); 65 FEATUREMGR->registerFeature(MFT_SubSurface, new DeferredSubSurfaceGLSL()); 66 FEATUREMGR->registerFeature(MFT_ReflectionProbes, new ReflectionProbeFeatGLSL); 67#endif 68 } 69 else 70 { 71#if defined( TORQUE_OS_WIN ) 72 cond = new GBufferConditionerHLSL( deferredTargetFormat, GBufferConditionerHLSL::ViewSpace ); 73 FEATUREMGR->registerFeature(MFT_DeferredConditioner, cond); 74 FEATUREMGR->registerFeature(MFT_RTLighting, new DeferredRTLightingFeatHLSL()); 75 FEATUREMGR->registerFeature(MFT_NormalMap, new DeferredBumpFeatHLSL()); 76 FEATUREMGR->registerFeature(MFT_MinnaertShading, new DeferredMinnaertHLSL()); 77 FEATUREMGR->registerFeature(MFT_SubSurface, new DeferredSubSurfaceHLSL()); 78 FEATUREMGR->registerFeature(MFT_ReflectionProbes, new ReflectionProbeFeatHLSL); 79#endif 80 } 81 82 NamedTexTarget *target = NamedTexTarget::find( "deferred" ); 83 if ( target ) 84 target->setConditioner( cond ); 85 86 smFeaturesRegistered = true; 87} 88 89void AdvancedLightingFeatures::unregisterFeatures() 90{ 91 NamedTexTarget *target = NamedTexTarget::find( "deferred" ); 92 if ( target ) 93 target->setConditioner( NULL ); 94 95 FEATUREMGR->unregisterFeature(MFT_DeferredConditioner); 96 FEATUREMGR->unregisterFeature(MFT_RTLighting); 97 FEATUREMGR->unregisterFeature(MFT_NormalMap); 98 FEATUREMGR->unregisterFeature(MFT_MinnaertShading); 99 FEATUREMGR->unregisterFeature(MFT_SubSurface); 100 101 smFeaturesRegistered = false; 102} 103