Logo by Pauldelbrot - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. April 19, 2024, 01:04:31 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Adding to the Buffershader (Lens Flare)  (Read 1387 times)
Description: ideas and code for Fragmentarium's buffershader
0 Members and 1 Guest are viewing this topic.
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« on: May 27, 2016, 05:15:25 AM »

Lens Flare

any ideas on how to make this work with tiled render and work better with subframes huh?
edit: fixed subframes?

add these lines to the #group Post in 3Dkn-1.0.1.frag
Code:
uniform bool  LensFlare; checkbox[false]
uniform float FlareIntensity; slider[0,0.25,1]
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]

add this to BufferShader-1.0.1.frag right before  the line vec4 bloom(vec2 pos, vec2 quality){//see: https://gist.github.com/BlackBulletIV/4218802
Code:
/*----------------------------------------------------------------------------*/
// 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 sampler2D tex,
        in vec2 texcoord,
        in vec2 direction,
        in vec4 distortion
) {
        return vec4(
                texture2D(tex, texcoord + direction * distortion.r).r,
                texture2D(tex, texcoord + direction * distortion.g).g,
                texture2D(tex, texcoord + direction * distortion.b).b,
                texture2D(tex, 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( frontbuffer,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( frontbuffer, fract(texcoord + haloVec), ghostVecNorm, distortion ) * weight;
        return result;
}
/*----------------------------------------------------------------------------*/


and in the main() routine add this somewhere, right after the test and call to bloom seems to work
Code:
	if(LensFlare) {
                vec4 lf=lensflare(pos,pixelsiz);
                lf=lf/lf.w;
                c += FlareIntensity*lf.xyz;
        }

and you get this...

edit: John Chapman informed me that this use of his code is fine cheesy (yes I actually asked him)


* lensflare-test3.jpg (72.02 KB, 1280x720 - viewed 456 times.)
« Last Edit: August 01, 2016, 05:28:28 PM by 3dickulus, Reason: relevant title » Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Adding some imagination... Mandelbulb Renderings David Makin 1 1440 Last post December 05, 2009, 12:02:05 AM
by David Makin
Adding to personal gallery Discuss Fractal Forums MarkJayBee 3 921 Last post May 06, 2010, 05:49:51 PM
by cKleinhuis
Lens Flare! Mandelbulb3D Gallery Lee Oliver 1 695 Last post April 16, 2012, 07:12:24 AM
by Rathinagiri
Adding Signature To Your Work Discuss Fractal Forums darciamoonz 3 1456 Last post November 24, 2012, 07:15:12 PM
by lenord
Adding formulas from MB3D and others? Feature Requests « 1 2 » cKleinhuis 23 11177 Last post February 19, 2015, 09:26:26 PM
by taurus

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.307 seconds with 28 queries. (Pretty URLs adds 0.014s, 2q)