Light Scattering failure

Yes but even in shadow, there can be bright nodes or even bright textures you know? How would those be affected then?

They won’t scatter, but that’s the case for the current implementation. Only bright areas of the sky (as in things in the sky bucket) scatter.

OH OK! Only the Bucket.Sky scatters… yeah this would be very useful then! :smiley:

I’ve been playing around with the filter. First I merged the change from this post http://hub.jmonkeyengine.org/forum/topic/light-scattering/#post-207641
Then I changed the way the blur is mixed with the original scene color. I managed to have a nice result that avoid black shaftswithout using the ray casting and allow to see light shafts when the light source is partially visible.

before :

after :

It’s not perfect because there is some halo around the mountains and on still images it can look a bit weird. But that’s definitely better.

2 Likes

It made the light shafts a bit more subtle too… This may change things in some scenes, maybe the light density will need to be adjusted.
before

after

2 Likes

Good! I’m eager to test this out Remy! At last the changes from http://hub.jmonkeyengine.org/forum/topic/light-scattering/#post-207641 those were so much welcome, it completely fixed the issues when the camera was turning to the right.

Good job @nehon! +1 for you :stuck_out_tongue:

Alright, hi @nehon, I assembled a new computer with a different graphics card (different brand too, before I had nVidia now it’s an ATI) and when I tested this perfectly working project of mine on this new computer, it complained about the LightScatteringFilter (ATI seems to be a lot stricter about GLSL compilation, nVidia just silently ignores most of the strict errors):

com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Common/MatDefs/Post/LightScattering.frag, defines, type=Fragment, language=GLSL120] error:Fragment shader failed to compile with the following errors:
WARNING: 0:18: implicit cast from int to float
WARNING: 0:24: implicit cast from int to float
WARNING: 0:30: implicit cast from int to float
WARNING: 0:33: implicit cast from int to float
ERROR: 0:34: ‘fragColor’ : undeclared identifier
ERROR: 0:34: ‘assign’ : cannot convert from ‘4-component vector of float’ to ‘float’
ERROR: compilation errors. No code generated.

I just thought I’d let you know.

Thx

@.Ben. said: (different brand too, before I had nVidia now it's an ATI)
Oh boy...I feel sorry for you.

You should also have the code ouput in the console, could you please post it too?
The 0:18,0:24 etc are referring to lines in this code (generated code, not the shader code itself).
This would help a lot.
Thanks

Oops… my bad. I had the verbosity turned off, that’s why I didn’t see this at first. Here is the full error output:

Avertissement: Bad compile of:
1 #version 120
2 uniform sampler2D m_Texture;
3 uniform sampler2D m_DepthTexture;
4 uniform int m_NbSamples;
5 uniform float m_BlurStart;
6 uniform float m_BlurWidth;
7 uniform float m_LightDensity;
8 uniform bool m_Display;
9 uniform vec3 m_LightPosition;
10
11 varying vec2 texCoord;
12
13 void main(void)
14 {
15 if(m_Display){
16
17 vec4 colorRes= texture2D(m_Texture,texCoord);
18 float factor=(m_BlurWidth/float(m_NbSamples-1.0));
19 float scale;
20 vec2 texCoo=texCoord - m_LightPosition.xy;
21 vec2 scaledCoord;
22 vec4 res = vec4(0.0);
23 for(int i=0; i<m_NbSamples; i++) {
24 scale = i * factor + m_BlurStart ;
25 scaledCoord=texCoo*scale + m_LightPosition.xy;
26 if(texture2D(m_DepthTexture,scaledCoord).r==1.0){
27 res += texture2D(m_Texture,scaledCoord);
28 }
29 }
30 res /= m_NbSamples;
31
32 //Blend the original color with the averaged pixels
33 float mean = (res.r + res.g + res.b)/3;
34 fragColor =mix(colorRes ,mix( colorRes, res, m_LightDensity),mean);
35 }else{
36 gl_FragColor= texture2D(m_Texture,texCoord);
37 }
38 }

avr. 13, 2014 1:09:56 PM com.jme3.app.Application handleError
Grave: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Common/MatDefs/Post/LightScattering.frag, defines, type=Fragment, language=GLSL120] error:Fragment shader failed to compile with the following errors:
WARNING: 0:18: implicit cast from int to float
WARNING: 0:24: implicit cast from int to float
WARNING: 0:30: implicit cast from int to float
WARNING: 0:33: implicit cast from int to float
ERROR: 0:34: ‘fragColor’ : undeclared identifier
ERROR: 0:34: ‘assign’ : cannot convert from ‘4-component vector of float’ to ‘float’
ERROR: compilation errors. No code generated.

Thanks, I’m gonna fix this.
Though you should check your drivers, because it’s not using the glsl 1.5 shader.
Since you have a complete new computer I would have though that it was compatilble with glsl 1.5

Not in this case, because I haven’t received my new Radeon R9 270X yet, so I’m currently using an older passive (lol) Radeon HD 4350 which says only supports OpenGL 2.1 thus GLSL 1.3 that’s why it falls back on the GLSL 1.0 shader.

Then it’s perfectly fine :stuck_out_tongue:

It’s fixed in last revision btw. Thanks for reporting the issue.

2 Likes