Skip to content

Commit b9ae21c

Browse files
author
Jaedan
committed
Add a bloom example
1 parent 33cdf2a commit b9ae21c

12 files changed

+551
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ add_executable(SDL_gpu_examples
2828
Examples/TriangleMSAA.c
2929
Examples/Cubemap.c
3030
Examples/WindowResize.c
31+
Examples/Bloom.c
3132
)
3233

3334
target_include_directories(SDL_gpu_examples PRIVATE . spirv)
1016 Bytes
Binary file not shown.
1.19 KB
Binary file not shown.
948 Bytes
Binary file not shown.
3.44 KB
Binary file not shown.

Content/Shaders/Source/Bloom.vert

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#version 450
2+
3+
layout (location = 0) in vec3 Position;
4+
layout (location = 1) in vec2 TexCoord;
5+
layout (location = 0) out vec2 outTexCoord;
6+
7+
void main()
8+
{
9+
outTexCoord = TexCoord;
10+
gl_Position = vec4(Position, 1);
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#version 450
2+
3+
layout (location = 0) in vec2 TexCoord;
4+
layout (location = 0) out vec4 FragColor;
5+
layout (set = 2, binding = 0) uniform sampler2D Scene;
6+
layout (set = 2, binding = 1) uniform sampler2D Blur;
7+
layout (set = 3, binding = 0) uniform UniformBlock
8+
{
9+
float Exposure;
10+
};
11+
12+
void main()
13+
{
14+
vec3 color = texture(Scene, TexCoord).rgb;
15+
vec3 blurColor = texture(Blur, TexCoord).rgb;
16+
color += blurColor;
17+
18+
FragColor = vec4(color, 1.0);
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#version 450
2+
3+
layout (location = 0) in vec2 TexCoord;
4+
layout (location = 0) out vec4 FragColor;
5+
layout (set = 2, binding = 0) uniform sampler2D Sampler;
6+
7+
void main()
8+
{
9+
FragColor = texture(Sampler, TexCoord);
10+
11+
float brightness = dot(FragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
12+
if (brightness < 1.0)
13+
FragColor = vec4(0.0, 0.0, 0.0, 0.0);
14+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#version 450
2+
3+
layout (location = 0) in vec2 TexCoord;
4+
layout (location = 0) out vec4 FragColor;
5+
layout (set = 2, binding = 0) uniform sampler2D Sampler;
6+
layout (set = 3, binding = 0) uniform UniformBlock
7+
{
8+
bool Horizontal;
9+
};
10+
11+
float Weight[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
12+
13+
void main()
14+
{
15+
vec2 tex_offset = 1.0 / textureSize(Sampler, 0); // gets size of single texel
16+
vec3 result = texture(Sampler, TexCoord).rgb * Weight[0]; // current fragment's contribution
17+
if (Horizontal) {
18+
for (int i = 1; i < 5; ++i) {
19+
result += texture(Sampler, TexCoord + vec2(tex_offset.x * i, 0.0)).rgb * Weight[i];
20+
result += texture(Sampler, TexCoord - vec2(tex_offset.x * i, 0.0)).rgb * Weight[i];
21+
}
22+
} else {
23+
for (int i = 1; i < 5; ++i) {
24+
result += texture(Sampler, TexCoord + vec2(0.0, tex_offset.y * i)).rgb * Weight[i];
25+
result += texture(Sampler, TexCoord - vec2(0.0, tex_offset.y * i)).rgb * Weight[i];
26+
}
27+
}
28+
FragColor = vec4(result, 1.0);
29+
}

0 commit comments

Comments
 (0)