Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Toggle Effects
- #define DO_VIGNETTE 1
- #define DO_GAUSSIANBLUR 1
- //Effect Configurations
- #define GAUSSIAN_SAMPLES 6
- const float double_pi = 6.283185307179586476925286766559;
- const float sigma = float(GAUSSIAN_SAMPLES) / 2.0;
- const vec2 image_res = vec2(3860, 2160);
- vec2 ps = vec2(1.0) / iResolution.xy;
- float ar = iResolution.x / iResolution.y;
- //Functions
- vec2 scaleUV(vec2, vec2);
- vec3 crop(sampler2D, vec2);
- float gaussian_function(float);
- float gaussian_function(vec2);
- float gaussian_get_accum();
- //Effects
- vec3 GaussianBlur(sampler2D, vec2, vec2);
- vec3 GaussianBlur(sampler2D, vec2);
- void Vignette(inout vec3, vec2);
- //Main Function
- void main() {
- vec2 uv = gl_FragCoord.xy * ps;
- vec3 col = GaussianBlur(iChannel0, uv);
- Vignette(col, uv);
- gl_FragColor = vec4(col, 1.0);
- }
- vec2 scaleUV(vec2 uv, vec2 scale) {
- return (uv - 0.5) * scale + 0.5;
- }
- vec3 crop(sampler2D sp, vec2 uv) {
- return vec3(0.0);
- }
- float gaussian_function(float x) {
- const float first_part = 1.0 / sqrt(double_pi * pow(sigma, 2.0));
- const float second_part_a = 1.0 / (2.0 * pow(sigma, 2.0));
- float second_part_b = pow(x, 2.0) * second_part_a;
- return first_part * exp(-second_part_a);
- }
- float gaussian_function(vec2 i) {
- const float first_part = 1.0 / (double_pi * pow(sigma, 2.0));
- const float second_part_a = 1.0 / (2.0 * pow(sigma, 2.0));
- float second_part_b = (pow(i.x, 2.0) + pow(i.y, 2.0)) * second_part_a;
- return first_part * exp(-second_part_b);
- }
- float gaussian_get_accum() {
- float accum = 0.0;
- for (int i = -GAUSSIAN_SAMPLES; i <= GAUSSIAN_SAMPLES; ++i)
- accum += gaussian_function(float(i));
- return 1.0 / accum;
- }
- vec3 GaussianBlur(sampler2D sp, vec2 uv, vec2 dir) {
- #if !DO_GAUSSIANBLUR
- return texture2D(sp, uv).rgb;
- #endif
- vec3 col = vec3(0.0);
- float gauss_weight = 0.0;
- float accum = 0.0;
- for (int i = -GAUSSIAN_SAMPLES; i <= GAUSSIAN_SAMPLES; ++i) {
- gauss_weight = gaussian_function(float(i));
- col += texture2D(sp, uv + ps * dir * vec2(i)).rgb * gauss_weight;
- accum += gauss_weight;
- }
- return col / accum;
- }
- vec3 GaussianBlur(sampler2D sp, vec2 uv) {
- #if !DO_GAUSSIANBLUR
- return texture2D(sp, uv).rgb;
- #endif
- vec3 col = vec3(0.0);
- float gauss_weight = 0.0;
- float accum = 0.0;
- for (int x = -GAUSSIAN_SAMPLES; x <= GAUSSIAN_SAMPLES; ++x) {
- for (int y = -GAUSSIAN_SAMPLES; y <= GAUSSIAN_SAMPLES; ++y) {
- gauss_weight = gaussian_function(vec2(x, y));
- col += texture2D(sp, uv + ps * vec2(x, y)).rgb * gauss_weight;
- accum += gauss_weight;
- }
- }
- return col / accum;
- }
- void Vignette(inout vec3 col, vec2 uv) {
- #if DO_VIGNETTE
- col *= 1.0 - distance(uv, vec2(0.5));
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement