bgfx/examples/38-bloom/fs_downsample.sc

43 lines
1.4 KiB
Python
Raw Normal View History

$input v_texcoord0
/*
* Copyright 2018 Eric Arnebäck. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "../common/common.sh"
SAMPLER2D(s_tex, 0);
// pixel size of the target texture.
uniform vec4 u_pixelSize;
void main()
{
2018-09-21 01:49:56 +03:00
vec2 halfpixel = 0.5 * vec2(u_pixelSize.x, u_pixelSize.y);
vec2 oneepixel = 1.0 * vec2(u_pixelSize.x, u_pixelSize.y);
vec2 uv = v_texcoord0.xy;
2018-09-21 01:49:56 +03:00
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
2018-09-21 01:49:56 +03:00
sum += (4.0/32.0) * texture2D(s_tex, uv).rgba;
2018-09-21 01:49:56 +03:00
sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(-halfpixel.x, -halfpixel.y) );
sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(+halfpixel.x, +halfpixel.y) );
sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(+halfpixel.x, -halfpixel.y) );
sum += (4.0/32.0) * texture2D(s_tex, uv + vec2(-halfpixel.x, +halfpixel.y) );
sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, 0.0) );
sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, 0.0) );
sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(0.0, +oneepixel.y) );
sum += (2.0/32.0) * texture2D(s_tex, uv + vec2(0.0, -oneepixel.y) );
sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, +oneepixel.y) );
sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, +oneepixel.y) );
sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(+oneepixel.x, -oneepixel.y) );
sum += (1.0/32.0) * texture2D(s_tex, uv + vec2(-oneepixel.x, -oneepixel.y) );
gl_FragColor.xyzw = sum;
}