Merge pull request #1258 from Azaezel/alpha41/probePoke

shift capturing from a globalMacro to a sceneRenderstate S32
This commit is contained in:
Brian Roberts 2024-04-18 01:42:33 -05:00 committed by GitHub
commit e5aa6e4a95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 69 additions and 101 deletions

View file

@ -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;
}

View file

@ -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.
//

View file

@ -104,6 +104,7 @@ public:
GFXShaderConstHandle* mNodeTransforms;
GFXShaderConstHandle* mIsCapturingSC;
struct customHandleData
{
StringTableEntry handleName;

View file

@ -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() )
{

View file

@ -164,6 +164,8 @@ protected:
GFXShaderConstHandle *mMatCameraToScreenSC;
GFXShaderConstHandle *mMatScreenToCameraSC;
GFXShaderConstHandle* mIsCapturingSC;
bool mAllowReflectPass;
/// If true update the shader.

View file

@ -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)

View file

@ -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

View file

@ -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");

View file

@ -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;

View file

@ -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,

View file

@ -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,

View file

@ -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
}

View file

@ -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
}