Code style cleanup

#3250
This commit is contained in:
Wojtek Figat
2025-03-08 20:18:38 +01:00
parent f7c6d34f59
commit 4c9d51f0ef
5 changed files with 216 additions and 240 deletions

View File

@@ -48,7 +48,6 @@ void BloomSettings::BlendWith(BloomSettings& other, float weight)
BLEND_FLOAT(HighMix);
}
void ToneMappingSettings::BlendWith(ToneMappingSettings& other, float weight)
{
const bool isHalf = weight >= 0.5f;

File diff suppressed because it is too large Load Diff

View File

@@ -83,7 +83,6 @@ bool PostProcessingPass::setupResources()
if (_psBloomDownsample->Init(psDesc))
return true;
}
if (!_psBloomDualFilterUpsample->IsValid())
{
psDesc.PS = shader->GetPS("PS_BloomDualFilterUpsample");
@@ -189,7 +188,7 @@ void PostProcessingPass::Dispose()
_defaultLensStar = nullptr;
}
float CalculateBloomMipCount(int32 width, int32 height)
int32 CalculateBloomMipCount(int32 width, int32 height)
{
// Calculate the smallest dimension
int32 minDimension = Math::Min(width, height);
@@ -197,14 +196,12 @@ float CalculateBloomMipCount(int32 width, int32 height)
// Calculate how many times we can half the dimension until we hit a minimum size
// (e.g., 16x16 pixels as the smallest mip)
const int32 MIN_MIP_SIZE = 16;
float mipCount = 1.0f;
while (minDimension > MIN_MIP_SIZE) {
int32 mipCount = 1;
while (minDimension > MIN_MIP_SIZE)
{
minDimension /= 2;
mipCount += 1.0f;
mipCount++;
}
return mipCount;
}
@@ -282,7 +279,7 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
data.BloomThresholdKnee = settings.Bloom.ThresholdKnee;
data.BloomBaseMix = settings.Bloom.BaseMix;
data.BloomHighMix = settings.Bloom.HighMix;
data.BloomMipCount = bloomMipCount;
data.BloomMipCount = (float)bloomMipCount;
data.BloomLayer = 0.0f;
}
else
@@ -333,7 +330,6 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
////////////////////////////////////////////////////////////////////////////////////
// Bloom
auto tempDesc = GPUTextureDescription::New2D(w2, h2, bloomMipCount, output->Format(), GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget | GPUTextureFlags::PerMipViews);
auto bloomBuffer1 = RenderTargetPool::Get(tempDesc);
RENDER_TARGET_POOL_SET_NAME(bloomBuffer1, "PostProcessing.Bloom");
@@ -346,10 +342,8 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
context->Clear(bloomBuffer2->View(0, mip), Color::Transparent);
}
// Check if use bloom
if (useBloom)
{
context->SetRenderTarget(bloomBuffer1->View(0, 0));
context->SetViewportAndScissors((float)w2, (float)h2);
context->BindSR(0, input->View());
@@ -360,47 +354,44 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
// Progressive downsamples
for (int32 mip = 1; mip < bloomMipCount; mip++)
{
const float mipWidth = w2 >> mip;
const float mipHeight = h2 >> mip;
const int32 mipWidth = w2 >> mip;
const int32 mipHeight = h2 >> mip;
context->SetRenderTarget(bloomBuffer1->View(0, mip));
context->SetViewportAndScissors(mipWidth, mipHeight);
context->SetViewportAndScissors((float)mipWidth, (float)mipHeight);
context->BindSR(0, bloomBuffer1->View(0, mip - 1));
context->SetState(_psBloomDownsample);
context->DrawFullscreenTriangle();
context->ResetRenderTarget();
}
// Progressive upsamples
for (int32 mip = bloomMipCount - 2; mip >= 0; mip--)
{
auto upscalebuffer = bloomBuffer2;
auto upscaleBuffer = bloomBuffer2;
if (mip == bloomMipCount - 2)
{
// if it's the first, copy the chain over.
upscalebuffer = bloomBuffer1;
// If it's the first, copy the chain over
upscaleBuffer = bloomBuffer1;
}
const int32 mipWidth = w2 >> mip;
const int32 mipHeight = h2 >> mip;
const float mipWidth = w2 >> mip;
const float mipHeight = h2 >> mip;
data.BloomLayer = static_cast<float>(mip); // Set the current mip as bloom layer
context->UpdateCB(cb0, &data); // Update the constant buffer
data.BloomLayer = static_cast<float>(mip);
context->UpdateCB(cb0, &data);
context->SetRenderTarget(bloomBuffer2->View(0, mip));
context->SetViewportAndScissors(mipWidth, mipHeight);
context->BindSR(0, upscalebuffer->View(0, mip + 1));
context->SetViewportAndScissors((float)mipWidth, (float)mipHeight);
context->BindSR(0, upscaleBuffer->View(0, mip + 1));
context->BindSR(1, bloomBuffer1->View(0, mip + 1));
context->SetState(_psBloomDualFilterUpsample);
context->DrawFullscreenTriangle();
context->ResetRenderTarget();
}
// Final composite
context->BindSR(1, bloomBuffer1);
context->BindSR(2, bloomBuffer2);
// Set bloom output
context->UnBindSR(0);
context->UnBindSR(1);
context->BindSR(2, bloomBuffer2->View(0, 0));
}
else
{
@@ -408,8 +399,7 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
}
////////////////////////////////////////////////////////////////////////////////////
//Lens Flares
// Lens Flares
// Check if use lens flares
if (useLensFlares)
@@ -418,8 +408,6 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
context->BindSR(5, getCustomOrDefault(settings.LensFlares.LensStar, _defaultLensStar, TEXT("Engine/Textures/DefaultLensStarburst")));
context->BindSR(6, getCustomOrDefault(settings.LensFlares.LensColor, _defaultLensColor, TEXT("Engine/Textures/DefaultLensColor")));
// use bloomBuffer1's mip 1 as input for lens flares
// Render lens flares
context->SetRenderTarget(bloomBuffer2->View(0, 1));
context->SetViewportAndScissors((float)w4, (float)h4);

