# [Solved] How can I set the direction of the Directional Light to light in the right way?

how can I set the direction of the Directional Light to light in the right way?

I want to have a directional light in pos (0,300,0) and use it to cast receive shadow, but it has not any set position method.
the black Square is my landscape.

Directional light dont have position.

it have just direction(that you should provide normalized) that affect all Node that is attatched to.

If you want limited range/positional, then use PointLight or SpotLight for example.

About directional light, see example in wiki:

``````DirectionalLight sun = new DirectionalLight();
sun.setColor(ColorRGBA.White);
sun.setDirection(new Vector3f(-.5f,-.5f,-.5f).normalizeLocal());
``````

and this -.5,-.5,-.5 is direction that is normalized

2 Likes

direction? from where to where? I think it a line with a start point and endpoint, am I right?

no, its a infinite line kind of.

you provide only direction

if you want line from->to, use PointLight or SpotLight

1 Like

I used point light but the shadow color was white color

odd, maybe you configured Shadow color somewhere as white.

or you modified static ColorRGBA.Black that affect everything other. (you should avoid it)

could you please show me this direction on an image? I cant understand.

no need image,

you can look at:

(if Y is UP axis)
[0,1,0] = Up
[0,-1,0] = Down
(if X is LEFT axis)
[1,0,0] = Right
[-1,0,0] = Left

etc.

If you use standard Y as UP, then usually you need light dir to have Y as minus value like:
[ANY_VALUE, -1f, ANY_VALUE].normalizeLocal()
where â€śANY_VALUEâ€ť will decide about â€śangleâ€ť

and normalizeLocal make UNIT Vector from it.
for example [15,5,5] is like [0.53, 0.17, 0.17] as normalized Vector.(direction vector - length need to be 1, so its not precise what i tell)

2 Likes

I think I found it, directional light is not a line of light, it is a bunch of light lines in a direction.

1 Like

technically its just one line used for each Fragment Shader.(like same line used each pixel)

RTX is something that use many.

1 Like

for completeness: if you want the direction based on your first image, this is the way to go:

``````Vector3f direction = new Vector3f(512, 0, 512).subtractLocal(new Vector3f(0, 300, 0)).normalizeLocal();
``````