diff --git a/Engine/source/materials/processedCustomMaterial.cpp b/Engine/source/materials/processedCustomMaterial.cpp index abca21dd9..43d21ec8f 100644 --- a/Engine/source/materials/processedCustomMaterial.cpp +++ b/Engine/source/materials/processedCustomMaterial.cpp @@ -328,6 +328,7 @@ bool ProcessedCustomMaterial::setupPass( SceneRenderState *state, const SceneDat shaderConsts->setSafe(rpd->shaderHandles.mAccumTimeSC, MATMGR->getTotalTime()); shaderConsts->setSafe(rpd->shaderHandles.mDampnessSC, MATMGR->getDampnessClamped()); + shaderConsts->setSafe(rpd->shaderHandles.mIsCapturingSC, state ? (S32)state->isCapturing() : 0); return true; } diff --git a/Engine/source/materials/processedShaderMaterial.cpp b/Engine/source/materials/processedShaderMaterial.cpp index 83f58e1d9..450d0bf25 100644 --- a/Engine/source/materials/processedShaderMaterial.cpp +++ b/Engine/source/materials/processedShaderMaterial.cpp @@ -115,6 +115,8 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/) // MFT_HardwareSkinning mNodeTransforms = shader->getShaderConstHandle( "$nodeTransforms" ); + mIsCapturingSC = shader->getShaderConstHandle(ShaderGenVars::isCapturing); + // Clear any existing texture handles. dMemset( mTexHandlesSC, 0, sizeof( mTexHandlesSC ) ); if(mat) @@ -1093,6 +1095,8 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons shaderConsts->setSafe( handles->mAccumTimeSC, MATMGR->getTotalTime() ); shaderConsts->setSafe(handles->mDampnessSC, MATMGR->getDampnessClamped()); + shaderConsts->setSafe(handles->mIsCapturingSC, (S32)state->isCapturing()); + // If the shader constants have not been lost then // they contain the content from a previous render pass. // diff --git a/Engine/source/materials/processedShaderMaterial.h b/Engine/source/materials/processedShaderMaterial.h index a1bde06f1..e922b61a8 100644 --- a/Engine/source/materials/processedShaderMaterial.h +++ b/Engine/source/materials/processedShaderMaterial.h @@ -104,6 +104,7 @@ public: GFXShaderConstHandle* mNodeTransforms; + GFXShaderConstHandle* mIsCapturingSC; struct customHandleData { StringTableEntry handleName; diff --git a/Engine/source/postFx/postEffect.cpp b/Engine/source/postFx/postEffect.cpp index f5513f848..c1ebaee52 100644 --- a/Engine/source/postFx/postEffect.cpp +++ b/Engine/source/postFx/postEffect.cpp @@ -498,7 +498,8 @@ PostEffect::PostEffect() mMatCameraToWorldSC( NULL), mInvCameraTransSC(NULL), mMatCameraToScreenSC(NULL), - mMatScreenToCameraSC(NULL) + mMatScreenToCameraSC(NULL), + mIsCapturingSC(NULL) { dMemset( mTexSRGB, 0, sizeof(bool) * NumTextures); dMemset( mActiveTextures, 0, sizeof( GFXTextureObject* ) * NumTextures ); @@ -798,8 +799,12 @@ void PostEffect::_setupConstants( const SceneRenderState *state ) mInvCameraTransSC = mShader->getShaderConstHandle("$invCameraTrans"); mMatCameraToScreenSC = mShader->getShaderConstHandle("$cameraToScreen"); mMatScreenToCameraSC = mShader->getShaderConstHandle("$screenToCamera"); + mIsCapturingSC = mShader->getShaderConstHandle("$isCapturing"); } + if (mIsCapturingSC->isValid()) + mShaderConsts->set(mIsCapturingSC, (S32)state->isCapturing()); + // Set up shader constants for source image size if ( mRTSizeSC->isValid() ) { diff --git a/Engine/source/postFx/postEffect.h b/Engine/source/postFx/postEffect.h index 9b7e7afef..89c4b7427 100644 --- a/Engine/source/postFx/postEffect.h +++ b/Engine/source/postFx/postEffect.h @@ -164,6 +164,8 @@ protected: GFXShaderConstHandle *mMatCameraToScreenSC; GFXShaderConstHandle *mMatScreenToCameraSC; + GFXShaderConstHandle* mIsCapturingSC; + bool mAllowReflectPass; /// If true update the shader. diff --git a/Engine/source/renderInstance/renderProbeMgr.cpp b/Engine/source/renderInstance/renderProbeMgr.cpp index 954d199e2..32f781f15 100644 --- a/Engine/source/renderInstance/renderProbeMgr.cpp +++ b/Engine/source/renderInstance/renderProbeMgr.cpp @@ -503,47 +503,13 @@ void RenderProbeMgr::reloadTextures() void RenderProbeMgr::preBake() { RenderProbeMgr::smBakeReflectionProbes = true; - GFXShader::addGlobalMacro("CAPTURING", String("1")); - - //Con::setVariable("$Probes::Capturing", "1"); - mRenderMaximumNumOfLights = AdvancedLightBinManager::smMaximumNumOfLights; - mRenderUseLightFade = AdvancedLightBinManager::smUseLightFade; - - AdvancedLightBinManager::smMaximumNumOfLights = -1; - AdvancedLightBinManager::smUseLightFade = false; - - //kickstart rendering - LightManager* lm = LIGHTMGR; - if (lm) - { - SceneManager* sm = lm->getSceneManager(); - if (sm && sm->getContainer() == &gClientContainer) - { - lm->deactivate(); - lm->activate(sm); - } - } + Con::setBoolVariable("$ReflectionProbes::Capturing", RenderProbeMgr::smBakeReflectionProbes); } void RenderProbeMgr::postBake() { RenderProbeMgr::smBakeReflectionProbes = false; - GFXShader::addGlobalMacro("CAPTURING", String("0")); - //Con::setVariable("$Probes::Capturing", "0"); - AdvancedLightBinManager::smMaximumNumOfLights = mRenderMaximumNumOfLights; - AdvancedLightBinManager::smUseLightFade = mRenderUseLightFade; - - //kickstart rendering - LightManager* lm = LIGHTMGR; - if (lm) - { - SceneManager* sm = lm->getSceneManager(); - if (sm && sm->getContainer() == &gClientContainer) - { - lm->deactivate(); - lm->activate(sm); - } - } + Con::setBoolVariable("$ReflectionProbes::Capturing", RenderProbeMgr::smBakeReflectionProbes); } void RenderProbeMgr::bakeProbe(ReflectionProbe* probe) diff --git a/Engine/source/scene/sceneRenderState.h b/Engine/source/scene/sceneRenderState.h index f6596a907..37d4763ab 100644 --- a/Engine/source/scene/sceneRenderState.h +++ b/Engine/source/scene/sceneRenderState.h @@ -223,6 +223,7 @@ class SceneRenderState /// Returns true if this is not one of the other rendering passes. bool isOtherPass() const { return mScenePassType >= SPT_Other; } + bool isCapturing() const { return Con::getBoolVariable("$ReflectionProbes::Capturing", false); }; /// @} /// @name Render Style diff --git a/Engine/source/shaderGen/shaderGenVars.cpp b/Engine/source/shaderGen/shaderGenVars.cpp index b1fa02347..e6a334893 100644 --- a/Engine/source/shaderGen/shaderGenVars.cpp +++ b/Engine/source/shaderGen/shaderGenVars.cpp @@ -74,6 +74,8 @@ const String ShaderGenVars::vectorLightDirection("$vectorLightDirection"); const String ShaderGenVars::vectorLightColor("$vectorLightColor"); const String ShaderGenVars::vectorLightBrightness("$vectorLightBrightness"); +const String ShaderGenVars::isCapturing("$isCapturing"); + const String ShaderGenVars::ormConfig("$ORMConfig"); const String ShaderGenVars::roughness("$roughness"); const String ShaderGenVars::metalness("$metalness"); diff --git a/Engine/source/shaderGen/shaderGenVars.h b/Engine/source/shaderGen/shaderGenVars.h index a4e87338c..4acc97fa8 100644 --- a/Engine/source/shaderGen/shaderGenVars.h +++ b/Engine/source/shaderGen/shaderGenVars.h @@ -86,6 +86,8 @@ struct ShaderGenVars const static String vectorLightColor; const static String vectorLightBrightness; + const static String isCapturing; + const static String ormConfig; const static String roughness; const static String metalness; diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl index 723a62511..b221ac9fc 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl @@ -24,6 +24,7 @@ #include "./brdf.glsl" uniform float maxProbeDrawDistance; +uniform int isCapturing; #ifndef TORQUE_SHADERGEN #line 27 @@ -54,10 +55,6 @@ uniform vec4 albedo; #define MAX_FORWARD_LIGHT 4 -#ifndef CAPTURING -#define CAPTURING 0 -#endif - #ifndef DEBUGVIZ_ATTENUATION #define DEBUGVIZ_ATTENUATION 0 #endif @@ -237,32 +234,28 @@ vec3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight) float D = D_GGX(surfaceToLight.NdotH, surface.linearRoughnessSq); vec3 Fr = D * F * Vis; -#if CAPTURING == 1 - return mix(Fd + Fr, surface.baseColor.rgb, surface.metalness); -#else - return Fd + Fr; -#endif - + if(isCapturing == 1) + return mix(Fd + Fr, surface.baseColor.rgb, surface.metalness); + else + return Fd + Fr; } vec3 getDirectionalLight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float shadow) { -#if CAPTURING == 1 float lightfloor = CAPTURE_LIGHT_FLOOR; -#else - float lightfloor = 0.0; -#endif + if(isCapturing != 1) + lightfloor = 0.0; + vec3 factor = lightColor * max(surfaceToLight.NdotL * shadow * lightIntensity, lightfloor); return evaluateStandardBRDF(surface,surfaceToLight) * factor; } vec3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float radius, float shadow) { -#if CAPTURING == 1 float lightfloor = CAPTURE_LIGHT_FLOOR; -#else - float lightfloor = 0.0; -#endif + if(isCapturing != 1) + lightfloor = 0.0; + float attenuation = getDistanceAtt(surfaceToLight.Lu, radius); vec3 factor = lightColor * max(surfaceToLight.NdotL * shadow * lightIntensity * attenuation, lightfloor); return evaluateStandardBRDF(surface,surfaceToLight) * factor; @@ -270,11 +263,10 @@ vec3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, vec3 light vec3 getSpotlight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float radius, vec3 lightDir, vec2 lightSpotParams, float shadow) { -#if CAPTURING == 1 float lightfloor = CAPTURE_LIGHT_FLOOR; -#else - float lightfloor = 0.0; -#endif + if(isCapturing != 1) + lightfloor = 0.0; + float attenuation = 1.0f; attenuation *= getDistanceAtt(surfaceToLight.Lu, radius); attenuation *= getSpotAngleAtt(-surfaceToLight.L, lightDir, lightSpotParams.xy); @@ -567,11 +559,11 @@ vec4 computeForwardProbes(Surface surface, float horizonOcclusion = 1.3; float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); horizon *= horizon; -#if CAPTURING == 1 - return vec4(mix((irradiance + specular* horizon),surface.baseColor.rgb,surface.metalness),0); -#else - return vec4((irradiance + specular* horizon) , 0);//alpha writes disabled -#endif + + if(isCapturing == 1) + return vec4(mix((irradiance + specular* horizon),surface.baseColor.rgb,surface.metalness),0); + else + return vec4((irradiance + specular* horizon) , 0);//alpha writes disabled } vec4 debugVizForwardProbes(Surface surface, diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index 3ec490af1..c9e1fc512 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -27,6 +27,7 @@ //globals uniform float3 eyePosWorld; uniform float maxProbeDrawDistance; +uniform int isCapturing; #ifndef TORQUE_SHADERGEN // These are the uniforms used by most lighting shaders. @@ -56,10 +57,6 @@ uniform float4 albedo; #define MAX_FORWARD_LIGHT 4 -#ifndef CAPTURING -#define CAPTURING 0 -#endif - #ifndef DEBUGVIZ_ATTENUATION #define DEBUGVIZ_ATTENUATION 0 #endif @@ -238,32 +235,28 @@ float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight) float D = D_GGX(surfaceToLight.NdotH, surface.linearRoughnessSq); float3 Fr = D * F * Vis; -#if CAPTURING == 1 - return lerp(Fd + Fr,surface.baseColor.rgb,surface.metalness); -#else - return Fd + Fr; -#endif - + if(isCapturing == 1) + return lerp(Fd + Fr,surface.baseColor.rgb,surface.metalness); + else + return Fd + Fr; } float3 getDirectionalLight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow) { -#if CAPTURING == 1 float lightfloor = CAPTURE_LIGHT_FLOOR; -#else - float lightfloor = 0.0; -#endif + if(isCapturing != 1) + lightfloor = 0.0; + float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity, lightfloor) ; return evaluateStandardBRDF(surface,surfaceToLight) * factor; } float3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float radius, float shadow) { -#if CAPTURING == 1 float lightfloor = CAPTURE_LIGHT_FLOOR; -#else - float lightfloor = 0.0; -#endif + if(isCapturing != 1) + lightfloor = 0.0; + float attenuation = getDistanceAtt(surfaceToLight.Lu, radius); float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, lightfloor) ; return evaluateStandardBRDF(surface,surfaceToLight) * factor; @@ -271,11 +264,10 @@ float3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, float3 l float3 getSpotlight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float radius, float3 lightDir, float2 lightSpotParams, float shadow) { -#if CAPTURING == 1 float lightfloor = CAPTURE_LIGHT_FLOOR; -#else - float lightfloor = 0.0; -#endif + if(isCapturing != 1) + lightfloor = 0.0; + float attenuation = 1.0f; attenuation *= getDistanceAtt(surfaceToLight.Lu, radius); attenuation *= getSpotAngleAtt(-surfaceToLight.L, lightDir, lightSpotParams.xy); @@ -573,11 +565,11 @@ float4 computeForwardProbes(Surface surface, float horizonOcclusion = 1.3; float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); horizon *= horizon; -#if CAPTURING == 1 - return float4(lerp((irradiance + specular* horizon),surface.baseColor.rgb,surface.metalness),0); -#else - return float4((irradiance + specular* horizon) , 0);//alpha writes disabled -#endif + + if(isCapturing == 1) + return float4(lerp((irradiance + specular* horizon),surface.baseColor.rgb,surface.metalness),0); + else + return float4((irradiance + specular* horizon) , 0);//alpha writes disabled } float4 debugVizForwardProbes(Surface surface, diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl index 65ef21a22..1f6963c2c 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl @@ -222,9 +222,9 @@ void main() float horizonOcclusion = 1.3; float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); horizon *= horizon; -#if CAPTURING == 1 - OUT_col = vec4(mix((irradiance + specular* horizon),surface.baseColor.rgb, surface.metalness),0); -#else - OUT_col = vec4((irradiance + specular* horizon)*ambientColor, 0);//alpha writes disabled -#endif + + if(isCapturing == 1) + OUT_col = vec4(mix((irradiance + specular* horizon),surface.baseColor.rgb, surface.metalness),0); + else + OUT_col = vec4((irradiance + specular* horizon)*ambientColor, 0);//alpha writes disabled } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl index 4ec3df65d..845793a82 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl @@ -208,9 +208,9 @@ float4 main(PFXVertToPix IN) : SV_TARGET float horizonOcclusion = 1.3; float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); horizon *= horizon; -#if CAPTURING == 1 - return float4(lerp((irradiance + specular* horizon), surface.baseColor.rgb,surface.metalness),0); -#else - return float4((irradiance + specular* horizon)*ambientColor, 0);//alpha writes disabled -#endif + + if(isCapturing == 1) + return float4(lerp((irradiance + specular* horizon), surface.baseColor.rgb,surface.metalness),0); + else + return float4((irradiance + specular* horizon)*ambientColor, 0);//alpha writes disabled }