Add DDGI reflections to transparent materials

This commit is contained in:
2026-07-21 13:25:09 +02:00
parent 8a5ff58b9e
commit b6204ceb76
9 changed files with 28 additions and 13 deletions
@@ -112,12 +112,17 @@ void PS_Forward(
// Calculate lighting from Global Illumination
#if USE_GI
light += GetGlobalIlluminationLighting(gBuffer);
// TODO: when using both indirect and specular lighting from DDGI, merge cascade selection and probes visibility resolving to be done once
#endif
// Calculate reflections
#if USE_REFLECTIONS
float4 reflections = SampleReflectionProbe(ViewPos, EnvProbe, EnvironmentProbe, gBuffer.WorldPos, gBuffer.Normal, gBuffer.Roughness);
reflections.rgb *= reflections.a;
float4 reflectionsProbe = SampleReflectionProbe(ViewPos, EnvProbe, EnvironmentProbe, gBuffer.WorldPos, gBuffer.Normal, gBuffer.Roughness);
float3 reflections = reflectionsProbe.rgb * reflectionsProbe.a;
#if USE_GI
float4 reflectionsGI = GetGlobalIlluminationSpecular(gBuffer);
reflections = lerp(reflections, reflectionsGI.rgb, reflectionsGI.a);
#endif
#if MATERIAL_REFLECTIONS == MATERIAL_REFLECTIONS_SSR
// Screen Space Reflections
@@ -133,7 +138,7 @@ void PS_Forward(
if (hit.z > 0)
{
float3 screenColor = sceneColorTexture.SampleLevel(SamplerPointClamp, hit.xy, 0).rgb;
reflections.rgb = lerp(reflections.rgb, screenColor, hit.z);
reflections = lerp(reflections, screenColor, hit.z);
}
// Fallback to software tracing if possible
@@ -145,18 +150,17 @@ void PS_Forward(
if (TraceSDFSoftwareReflections(gBuffer, reflectWS, surfaceAtlas))
{
float3 screenColor = sceneColorTexture.SampleLevel(SamplerPointClamp, hit.xy, 0).rgb;
reflections.rgb = lerp(surfaceAtlas, float4(screenColor, 1), hit.z);
reflections = lerp(surfaceAtlas, float4(screenColor, 1), hit.z);
}
}
#endif
#endif
light.rgb += reflections.rgb * GetReflectionSpecularLighting(PreIntegratedGF, ViewPos, gBuffer);
light.rgb += reflections * GetReflectionSpecularLighting(PreIntegratedGF, ViewPos, gBuffer);
#endif
// Add lighting
output.rgb += light.rgb;
#endif
#if USE_FOG && MATERIAL_SHADING_MODEL != SHADING_MODEL_UNLIT
@@ -8,16 +8,24 @@
@2// Global Illumination: Constants
DDGIData DDGI;
@3// Global Illumination: Resources
Texture2D<snorm float4> ProbesState : register(t__SRV__);
Texture2D<snorm float4> ProbesData : register(t__SRV__);
Texture2D<float4> ProbesDistance : register(t__SRV__);
Texture2D<float4> ProbesIrradiance : register(t__SRV__);
Texture2D<float4> ProbesRadiance : register(t__SRV__);
@4// Global Illumination: Utilities
float4 GetGlobalIlluminationLighting(GBufferSample gBuffer)
{
float3 irradiance = SampleDDGIIrradiance(DDGI, ProbesState, ProbesDistance, ProbesIrradiance, gBuffer.WorldPos, gBuffer.Normal);
float3 irradiance = SampleDDGIIrradiance(DDGI, ProbesData, ProbesDistance, ProbesIrradiance, gBuffer.WorldPos, gBuffer.Normal);
float3 diffuseColor = GetDiffuseColor(gBuffer);
float3 diffuse = Diffuse_Lambert(diffuseColor);
return float4(diffuse * irradiance, saturate(length(irradiance)));
}
float4 GetGlobalIlluminationSpecular(GBufferSample gBuffer)
{
float3 specular = SampleDDGISpecular(DDGI, ProbesData, ProbesDistance, ProbesRadiance, gBuffer.WorldPos, gBuffer.Normal, gBuffer.Roughness);
float useRadiance = DDGI.BlendOrigin[0].w; // 1 or 0
return float4(specular, useRadiance);
}
@5// Global Illumination: Shaders
+1 -1
View File
@@ -4,7 +4,7 @@
"Major": 1,
"Minor": 13,
"Revision": 0,
"Build": 7007
"Build": 7008
},
"Company": "Flax",
"Copyright": "Copyright (c) 2012-2026 Wojciech Figat. All rights reserved.",
@@ -10,7 +10,7 @@
/// <summary>
/// Current materials shader version.
/// </summary>
#define MATERIAL_GRAPH_VERSION 184
#define MATERIAL_GRAPH_VERSION 185
class Material;
class GPUShader;
@@ -172,6 +172,7 @@ bool GlobalIlluminationFeature::Bind(MaterialShader::BindParameters& params, Spa
params.GPUContext->BindSR(srv + 0, bindingDataDDGI.ProbesData);
params.GPUContext->BindSR(srv + 1, bindingDataDDGI.ProbesDistance);
params.GPUContext->BindSR(srv + 2, bindingDataDDGI.ProbesIrradiance);
params.GPUContext->BindSR(srv + 3, bindingDataDDGI.ProbesRadiance);
}
break;
}
@@ -185,6 +186,7 @@ bool GlobalIlluminationFeature::Bind(MaterialShader::BindParameters& params, Spa
params.GPUContext->UnBindSR(srv + 0);
params.GPUContext->UnBindSR(srv + 1);
params.GPUContext->UnBindSR(srv + 2);
params.GPUContext->UnBindSR(srv + 3);
}
cb = cb.Slice(sizeof(Data));
@@ -73,7 +73,7 @@ struct LightmapFeature : MaterialShaderFeature
// Material shader feature that adds Global Illumination sampling feature (light probes).
struct GlobalIlluminationFeature : MaterialShaderFeature
{
enum { SRVs = 3 };
enum { SRVs = 4 };
PACK_STRUCT(struct Data {
DynamicDiffuseGlobalIlluminationPass::ConstantsData DDGI;
@@ -648,6 +648,7 @@ bool DynamicDiffuseGlobalIlluminationPass::RenderInner(RenderContext& renderCont
ddgiData.Result.Constants.BlendOrigin[cascadeIndex] = Float4(blendOrigins[cascadeIndex], 0.0f);
ddgiData.Result.Constants.ProbesScrollOffsets[cascadeIndex] = Int4(cascade.ProbeScrollOffsets, 0);
}
ddgiData.Result.Constants.BlendOrigin[0].W = ddgiData.ProbesRadiance ? 1.0f : 0.0f; // Use radiance flag
ddgiData.Result.Constants.RayMaxDistance = distance;
ddgiData.Result.Constants.ViewPos = renderContext.View.Position;
ddgiData.Result.Constants.RaysCount = probeRaysCount;
@@ -15,7 +15,7 @@ public:
// Constant buffer data for DDGI access on a GPU.
GPU_CB_STRUCT(ConstantsData {
Float4 ProbesOriginAndSpacing[4];
Float4 BlendOrigin[4]; // w is unused
Float4 BlendOrigin[4]; // [0] w is flag for specular usage, [1-3] w is unused
Int4 ProbesScrollOffsets[4]; // w is unused
uint32 ProbesCounts[3];
uint32 CascadesCount;
+1 -1
View File
@@ -38,7 +38,7 @@
struct DDGIData
{
float4 ProbesOriginAndSpacing[4];
float4 BlendOrigin[4]; // w is unused
float4 BlendOrigin[4]; // [0] w is flag for specular usage, [1-3] w is unused
int4 ProbesScrollOffsets[4]; // w is unused
uint3 ProbesCounts;
uint CascadesCount;