Skip to content

Commit

Permalink
refactor(HLSL): create namespaces for rest of hlsli (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN authored Nov 19, 2024
1 parent 2d3e962 commit 7543111
Show file tree
Hide file tree
Showing 22 changed files with 914 additions and 1,008 deletions.
16 changes: 8 additions & 8 deletions features/Skylighting/Shaders/Skylighting/Skylighting.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ namespace Skylighting
float w = trilinearWeights.x * trilinearWeights.y * trilinearWeights.z * tangentWeight;

uint3 cellTexID = (cellID + params.ArrayOrigin.xyz) % ARRAY_DIM;
sh2 probe = shScale(probeArray[cellTexID], w);
sh2 probe = SphericalHarmonics::Scale(probeArray[cellTexID], w);

sum = shAdd(sum, probe);
sum = SphericalHarmonics::Add(sum, probe);
wsum += w;
}

return shScale(sum, rcp(wsum + 1e-10));
return SphericalHarmonics::Scale(sum, rcp(wsum + 1e-10));
}

float getVL(SkylightingSettings params, Texture3D<sh2> probeArray, float3 startPosWS, float3 endPosWS, float2 pxCoord)
Expand All @@ -102,7 +102,7 @@ namespace Skylighting

sh2 skylighting = Skylighting::sample(params, probeArray, samplePositionWS, float3(0, 0, 1));

shadow += Skylighting::mixDiffuse(params, shUnproject(skylighting, worldDirNormalised));
shadow += Skylighting::mixDiffuse(params, SphericalHarmonics::Unproject(skylighting, worldDirNormalised));
}
vl += shadow;
}
Expand All @@ -123,10 +123,10 @@ namespace Skylighting
float roughness2 = roughness * roughness;
float halfAngle = clamp(4.1679 * roughness2 * roughness2 - 9.0127 * roughness2 * roughness + 4.6161 * roughness2 + 1.7048 * roughness + 0.1, 0, Math::HALF_PI);
float lerpFactor = halfAngle / Math::HALF_PI;
sh2 directional = shEvaluate(dominantDir);
sh2 cosineLobe = shEvaluateCosineLobe(dominantDir) / Math::PI;
sh2 result = shAdd(shScale(directional, lerpFactor), shScale(cosineLobe, 1 - lerpFactor));
sh2 directional = SphericalHarmonics::Evaluate(dominantDir);
sh2 cosineLobe = SphericalHarmonics::EvaluateCosineLobe(dominantDir) / Math::PI;
sh2 result = SphericalHarmonics::Add(SphericalHarmonics::Scale(directional, lerpFactor), SphericalHarmonics::Scale(cosineLobe, 1 - lerpFactor));

return result;
}
}
}
4 changes: 2 additions & 2 deletions features/Skylighting/Shaders/Skylighting/UpdateProbesCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ SamplerState samplerPointClamp : register(s0);
float occlusionDepth = srcOcclusionDepth.SampleLevel(samplerPointClamp, occlusionUV, 0);
float visibility = saturate((occlusionDepth + 0.0005 - cellCentreOS.z) * 1024);

sh2 occlusionSH = shScale(shEvaluate(settings.OcclusionDir.xyz), visibility * 4.0 * Math::PI); // 4 pi from monte carlo
sh2 occlusionSH = SphericalHarmonics::Scale(SphericalHarmonics::Evaluate(settings.OcclusionDir.xyz), visibility * 4.0 * Math::PI); // 4 pi from monte carlo
if (isValid) {
float lerpFactor = rcp(accumFrames);
sh2 prevProbeSH = unitSH;
if (accumFrames > 1)
prevProbeSH += (outProbeArray[dtid] - unitSH) * fadeInThreshold / min(fadeInThreshold, accumFrames - 1); // inverse confidence
occlusionSH = shAdd(shScale(prevProbeSH, 1 - lerpFactor), shScale(occlusionSH, lerpFactor));
occlusionSH = SphericalHarmonics::Add(SphericalHarmonics::Scale(prevProbeSH, 1 - lerpFactor), SphericalHarmonics::Scale(occlusionSH, lerpFactor));
}
occlusionSH = lerp(unitSH, occlusionSH, min(fadeInThreshold, accumFrames) / fadeInThreshold); // confidence fade in

Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/AmbientCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RWTexture2D<half3> DiffuseAmbientRW : register(u1);
# endif

sh2 skylighting = Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMS.xyz, normalWS);
half skylightingDiffuse = shFuncProductIntegral(skylighting, shEvaluateCosineLobe(float3(normalWS.xy, normalWS.z * 0.5 + 0.5))) / Math::PI;
half skylightingDiffuse = SphericalHarmonics::FuncProductIntegral(skylighting, SphericalHarmonics::EvaluateCosineLobe(float3(normalWS.xy, normalWS.z * 0.5 + 0.5))) / Math::PI;
skylightingDiffuse = Skylighting::mixDiffuse(skylightingSettings, skylightingDiffuse);

visibility = skylightingDiffuse;
Expand Down
150 changes: 0 additions & 150 deletions package/Shaders/Common/DICETonemapper.hlsli

This file was deleted.

Loading

0 comments on commit 7543111

Please sign in to comment.