Initial commit for forward software reflection

This commit is contained in:
ExMatics HydrogenC
2024-06-17 23:00:48 +08:00
parent 2676daabf1
commit 5f939430ee
4 changed files with 62 additions and 4 deletions

View File

@@ -178,6 +178,7 @@ bool ForwardMaterialShader::Load()
psDesc.VS = _shader->GetVS("VS");
if (psDesc.VS == nullptr)
return true;
psDesc.PS = _shader->GetPS("PS_Forward");
psDesc.DepthWriteEnable = false;
psDesc.BlendMode = BlendingMode::AlphaBlend;

View File

@@ -5,6 +5,7 @@
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Renderer/ShadowsPass.h"
#include "Engine/Renderer/GlobalSignDistanceFieldPass.h"
#if USE_EDITOR
#include "Engine/Renderer/Lightmaps.h"
#endif
@@ -22,6 +23,8 @@ void ForwardShadingFeature::Bind(MaterialShader::BindParameters& params, Span<by
const int32 envProbeShaderRegisterIndex = srv + 0;
const int32 skyLightShaderRegisterIndex = srv + 1;
const int32 dirLightShaderRegisterIndex = srv + 2;
const int32 surfaceAtlasDepthShaderRegisterIndex = srv + 3;
const int32 surfaceAtlasTexShaderRegisterIndex = srv + 4;
const bool canUseShadow = view.Pass != DrawPass::Depth;
// Set fog input
@@ -97,6 +100,15 @@ void ForwardShadingFeature::Bind(MaterialShader::BindParameters& params, Span<by
params.GPUContext->UnBindSR(envProbeShaderRegisterIndex);
}
// Bind sdf resources if using software reflections
if (!GlobalSignDistanceFieldPass::Instance()->Render(params.RenderContext, params.GPUContext, bindingDataSDF) &&
!GlobalSurfaceAtlasPass::Instance()->Render(params.RenderContext, params.GPUContext, bindingDataSurfaceAtlas))
{
useGlobalSurfaceAtlas = true;
data.GlobalSDF = bindingDataSDF.Constants;
data.GlobalSurfaceAtlas = bindingDataSurfaceAtlas.Constants;
}
// Set local lights
data.LocalLightsCount = 0;
const BoundingSphere objectBounds(drawCall.ObjectPosition, drawCall.ObjectRadius);

View File

@@ -133,11 +133,12 @@ float4 PS_RayTracePass(Quad_VS2PS input) : SV_Target0
return result;
}
// Calculate reflection direction (the same TraceScreenSpaceReflection)
float3 reflectWS = ScreenSpaceReflectionDirection(input.TexCoord, gBuffer, gBufferData.ViewPos, TemporalEffect, TemporalTime, BRDFBias);
// Fallback to Global SDF and Global Surface Atlas tracing
#if USE_GLOBAL_SURFACE_ATLAS && CAN_USE_GLOBAL_SURFACE_ATLAS
// Calculate reflection direction (the same TraceScreenSpaceReflection)
float3 reflectWS = ScreenSpaceReflectionDirection(input.TexCoord, gBuffer, gBufferData.ViewPos, TemporalEffect, TemporalTime, BRDFBias);
GlobalSDFTrace sdfTrace;
float maxDistance = 100000;
float selfOcclusionBias = GlobalSDF.CascadeVoxelSize[0];
@@ -148,7 +149,9 @@ float4 PS_RayTracePass(Quad_VS2PS input) : SV_Target0
float3 hitPosition = sdfHit.GetHitPosition(sdfTrace);
float surfaceThreshold = GetGlobalSurfaceAtlasThreshold(GlobalSDF, sdfHit);
float4 surfaceAtlas = SampleGlobalSurfaceAtlas(GlobalSurfaceAtlas, GlobalSurfaceAtlasChunks, RWGlobalSurfaceAtlasCulledObjects, GlobalSurfaceAtlasObjects, GlobalSurfaceAtlasDepth, GlobalSurfaceAtlasTex, hitPosition, -reflectWS, surfaceThreshold);
result = lerp(surfaceAtlas, float4(result.rgb, 1), result.a);
// Now the sdf reflection part is significantly darker than the screen space part
// TODO: Maybe multiply surfaceAtlas by a constant to make it brighter
result = lerp(surfaceAtlas, float4(result.rgb, 1), result.a);
}
#endif