-
Notifications
You must be signed in to change notification settings - Fork 116
fix: add anti-firefly pass #2028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||
| #include "Common/Color.hlsli" | ||||||||||||||||||||
| #include "Common/DummyVSTexCoord.hlsl" | ||||||||||||||||||||
| #include "Common/FrameBuffer.hlsli" | ||||||||||||||||||||
| #include "Common/Math.hlsli" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| typedef VS_OUTPUT PS_INPUT; | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -29,6 +30,36 @@ float4 GetImageColor(float2 texCoord, float blurScale) | |||||||||||||||||||
| return ImageTex.Sample(ImageSampler, texCoord) * float4(blurScale.xxx, 1); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # if defined(BRIGHTPASS) | ||||||||||||||||||||
| static const float kBrightPassSoftKneeRatio = 0.5; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Sample a 2x2 neighborhood and Karis-average to suppress isolated HDR outliers. | ||||||||||||||||||||
| float3 SampleKarisFireflySuppress(float2 uv, float2 texelSize) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| float3 s0 = ImageTex.SampleLevel(ImageSampler, uv + float2(-0.5, -0.5) * texelSize, 0).rgb; | ||||||||||||||||||||
| float3 s1 = ImageTex.SampleLevel(ImageSampler, uv + float2(0.5, -0.5) * texelSize, 0).rgb; | ||||||||||||||||||||
| float3 s2 = ImageTex.SampleLevel(ImageSampler, uv + float2(-0.5, 0.5) * texelSize, 0).rgb; | ||||||||||||||||||||
| float3 s3 = ImageTex.SampleLevel(ImageSampler, uv + float2(0.5, 0.5) * texelSize, 0).rgb; | ||||||||||||||||||||
| return Color::KarisWeightedAverage(s0, s1, s2, s3); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| float3 ApplyBrightPass(float3 hdrColor) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| float threshold = max(BlurBrightPass.x, 0.0); | ||||||||||||||||||||
| float scale = max(BlurBrightPass.y, 0.0); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Soft-knee threshold avoids binary bloom popping when highlights hover near threshold. | ||||||||||||||||||||
| float knee = max(threshold * kBrightPassSoftKneeRatio, EPSILON_DIVISION); | ||||||||||||||||||||
| float brightness = max(Color::RGBToLuminance(hdrColor), EPSILON_DIVISION); | ||||||||||||||||||||
| float soft = saturate((brightness - threshold + knee) / max(2.0 * knee, EPSILON_DIVISION)); | ||||||||||||||||||||
| soft = soft * soft * (3.0 - 2.0 * soft); | ||||||||||||||||||||
| float contribution = max(brightness - threshold, 0.0) + soft * knee; | ||||||||||||||||||||
| float weight = contribution / brightness; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return hdrColor * weight * scale; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| # endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| PS_OUTPUT main(PS_INPUT input) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| PS_OUTPUT psout; | ||||||||||||||||||||
|
|
@@ -45,9 +76,22 @@ PS_OUTPUT main(PS_INPUT input) | |||||||||||||||||||
| blurScale = 1; | ||||||||||||||||||||
| # endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # if defined(BRIGHTPASS) | ||||||||||||||||||||
| float avgLum = Color::RGBToLuminance(AvgLumTex.Sample(AvgLumSampler, input.TexCoord.xy).xyz); | ||||||||||||||||||||
| uint imgWidth, imgHeight; | ||||||||||||||||||||
| ImageTex.GetDimensions(imgWidth, imgHeight); | ||||||||||||||||||||
| float2 texelSize = rcp(float2(imgWidth, imgHeight)); | ||||||||||||||||||||
| # endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| for (int blurIndex = 0; blurIndex < blurRadius; ++blurIndex) { | ||||||||||||||||||||
| float2 screenPosition = BlurOffsets[blurIndex].xy + input.TexCoord.xy; | ||||||||||||||||||||
| float4 imageColor = 0; | ||||||||||||||||||||
| # if defined(BRIGHTPASS) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| float2 sampleUV = (BlurScale.x < 0.5) ? FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(screenPosition) : screenPosition; | ||||||||||||||||||||
| imageColor.rgb = ApplyBrightPass(SampleKarisFireflySuppress(sampleUV, texelSize)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+90
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep This branch no longer goes through Suggested fix {
float2 sampleUV = (BlurScale.x < 0.5) ? FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(screenPosition) : screenPosition;
- imageColor.rgb = ApplyBrightPass(SampleKarisFireflySuppress(sampleUV, texelSize));
+ float3 hdrColor = SampleKarisFireflySuppress(sampleUV, texelSize) * blurScale.y;
+ imageColor.rgb = ApplyBrightPass(hdrColor);
}If 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| # else | ||||||||||||||||||||
| [branch] if (BlurScale.x < 0.5) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| imageColor = GetImageColor(FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(screenPosition), blurScale.y); | ||||||||||||||||||||
|
|
@@ -56,14 +100,11 @@ PS_OUTPUT main(PS_INPUT input) | |||||||||||||||||||
| { | ||||||||||||||||||||
| imageColor = GetImageColor(screenPosition, blurScale.y); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| # if defined(BRIGHTPASS) | ||||||||||||||||||||
| imageColor = BlurBrightPass.y * max(0, -BlurBrightPass.x + imageColor); | ||||||||||||||||||||
| # endif | ||||||||||||||||||||
| color += imageColor * BlurOffsets[blurIndex].z; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # if defined(BRIGHTPASS) | ||||||||||||||||||||
| float avgLum = Color::RGBToLuminance(AvgLumTex.Sample(AvgLumSampler, input.TexCoord.xy).xyz); | ||||||||||||||||||||
| color.w = avgLum; | ||||||||||||||||||||
| # endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be needed now. probably isn't very effective
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you're saying.