diff options
Diffstat (limited to 'src/example/04_bloom/postprocess.c')
-rw-r--r-- | src/example/04_bloom/postprocess.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/example/04_bloom/postprocess.c b/src/example/04_bloom/postprocess.c new file mode 100644 index 0000000..1ec10e4 --- /dev/null +++ b/src/example/04_bloom/postprocess.c @@ -0,0 +1,41 @@ +#include "../../shaders/common.h" + +/*uniforms*/ +#define _frag_tex UTEX(0) +#define _bright_tex UTEX(1) + +/*varyings*/ +#define _texcoord reg_v2_00 + +static float weight[5] = { 0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162 }; + +static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { + clipcoord->xyz = in->vertex->position; + clipcoord->w = 1; + *_texcoord = in->vertex->texcoord; +} + +static bool frag(UniformCollection* uniforms, FragmentShaderIn* in, Color32* color) { + float off = 1 / 600.f; + //blur + *color = tex2d(_frag_tex, _texcoord); + vec4_scale(color, weight[0], color); + Vec2 p = {0, _texcoord->y}; + Color32 c; + for (int i = 1; i < 5; ++i) { + p.x = _texcoord->x + off * i; + c = tex2d(_frag_tex, &p); + vec4_scale(&c, weight[i], &c); + vec4_add(color, &c, color); + p.x = _texcoord->x - off * i; + c = tex2d(_frag_tex, &p); + vec4_scale(&c, weight[i], &c); + vec4_add(color, &c, color); + } + return 1; +} + +Program _04_bloom_postprocess = { + vert, frag, + VARYING_V2_00 +}; |