• June 18, 2021, 08:23:44 AM

Login with username, password and session length

Author Topic:  Lens Flare (Post Effect)  (Read 319 times)

0 Members and 1 Guest are viewing this topic.

Offline 3DickUlus

  • Administrator
  • *******
  • Posts: 2276
    • Digilantism
Lens Flare (Post Effect)
« 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/index.php?topic=2281.0
« Last Edit: November 11, 2018, 02:49:09 AM by 3DickUlus »

Offline timemit

  • Fractal Friar
  • *
  • Posts: 139
    • timemit@DeiantArt
Re: Lens Flare (Post Effect)
« 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: 1915
    • mathr.co.uk
Re: Lens Flare (Post Effect)
« 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:


I do:


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.

Benesi SMenger + Lens Flare effect

Started by 3DickUlus on Fragmentarium

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

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

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

Started by alber on Fractal Mathematics And New Theories

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

Started by kosalos on Code Snippets (fragments)

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

Started by mclarekin on Fractal Image Gallery

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