Lens Flare (Post Effect)

  • 2 Replies
  • 239 Views

0 Members and 1 Guest are viewing this topic.

Offline 3DickUlus

  • *
  • 3f
  • ******
  • Posts: 1790
    • Digilantism
« on: November 11, 2018, 02:36:24 AM »
this one is for BufferShader-n.n.n.frag...
After this line...
Code: [Select]
uniform sampler2D frontbuffer;
>>> here <<<
...
... insert
Code: [Select]
// modified from http://john-chapman-graphics.blogspot.ca/2013/02/pseudo-lens-flare.html
uniform bool LensFlare;
uniform float FlareIntensity;
uniform int   FlareSamples;
uniform float FlareDispersal;
uniform float FlareHaloWidth;
uniform float FlareDistortion;

vec4 textureDistorted(
        in vec2 texcoord,
        in vec2 direction,
        in vec4 distortion
) {
        return vec4(
                texture2D(frontbuffer, texcoord + direction * distortion.r).r,
                texture2D(frontbuffer, texcoord + direction * distortion.g).g,
                texture2D(frontbuffer, texcoord + direction * distortion.b).b,
                texture2D(frontbuffer, texcoord + direction * distortion.a).a
        );
}

vec4 lensflare(vec2 texcoord, vec2 texelSize) {

        vec2 ghostVec = (vec2(0.5) - texcoord) * FlareDispersal;
        vec2 ghostVecNorm = normalize(ghostVec);
        vec2 haloVec = normalize(ghostVec) * FlareHaloWidth;
        vec4 distortion = vec4(-texelSize.x * FlareDistortion, 0.0, texelSize.x * FlareDistortion, 0.0);

// sample ghosts:
        vec4 result = vec4(0.0);
        for (int i = 0; i < FlareSamples; ++i) {
                vec2 offset = fract(texcoord + ghostVec * float(i));
                float weight = pow(1.0 - (length(vec2(0.5) - offset) / length(vec2(0.5))), 10.0);
                result += textureDistorted(offset,ghostVecNorm,distortion ) * weight;
        }

//      sample halo:
        float weight = pow(1.0 - (length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5))), 10.0);
        result += textureDistorted(fract(texcoord + haloVec), ghostVecNorm, distortion ) * weight;
        return result;
}

NOTE 1: to get the uniform widget sliders to show up in the GUI we have to initialize them with default values in 3D-n.n.n.frag in the #group Post section...
Code: [Select]
uniform bool  LensFlare; checkbox[false]
uniform float FlareIntensity; slider[0.0,0.25,2]
uniform int   FlareSamples; slider[1,8,9]
uniform float FlareDispersal; slider[0.0,0.25,1.0]
uniform float FlareHaloWidth; slider[0.0,0.5,1.0]
uniform float FlareDistortion; slider[0.0,1.0,2.0]
..this is because 3D shader is part of the main raytracer and Buffer shader is a secondary program, you will note that the Bloom vars are done this way and the Post effects as well.

NOTE 2: all Post effects work on the color buffer directly this means Tiled Rendering may reveal tile edges or may not render as expected, the image attached was rendered using 1 tile.

This can be used as an example of how to add your own Post Effects ;)


Linkback: https://fractalforums.org/code-snippets-fragments/74/lens-flare-post-effect/2281/
« Last Edit: November 11, 2018, 02:49:09 AM by 3DickUlus »

Offline timemit

  • *
  • Fractal Friar
  • *
  • Posts: 137
    • timemit@DeiantArt
« Reply #1 on: November 12, 2018, 02:02:53 PM »
Great, something to try out.  I remember I had issues with tiles showing when using flare in  a psuedokleinian in the past, now I might be able to re-render some oldies I struggled with as a single tile.

Offline claude

  • *
  • 3f
  • ******
  • Posts: 1593
    • mathr.co.uk
« Reply #2 on: November 18, 2018, 05:05:07 AM »
In Raymond, I structured my shader #include tree a bit differently, instead of traditional Fragmentarium:

Scene
  MathUtils
  Raytracer
    3D
      BufferShader

I do:

Scene
  BufferShaderWrapper
    BufferShader
  Raytracer
    Lots
    Of
    Good
    Stuff

So the Scene has 2 includes, typically Raymond-sRGB which wraps a Raymond-sRGB-Buffer shader that stores linear RGB and outputs to sRGB in post pass (with exposure control); and Raymond (which has everything else transcluded).  The main wart is that conditional includes don't work so I can't include Raymond and use a different (faster) ray tracer for scene design.  The wrapper shader redeclares the uniforms from the real buffer shader in the main frag scope, so that it works nicely.


clip
Benesi SMenger + Lens Flare effect

Started by 3DickUlus on Fragmentarium

7 Replies
311 Views
Last post December 02, 2018, 08:26:36 AM
by Sabine62
xx
Did you know Virtual Lens are found in MB3D?

Started by i.AM.A.i on Share a fractal

0 Replies
68 Views
Last post June 18, 2020, 03:42:33 AM
by i.AM.A.i
clip
Moire effect

Started by alber on Fractal Mathematics And New Theories

4 Replies
349 Views
Last post February 22, 2019, 05:22:50 PM
by claude
clip
StarBurst effect for FragM

Started by kosalos on Code Snippets (fragments)

0 Replies
94 Views
Last post October 14, 2019, 08:55:35 PM
by kosalos
xx
testing water effect

Started by mclarekin on Fractal Image Gallery

0 Replies
145 Views
Last post November 03, 2018, 01:56:52 AM
by mclarekin