this one is for BufferShader-n.n.n.frag...

After this line...

`uniform sampler2D frontbuffer;`

>>> here <<<

...

... insert

`// 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...

`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