View File

@@ -16,16 +16,16 @@ class PostProcessingPass : public RendererPass<PostProcessingPass>
private:
GPU_CB_STRUCT(Data{
float BloomIntensity; // Overall bloom strength multiplier
float BloomClamp; // Maximum brightness limit for bloom
float BloomThreshold; // Luminance threshold where bloom begins
float BloomThresholdKnee; // Controls the threshold rolloff curve
float BloomBaseMix; // Base mip contribution
float BloomHighMix; // High mip contribution
float BloomIntensity; // Overall bloom strength multiplier
float BloomClamp; // Maximum brightness limit for bloom
float BloomThreshold; // Luminance threshold where bloom begins
float BloomThresholdKnee; // Controls the threshold rolloff curve
float BloomBaseMix; // Base mip contribution
float BloomHighMix; // High mip contribution
float BloomMipCount;
float BloomLayer;
Float3 VignetteColor;
float VignetteShapeFactor;

View File

@@ -36,7 +36,6 @@
META_CB_BEGIN(0, Data)
// Bloom parameters
float BloomIntensity;
float BloomClamp;
float BloomThreshold;
@@ -47,7 +46,6 @@ float BloomHighMix;
float BloomMipCount;
float BloomLayer;
float3 VignetteColor;
float VignetteShapeFactor;
@@ -260,7 +258,6 @@ float2 coordRot(in float2 tc, in float angle)
}
// Uses a lower exposure to produce a value suitable for a bloom pass
META_PS(true, FEATURE_LEVEL_ES2)
float4 PS_BloomBrightPass(Quad_VS2PS input) : SV_Target
{
@@ -278,10 +275,11 @@ float4 PS_BloomBrightPass(Quad_VS2PS input) : SV_Target
// Apply Karis average to prevent bright pixels from dominating
float centerLuma = max(dot(center, float3(0.2126, 0.7152, 0.0722)), 0.0001);
center = center / (1.0 + centerLuma);
float centerWeight = 4.0;
color += center * centerWeight;
totalWeight += centerWeight;
// Inner ring - fixed offset at 1.0 texel distance
UNROLL
for (int i = 0; i < 4; i++)
@@ -293,11 +291,12 @@ float4 PS_BloomBrightPass(Quad_VS2PS input) : SV_Target
// Apply Karis average
float sampleLuma = max(dot(sample, float3(0.2126, 0.7152, 0.0722)), 0.0001);
sample = sample / (1.0 + sampleLuma);
float weight = 2.0;
color += sample * weight;
totalWeight += weight;
}
// Outer ring - fixed offset at 1.4142 texel distance (diagonal)
UNROLL
for (int j = 0; j < 8; j++)
@@ -305,11 +304,11 @@ float4 PS_BloomBrightPass(Quad_VS2PS input) : SV_Target
float angle = j * (PI / 4.0);
float2 offset = float2(cos(angle), sin(angle)) * texelSize * 1.4142;
float3 sample = Input0.Sample(SamplerLinearClamp, input.TexCoord + offset).rgb;
// Apply Karis average
float sampleLuma = max(dot(sample, float3(0.2126, 0.7152, 0.0722)), 0.0001);
sample = sample / (1.0 + sampleLuma);
float weight = 1.0;
color += sample * weight;
totalWeight += weight;
@@ -320,24 +319,28 @@ float4 PS_BloomBrightPass(Quad_VS2PS input) : SV_Target
float finalLuma = max(dot(color, float3(0.2126, 0.7152, 0.0722)), 0.0001);
color = color * (1.0 + finalLuma);
// Apply threshold with quadratic rolloff for smoother transition
// Apply threshold with quadratic rolloff for smoother transition
float luminance = dot(color, float3(0.2126, 0.7152, 0.0722));
float threshold = max(BloomThreshold, 0.2);
float knee = threshold * BloomThresholdKnee;
float soft_max = threshold + knee;
float softMax = threshold + knee;
float contribution = 0;
if (luminance > threshold) {
if (luminance < soft_max) {
if (luminance > threshold)
{
if (luminance < softMax)
{
// Quadratic softening between threshold and (threshold + knee)
float x = (luminance - threshold) / knee;
contribution = x * x * 0.5;
} else {
// Full contribution above soft_max
}
else
{
// Full contribution above softMax
contribution = luminance - threshold;
}
}
float testc = BloomClamp;
float3 clamped = (color * contribution);
clamped.r = min(clamped.r, testc);
@@ -360,7 +363,8 @@ float4 PS_BloomDownsample(Quad_VS2PS input) : SV_Target
float totalWeight = 0;
// Sample offsets (fixed)
const float2 offsets[9] = {
const float2 offsets[9] =
{
float2( 0, 0), // Center
float2(-1, -1), // Corners
float2( 1, -1),
@@ -373,7 +377,8 @@ float4 PS_BloomDownsample(Quad_VS2PS input) : SV_Target
};
// Sample weights (fixed)
const float weights[9] = {
const float weights[9] =
{
4.0, // Center
1.0, // Corners
1.0,
@@ -401,11 +406,10 @@ META_PS(true, FEATURE_LEVEL_ES2)
float4 PS_BloomDualFilterUpsample(Quad_VS2PS input) : SV_Target
{
float anisotropy = 1.0;
uint width, height;
Input0.GetDimensions(width, height);
float2 texelSize = 1.0 / float2(width, height);
// Maintain fixed scale through mip chain
float baseOffset = 1.0;
float offsetScale = (1.0) * baseOffset;
@@ -436,7 +440,8 @@ float4 PS_BloomDualFilterUpsample(Quad_VS2PS input) : SV_Target
}
// Corners - fixed distance samples
float2 cornerOffsets[4] = {
float2 cornerOffsets[4] =
{
float2(offsetScale * anisotropy, offsetScale),
float2(-offsetScale * anisotropy, offsetScale),
float2(offsetScale * anisotropy, -offsetScale),
@@ -451,12 +456,12 @@ float4 PS_BloomDualFilterUpsample(Quad_VS2PS input) : SV_Target
color += sample.rgb * weight;
totalWeight += weight;
}
color /= totalWeight;
uint width1, height1;
Input1.GetDimensions(width1, height1);
// Calculate mip fade factor (0 = smallest mip, 1 = largest mip)
float mipFade = BloomLayer / (BloomMipCount - 1);
@@ -476,24 +481,20 @@ float4 PS_BloomDualFilterUpsample(Quad_VS2PS input) : SV_Target
float3 previousMip = Input1.Sample(SamplerLinearClamp, input.TexCoord).rgb;
color += previousMip;
}
return float4(color, 1.0);
}
// Horizontal gaussian blur
META_PS(true, FEATURE_LEVEL_ES2)
float4 PS_GaussainBlurH(Quad_VS2PS input) : SV_Target
{
float4 color = 0;
UNROLL
for (int i = 0; i < GB_KERNEL_SIZE; i++)
{
color += Input0.Sample(SamplerLinearClamp, input.TexCoord + float2(GaussianBlurCache[i].y, 0.0)) * GaussianBlurCache[i].x;
}
return color;
}
@@ -502,18 +503,14 @@ META_PS(true, FEATURE_LEVEL_ES2)
float4 PS_GaussainBlurV(Quad_VS2PS input) : SV_Target
{
float4 color = 0;
UNROLL
for (int i = 0; i < GB_KERNEL_SIZE; i++)
{
color += Input0.Sample(SamplerLinearClamp, input.TexCoord + float2(0.0, GaussianBlurCache[i].y)) * GaussianBlurCache[i].x;
}
return color;
}
// Generate 'ghosts' for lens flare
META_PS(true, FEATURE_LEVEL_ES2)
float4 PS_Ghosts(Quad_VS2PS input) : SV_Target
@@ -553,8 +550,7 @@ float4 PS_Ghosts(Quad_VS2PS input) : SV_Target
Input3.Sample(SamplerLinearClamp, offset + ghostVecnNorm * distortion.r).r,
Input3.Sample(SamplerLinearClamp, offset + ghostVecnNorm * distortion.g).g,
Input3.Sample(SamplerLinearClamp, offset + ghostVecnNorm * distortion.b).b);
color = clamp((color * 1.0f) + LensBias, 0, 10) * (LensScale * weight);
color = clamp(color + LensBias, 0, 10) * (LensScale * weight);
// Accumulate color
result += color;
@@ -610,8 +606,6 @@ float nrand(float2 n)
return frac(sin(dot(n.xy, float2(12.9898, 78.233)))* 43758.5453);
}
// Applies exposure, color grading and tone mapping to the input.
// Combines it with the results of the bloom pass and other postFx.
META_PS(true, FEATURE_LEVEL_ES2)
@@ -658,8 +652,7 @@ float4 PS_Composite(Quad_VS2PS input) : SV_Target
color = Input0.Sample(SamplerLinearClamp, uv);
}
// Lens Flaresf
// Lens Flares
BRANCH
if (LensFlareIntensity > 0)
{
@@ -677,21 +670,17 @@ float4 PS_Composite(Quad_VS2PS input) : SV_Target
lensLight += lensFlares * 1.5f;
color.rgb += lensFlares;
}
// In PS_Composite:
BRANCH
if (BloomIntensity > 0)
{
// Sample the final bloom result
float3 bloom = Input2.Sample(SamplerLinearClamp, input.TexCoord).rgb;
bloom = bloom * BloomIntensity;
lensLight += max(0, bloom * 3.0f + (- 1.0f * 3.0f));
color.rgb += bloom;
}
// Bloom
BRANCH
if (BloomIntensity > 0)
{
// Sample the final bloom result
float3 bloom = Input2.Sample(SamplerLinearClamp, input.TexCoord).rgb;
bloom = bloom * BloomIntensity;
lensLight += max(0, bloom * 3.0f + (-1.0f * 3.0f));
color.rgb += bloom;
}
// Lens Dirt
float3 lensDirt = LensDirt.SampleLevel(SamplerLinearClamp, uv, 0).rgb;