Light Scattering Effect

Hi, is there a way to change dynamicly the direction of the LightScatteringFilter ? I saw that we could set the direction only in the constructor.

The thing is that my sun is moving along my world, I can make the LightScattering effect to follow it by setting the position but I couldn’t

find any ways to change the direction.



Thanks.

The direction is based on the position to your camera. That position is the sun. So just use setPosition() and set it to follow your sun. The direction will always point towards you.

yeah the lightPosition is a reference, so if you feed the constructor with your sun.getWorldTranslation it should work.



but now that i look at the code i shouldn’t have done it like this…there should be a setLightPosition and the Filter should not keep a reference on the lightPosition… You’d have to update the pos on each update, but it’s more like everything else is working.

Alright, now the effect seems to point at the camera, but the beams of light getting out the sun seems to point another direction, is that normal ?

What kind of light are you using for the sun?



Edit: picture came later and now I see what you mean.



Actually, I’m curious as to that answer myself because when I used light scatter it also scattered my sun object which I didn’t want. I didn’t play with it much to try to eliminate the sun from the effect, though.

I’m using a directional light. Eh happy to see i’m not the only one with that question :slight_smile:

Is your sun a quad with a texture on it or a sphere?



If it’s a quad then you will need to offset it so that it is centered over the sun coordinate or it won’t line up with the source of the light.

The effect is not centered on your sun (lightPosition is wrong). Note that is your sun is a quad it’s coordinate are the coordinate of its left bottom corner. Maybe you’ll have to offset the position a little.

If its a sphere, what coordinate I should use?

the center

Alright i’ll try that as soon as I can, i’ll let you know the results, thanks.

If it doesn’t work, please provide some code, so i can test it.

My sun is a quad with a scale of 170x170. It is following a circle path around the world , the directional light’s position is the same as the geom’s position. What would be the good offset to make it point at camera?



I tried modifying the X and Z position but it seems to be irregular depending of the camera’s position.

You change the code to do different things.



If we see the code then maybe we can be more specific. :wink:

Okay well here’s the light scattering effect:

[java]

FilterPostProcessor fpp = new FilterPostProcessor(mainScene.getAssetManager());

LightScatteringFilter lsf = new LightScatteringFilter(sun.getWorldTranslation());

fpp.addFilter(lsf);

mainScene.getViewPort().addProcessor(fpp);

[/java]



Where “sun” is a quad 170x170.

That code is missing the offset that I need to make it point at camera.



I tried adding/removing half of the scale to X, Y or Z coordinate to center the beams at the camera but it seems to make their direction irregular and unconstant.

example in the update method:

[java] lsf.setLightPosition(new Vector3f(sun.getWorldTranslation().x+85,sun.getWorldTranslation().y,sun.getWorldTranslation().z));[/java]

@magickrabbit said:
Okay well here's the light scattering effect:
[java]
FilterPostProcessor fpp = new FilterPostProcessor(mainScene.getAssetManager());
LightScatteringFilter lsf = new LightScatteringFilter(sun.getWorldTranslation());
fpp.addFilter(lsf);
mainScene.getViewPort().addProcessor(fpp);
[/java]

Where "sun" is a quad 170x170.
That code is missing the offset that I need to make it point at camera.


Sun should be a node with an offset Geometry underneath it. Since it's the sun quad that needs fixing, it is the sun quad that we need to see the code for.

Well the quad object is an instance of this class:

[java]

public class SkyBillboardItem extends Geometry{

private BillboardControl billBoadControl = new BillboardControl();

private Quad quad;



public SkyBillboardItem(String name, Float scale){

super(name);



quad = new Quad(scale, scale);



setQueueBucket(Bucket.Transparent);

setCullHint(CullHint.Never);



setMesh(quad);



addControl(billBoadControl);

}

}

[/java]



initialized with:

[java]SkyBillboardItem sun = new SkyBillboardItem("sun", 170f);[/java]



and this SkyBillboardItem object is a member of another class which extends Node( which is my real sun object ).

Then you need to offset the Geometry by 170 / 2. setLocalTranslation( -170/2, 0, -170/2)



The node will be the position of the sun. Right now you are setting the lower left corner of the sun, not its center. So it scatters up and right.

mhh the quad is in world space so you may have to compute the offset in world space and not in gui space.

something like cam.getWorldCoordinates(cam.getScreenCoordinate(sun.getLocaltranslation()).add(170/2,170/2,0));

@nehon said:
mhh the quad is in world space so you may have to compute the offset in world space and not in gui space.
something like cam.getWorldCoordinates(cam.getScreenCoordinate(sun.getLocaltranslation()).add(170/2,170/2,0));


Curious if you are seeing code that I haven't because I don't know how you can tell that the quad is in world space.

Edit: Ah, I see... you are having him move the light position to the incorrectly set sun position instead of fixing the sun position to be right.

Anyway, to the original poster, you say your have a geometry (SkyBillboardItem) under a node. If it's the node you position to be the sun then try offsetting the SkyBillboardItem as I suggested. If the billboarding gets funny then you can move the billboard control up a level to the parent. Basically, you want the Quad to be centered over 0,0,0 of some parent and it's the parent you will put at the sun position.