-
Notifications
You must be signed in to change notification settings - Fork 92
feat(UI): add gaussian blur shader core files #1595
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
Open
davo0411
wants to merge
8
commits into
doodlum:dev
Choose a base branch
from
davo0411:blur-shader-core
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+830
−0
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
56a8784
blur
davo0411 51223f0
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] 36c10f4
refactor
davo0411 e07d14a
optimisations
davo0411 971eda2
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] 2e0a3c0
fixes
davo0411 f51556c
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] 98a2053
Update BackgroundBlur.cpp
davo0411 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Horizontal Blur Pass Shader | ||
| // Part of the BackgroundBlur system - separable Gaussian blur implementation | ||
|
|
||
| cbuffer BlurBuffer : register(b0) | ||
| { | ||
| float4 TexelSize; // x = 1/width, y = 1/height, z = blur strength, w = unused | ||
| int4 BlurParams; // x = samples, y = unused, z = unused, w = unused | ||
| }; | ||
|
|
||
| SamplerState LinearSampler : register(s0); | ||
| Texture2D InputTexture : register(t0); | ||
|
|
||
| struct VS_OUTPUT | ||
| { | ||
| float4 Position : SV_POSITION; | ||
| float2 TexCoord : TEXCOORD0; | ||
| }; | ||
|
|
||
| VS_OUTPUT VS_Main(uint vertexID : SV_VertexID) | ||
| { | ||
| VS_OUTPUT output; | ||
| output.TexCoord = float2((vertexID << 1) & 2, vertexID & 2); | ||
| output.Position = float4(output.TexCoord * 2.0f - 1.0f, 0.0f, 1.0f); | ||
| output.Position.y = -output.Position.y; | ||
| return output; | ||
| } | ||
|
|
||
| // Precomputed normalized Gaussian weights (sigma = 2.0) | ||
| static const float WEIGHTS[8] = { | ||
| 0.1760327f, // offset 0 (center) | ||
| 0.1658591f, // offset ±1 | ||
| 0.1403215f, // offset ±2 | ||
| 0.1069852f, // offset ±3 | ||
| 0.0732894f, // offset ±4 | ||
| 0.0451904f, // offset ±5 | ||
| 0.0248657f, // offset ±6 | ||
| 0.0122423f // offset ±7 | ||
| }; | ||
|
|
||
| float4 PS_Main(VS_OUTPUT input) : SV_TARGET | ||
| { | ||
| const int samples = min(BlurParams.x, 15); | ||
| const int halfSamples = samples / 2; | ||
|
|
||
| // Sample center pixel | ||
| float4 result = InputTexture.Sample(LinearSampler, input.TexCoord) * WEIGHTS[0]; | ||
|
|
||
| // Sample symmetric pairs (2x loop unrolling opportunity) | ||
| [unroll(7)] | ||
| for (int i = 1; i <= halfSamples; ++i) | ||
| { | ||
| float weight = WEIGHTS[min(i, 7)]; | ||
| float offset = i * TexelSize.x; | ||
|
|
||
| // Sampler CLAMP mode handles edge cases - no bounds check needed | ||
| result += InputTexture.Sample(LinearSampler, input.TexCoord + float2(offset, 0.0f)) * weight; | ||
| result += InputTexture.Sample(LinearSampler, input.TexCoord - float2(offset, 0.0f)) * weight; | ||
| } | ||
|
|
||
| return result; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Vertical Blur Pass Shader | ||
| // Part of the BackgroundBlur system - separable Gaussian blur implementation | ||
|
|
||
| cbuffer BlurBuffer : register(b0) | ||
| { | ||
| float4 TexelSize; // x = 1/width, y = 1/height, z = blur strength, w = unused | ||
| int4 BlurParams; // x = samples, y = unused, z = unused, w = unused | ||
| }; | ||
|
|
||
| SamplerState LinearSampler : register(s0); | ||
| Texture2D InputTexture : register(t0); | ||
|
|
||
| struct VS_OUTPUT | ||
| { | ||
| float4 Position : SV_POSITION; | ||
| float2 TexCoord : TEXCOORD0; | ||
| }; | ||
|
|
||
| VS_OUTPUT VS_Main(uint vertexID : SV_VertexID) | ||
| { | ||
| VS_OUTPUT output; | ||
| output.TexCoord = float2((vertexID << 1) & 2, vertexID & 2); | ||
| output.Position = float4(output.TexCoord * 2.0f - 1.0f, 0.0f, 1.0f); | ||
| output.Position.y = -output.Position.y; | ||
| return output; | ||
| } | ||
|
|
||
| // Precomputed normalized Gaussian weights (sigma = 2.0) | ||
| static const float WEIGHTS[8] = { | ||
| 0.1760327f, // offset 0 (center) | ||
| 0.1658591f, // offset ±1 | ||
| 0.1403215f, // offset ±2 | ||
| 0.1069852f, // offset ±3 | ||
| 0.0732894f, // offset ±4 | ||
| 0.0451904f, // offset ±5 | ||
| 0.0248657f, // offset ±6 | ||
| 0.0122423f // offset ±7 | ||
| }; | ||
|
|
||
| float4 PS_Main(VS_OUTPUT input) : SV_TARGET | ||
| { | ||
| const int samples = min(BlurParams.x, 15); | ||
| const int halfSamples = samples / 2; | ||
|
|
||
| // Sample center pixel | ||
| float4 result = InputTexture.Sample(LinearSampler, input.TexCoord) * WEIGHTS[0]; | ||
|
|
||
| // Sample symmetric pairs (2x loop unrolling opportunity) | ||
| [unroll(7)] | ||
| for (int i = 1; i <= halfSamples; ++i) | ||
| { | ||
| float weight = WEIGHTS[min(i, 7)]; | ||
| float offset = i * TexelSize.y; | ||
|
|
||
| // Sampler CLAMP mode handles edge cases - no bounds check needed | ||
| result += InputTexture.Sample(LinearSampler, input.TexCoord + float2(0.0f, offset)) * weight; | ||
| result += InputTexture.Sample(LinearSampler, input.TexCoord - float2(0.0f, offset)) * weight; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.