From e28b6ae6de1fe551de05988e254ae69cecb032ff Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 14 Apr 2020 11:36:49 -0500 Subject: [PATCH 1/3] misc fixes to mitigate banding scriptside: 1) HDRPostFX::onEnabled needs to test vs GFXFormatR16G16B16A16F, as that's what's getting returned by getBestHDRFormat() 2) AL_FormatToken shifted to that same GFXFormatR16G16B16A16F target format 3) tangental but somewhat related, we were doubling up refposition offsets in the boxproject sourceside: tweaked the capture code for probes to ensure that the "screengrab" and output cubemap formats were identical --- Templates/BaseGame/game/core/postFX/scripts/HDRPostFX.cs | 2 +- Templates/BaseGame/game/core/rendering/scripts/renderManager.cs | 2 +- Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDRPostFX.cs b/Templates/BaseGame/game/core/postFX/scripts/HDRPostFX.cs index f74fbcd0c..f1e7932d7 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDRPostFX.cs +++ b/Templates/BaseGame/game/core/postFX/scripts/HDRPostFX.cs @@ -287,7 +287,7 @@ function HDRPostFX::onEnabled( %this ) // Set the right global shader define for HDR. if ( %format $= "GFXFormatR10G10B10A2" ) addGlobalShaderMacro( "TORQUE_HDR_RGB10" ); - else if ( %format $= "GFXFormatR16G16B16A16" ) + else if ( %format $= "GFXFormatR16G16B16A16F" ) addGlobalShaderMacro( "TORQUE_HDR_RGB16" ); echo( "HDR FORMAT: " @ %format ); diff --git a/Templates/BaseGame/game/core/rendering/scripts/renderManager.cs b/Templates/BaseGame/game/core/rendering/scripts/renderManager.cs index 8a0a8adea..07b4f08a6 100644 --- a/Templates/BaseGame/game/core/rendering/scripts/renderManager.cs +++ b/Templates/BaseGame/game/core/rendering/scripts/renderManager.cs @@ -34,7 +34,7 @@ function initRenderManager() enabled = "false"; //When hdr is enabled this will be changed to the appropriate format - format = "GFXFormatR8G8B8A8_SRGB"; + format = "GFXFormatR16G16B16A16F"; depthFormat = "GFXFormatD24S8"; aaLevel = 0; // -1 = match backbuffer diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index 870756628..35dd834a0 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -377,7 +377,7 @@ float3 boxProject(float3 wsPosition, float3 wsReflectVec, float4x4 worldToObj, f float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z); float3 posonbox = wsPosition + wsReflectVec * dist; - return posonbox - refPosition.xyz; + return posonbox; } float4 computeForwardProbes(Surface surface, From 1a33d483a3a792b82d9e44b188aca544451a07ba Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 14 Apr 2020 12:40:31 -0500 Subject: [PATCH 2/3] ensure we've got a known stateblock set for GeneratePrefilterMap --- Engine/source/T3D/lighting/IBLUtilities.cpp | 14 ++++++++++++ .../source/renderInstance/renderProbeMgr.cpp | 22 ++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Engine/source/T3D/lighting/IBLUtilities.cpp b/Engine/source/T3D/lighting/IBLUtilities.cpp index b66838778..6945c6b80 100644 --- a/Engine/source/T3D/lighting/IBLUtilities.cpp +++ b/Engine/source/T3D/lighting/IBLUtilities.cpp @@ -138,6 +138,20 @@ namespace IBLUtilities GFXShaderConstHandle* prefilterMipSizeSC = prefilterShader->getShaderConstHandle("$mipSize"); GFXShaderConstHandle* prefilterResolutionSC = prefilterShader->getShaderConstHandle("$resolution"); + GFXStateBlockDesc desc; + desc.zEnable = false; + desc.samplersDefined = true; + desc.samplers[0].addressModeU = GFXAddressClamp; + desc.samplers[0].addressModeV = GFXAddressClamp; + desc.samplers[0].addressModeW = GFXAddressClamp; + desc.samplers[0].magFilter = GFXTextureFilterLinear; + desc.samplers[0].minFilter = GFXTextureFilterLinear; + desc.samplers[0].mipFilter = GFXTextureFilterLinear; + + GFXStateBlockRef preStateBlock; + preStateBlock = GFX->createStateBlock(desc); + GFX->setStateBlock(preStateBlock); + GFX->pushActiveRenderTarget(); GFX->setShader(prefilterShader); GFX->setShaderConstBuffer(prefilterConsts); diff --git a/Engine/source/renderInstance/renderProbeMgr.cpp b/Engine/source/renderInstance/renderProbeMgr.cpp index 4d7bf39c7..322e9397f 100644 --- a/Engine/source/renderInstance/renderProbeMgr.cpp +++ b/Engine/source/renderInstance/renderProbeMgr.cpp @@ -36,6 +36,7 @@ #include "materials/shaderData.h" #include "gfx/gfxTextureManager.h" +#include "scene/reflectionManager.h" #include "postFx/postEffect.h" #include "T3D/lighting/reflectionProbe.h" @@ -919,6 +920,14 @@ void RenderProbeMgr::bakeProbe(ReflectionProbe *probe) if (!renderWithProbes) RenderProbeMgr::smRenderReflectionProbes = false; + GFXFormat reflectFormat; + + if (clientProbe->mUseHDRCaptures) + reflectFormat = GFXFormatR16G16B16A16F; + else + reflectFormat = GFXFormatR8G8B8A8; + const GFXFormat oldRefFmt = REFLECTMGR->getReflectFormat(); + REFLECTMGR->setReflectFormat(reflectFormat); cubeRefl.updateReflection(reflParams); //Now, save out the maps @@ -929,16 +938,8 @@ void RenderProbeMgr::bakeProbe(ReflectionProbe *probe) clientProbe->createClientResources(); //Prep it with whatever resolution we've dictated for our bake - if (clientProbe->mUseHDRCaptures) - { - clientProbe->mIrridianceMap->mCubemap->initDynamic(resolution, GFXFormatR16G16B16A16F); - clientProbe->mPrefilterMap->mCubemap->initDynamic(resolution, GFXFormatR16G16B16A16F); - } - else - { - clientProbe->mIrridianceMap->mCubemap->initDynamic(resolution, GFXFormatR8G8B8A8); - clientProbe->mPrefilterMap->mCubemap->initDynamic(resolution, GFXFormatR8G8B8A8); - } + clientProbe->mIrridianceMap->mCubemap->initDynamic(resolution, reflectFormat); + clientProbe->mPrefilterMap->mCubemap->initDynamic(resolution, reflectFormat); GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false); @@ -969,6 +970,7 @@ void RenderProbeMgr::bakeProbe(ReflectionProbe *probe) probe->setMaskBits(-1); Con::warnf("RenderProbeMgr::bake() - Finished bake! Took %g milliseconds", diffTime); + REFLECTMGR->setReflectFormat(oldRefFmt); } void RenderProbeMgr::bakeProbes() From d15780b0cb3589b26abd079089e7cb3ed32bed2d Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 14 Apr 2020 15:00:29 -0500 Subject: [PATCH 3/3] we do actually need to account for reference position (of the capture box) to avoid it trying to look up the cube face relative to world origin... will need to eyeball what's going on backend wise forcing additional position-offsetting... --- Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index 35dd834a0..cfb89bf8a 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -377,7 +377,7 @@ float3 boxProject(float3 wsPosition, float3 wsReflectVec, float4x4 worldToObj, f float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z); float3 posonbox = wsPosition + wsReflectVec * dist; - return posonbox; + return posonbox-refPosition; } float4 computeForwardProbes(Surface surface,