Improved light scattering GLSL filter

Yeh you can reduce the amount of samples / Rays in the source code. to scale to computer specs.

I tried it out on my GTX 465, and got 60fps at 1300x1000 or something like that.
Unfortunately, it doesn’t work in Stereo 3D, so I can’t use it on my projects =/

Excellent work sir, amazing piece of work. I was still getting the full 60fps with 128 samples on my GTX285

Very neat work, this is. Getting 60 FPS with ATI HD Radeon 6570.

However, when I switch between cameras in-game, the shader appears to be disabled. Is there a work-around, or am I not doing something right?

Great bit of work, thanks for sharing!

One question: is it possible to use the x and y positions of a light in Blender in the shader directly?

I’m running on a mac book pro and I can’t get the effect!

I try to fiddle with the X and Y but nothing happens.

Is there a way to tell which objects do you want to apply this effect and which ones you don’t want? Right now it applies this effect all over the scene even in objects that the script is not applied.

I love your filter, it really adds a lot more interest to my scene.
Here is what I accomplished with it:


1 Like

Hi CTBM,

Good Thanks to this sharing! Awesome feature of games!

Can you give me some guidence on how to use it?

in order to get this working in bge 2.79 replace line 13+14 with:

float xPos = 0.5; // 0.0 - 1.0
float yPos = 0.8; // 0.0 - 1.0

for upbge no clue it throws a sample error

1 Like

To work in upbge
replace every ‘sample’ by ‘sampler’

EDIT:
and replace the line 31 with this:

     vec2 deltaTexCoord = vec2(gl_TexCoord[0]) - lightScreenPos;

this replace the w axis by x axis, only change the 3 in gl_TexCoord[3] for 0.

1 Like

ok that makes it work, but now it does not work as it should, direction of the rays are pointing the wrong way.

Make the coordinates to be uniforms and write a python script to update them based on your light’s position.

OR

if you make the rays origin coordinates to be constants, yes, the rays will always point as you defined.
Put it at off screen as if a light always comes from above: xPos=.5; yPos=1.9
or let it at the screen center: xPos=.5; yPos=.5

1 Like

BUT

there is another godrays filter with a light position update script by adriansnetlis:

i have made a mod of the file: Godrays_UP.blend (515.5 KB)

1 Like

The problem is, in bge it’s fine, in upbge its not, it point to the wrong direction, got no glsl knowledge so i’m not gonna adjust anything.

i edited my first reply:

1 Like

my upbge version of this shader

LScatter.fs

uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;

//uniform float avgL;

const float dens = 0.6; // Density
const float dec = 0.95; // Decay
const float weight = 0.2;
float exp = 0.25; // Exposure

// Light Screen (Origin if effect is not working Play with X & Y)

uniform float xPos = 0.5; // 0.0 - 1.0
uniform float yPos = 0.8; // 0.0 - 1.0

uniform vec2 lightScreenPos;

// Number of Ray Samples (Quality 1 - 128)

const int raySamples = 64;

void main()
{

    vec4 origin = vec4(0);
    vec4 sampler = vec4(0);
    vec4 mask = vec4(0);

    vec2 lightScreenPos = vec2(xPos,yPos);

    vec2 deltaTexCoord = vec2(gl_TexCoord[0]) - lightScreenPos;
	vec2 texCoo = gl_TexCoord[0].st;
	deltaTexCoord *= 1.0 / float(raySamples) * dens;
	float illumDecay = 1.0;

   for(int i=0; i < raySamples ; i++)
   {
       texCoo -= deltaTexCoord;

        if (texture2D(bgl_DepthTexture, texCoo).r > 0.9989)
        {
            sampler += texture2D(bgl_RenderedTexture, texCoo);
        }
        
        sampler *= illumDecay * weight;
    
        origin += sampler;
        illumDecay *= dec;
    }
    
    vec2 texcoord = vec2(gl_TexCoord[0]);
 
    gl_FragColor = texture2D(bgl_RenderedTexture, texcoord) + (origin*exp);

}

1 Like

works like a charm thanks!

Btw: your version of godray, that blend really is bugged, or very heavy.

i use:
ryzen 5 3600
16gb ram
rx 5700 xt

if i look at the sun, then move mouse slowly left or right, the godray effect is slowing down the mouse input/movement by a lot. like something blocking it from moving like normal.

tho i got over 1200 fps, so dunno what it is, i bet the shader itself.

hey @Cotaks , test this:

light scattering with light position update.
BGE 2.79 and UPBGE 0.2.5 compatible
lightScatter.blend (457.1 KB)