|
1 | 1 | #version 330 core |
2 | 2 | in vec2 screen_uv; |
3 | | -//layout (location = 0) out vec4 FragColor; // 保留原色 |
4 | | -//layout (location = 1) out vec4 BrightColor; // 模糊后的高亮结果 |
5 | | -out vec4 BrightColor; // 模糊后的高亮结果 |
| 3 | +out vec4 BrightColor; |
6 | 4 |
|
7 | | -//uniform sampler2D image; // 原场景 |
8 | | -uniform sampler2D bright; // 高亮通道 |
9 | | -uniform float uOffset; // Kawase 偏移 |
10 | | -uniform float intensity; // Bloom 强度 |
| 5 | +uniform sampler2D bright; |
| 6 | +uniform float uOffset; |
| 7 | +uniform float intensity; |
11 | 8 |
|
12 | 9 | void main() { |
13 | | -// // 原图颜色 |
14 | | -// vec4 sceneColor = texture2D(image, screen_uv); |
15 | | -// FragColor = sceneColor; |
16 | | - vec4 brightColor = texture2D(bright, screen_uv); |
17 | | - vec2 size = 1.0 / textureSize(bright, 0); |
18 | | - // Kawase 模糊采样 |
| 10 | + vec4 brightColor = texture(bright, screen_uv); |
| 11 | + vec2 size = 1.0 / vec2(textureSize(bright, 0)); |
19 | 12 | vec2 o = size * uOffset; |
20 | | - vec3 blur = |
21 | | - texture2D(bright, screen_uv + vec2(o.x, 0.0)).rgb + |
22 | | - texture2D(bright, screen_uv + vec2(-o.x, 0.0)).rgb + |
23 | | - texture2D(bright, screen_uv + vec2(0.0, o.y)).rgb + |
24 | | - texture2D(bright, screen_uv + vec2(0.0, -o.y)).rgb + |
25 | | - texture2D(bright, screen_uv + vec2(o.x, o.y)).rgb + |
26 | | - texture2D(bright, screen_uv + vec2(-o.x, o.y)).rgb + |
27 | | - texture2D(bright, screen_uv + vec2(o.x, -o.y)).rgb + |
28 | | - texture2D(bright, screen_uv + vec2(-o.x, -o.y)).rgb; |
29 | 13 |
|
30 | | - blur *= 0.125; // 平均值 |
| 14 | + vec3 blur = |
| 15 | + texture(bright, screen_uv + vec2(o.x, 0.0)).rgb + |
| 16 | + texture(bright, screen_uv + vec2(-o.x, 0.0)).rgb + |
| 17 | + texture(bright, screen_uv + vec2(0.0, o.y)).rgb + |
| 18 | + texture(bright, screen_uv + vec2(0.0, -o.y)).rgb + |
| 19 | + texture(bright, screen_uv + vec2(o.x, o.y)).rgb + |
| 20 | + texture(bright, screen_uv + vec2(-o.x, o.y)).rgb + |
| 21 | + texture(bright, screen_uv + vec2(o.x, -o.y)).rgb + |
| 22 | + texture(bright, screen_uv + vec2(-o.x, -o.y)).rgb; |
31 | 23 |
|
32 | | - // Bloom 结果(模糊 + 强度) |
| 24 | + blur *= 0.125; |
33 | 25 | BrightColor = vec4(blur * intensity, 1.0); |
34 | 26 | } |
0 commit comments