Lens Flare (Post Effect)

  • 2 Replies
  • 124 Views

0 Members and 1 Guest are viewing this topic.

Offline 3DickUlus

  • *
  • 3e
  • *****
  • Posts: 1142
    • 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 ;)
« Last Edit: November 11, 2018, 02:49:09 AM by 3DickUlus »
Resistance is fertile... you will be illuminated!

https://en.wikibooks.org/wiki/Fractals/fragmentarium

Offline timemit

  • *
  • Fractal Friar
  • *
  • Posts: 131
    • 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

  • *
  • 3e
  • *****
  • Posts: 1082
    • 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
200 Views
Last post December 02, 2018, 08:26:36 AM
by Sabine62
clip
Wanting someone to look at and post pictures of this ...

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

1 Replies
145 Views
Last post May 08, 2019, 12:35:14 PM
by 1bryan1
exclamation
MMFwip3D.ufm.zip - read post first !

Started by FractalDave on UltraFractal

0 Replies
88 Views
Last post November 14, 2018, 12:39:45 PM
by FractalDave
clip
Moire effect

Started by alber on Fractal Mathematics And New Theories

4 Replies
218 Views
Last post February 22, 2019, 05:22:50 PM
by claude
clip
analytic log(DE) post-processed with ImageMagick

Started by claude on Fractal Image Gallery

3 Replies
165 Views
Last post April 03, 2018, 07:00:04 AM
by claude