# Directional lighting

Hey, I have a problem with understanding the directional lighting. When I load up my scene I have 2 houses and in the middle of those houses I have a road spatial. Here is the code:

house.setLocalTranslation(new Vector3f(-6, 0f, 0f));

house2.setLocalTranslation(new Vector3f(6f, 0f, 0f));

rootNode.attachChild(house);

rootNode.attachChild(house2);

DirectionalLight sun = new DirectionalLight();

sun.setDirection(new Vector3f(00.f, 0.0f, 0.0f));

When I have the light direction set to (0.0f, 0.0f, 0.0f) I don’t see anything in the scene but when I change it to (-0.1f, -0.1f, -0.1f) I see the 3 spatials. I don’t understand how this light is working.

From the jME light article it says “A DirectionalLight has no position, only a direction. It sends out parallel beams of light”. I don’t understand how using this:

sun.setDirection(new Vector3f(-0.1.f, -0.1f, -0.1f));

tells the sun which direction to point in. Could someone please explain this to me? Thanks in advance.

Well, 0,0,0 means the directionlength is null (no direction given), imagine a light ray from the sun to earth, now imagine it with lenght 0, thats wha the 0,0,0 does. Since no direction is specified, the engine does not know wich sides of the objects to light.

Ok so if I put it at 1, 0, 0 that means the light will be shining in from my right? And if I put it at 1, 1, 0 the light will be coming from the right and pointing upwards at the same time?

somewhat like that yes, (i sometimes get mixed up with the wich way x is positive ^^ , but the upwards for sure)

Just try if it works as expected. (also think about the tangents → wiki or forum search ) as they might be needed for proper lighting)

Is there any difference between -1, -1, -1 and -100, -100, -100 since the coordinates are only making it point in a direction?

it should not. (Actually the constructor normalizes them)

Code:
direction.set(dir); if (!direction.isUnitVector()) { direction.normalizeLocal(); }
@EmpirePhoenix said:
it should not. (Actually the constructor normalizes them)
Code:
direction.set(dir); if (!direction.isUnitVector()) { direction.normalizeLocal(); }

That's hilarious. "Let's do a square root to avoid doing a square root."

Since the directional lighting has no position where exactly does the light start coming from? or if you had a map 1000 x 1000 world units and you set the light direction to be -0.1, -0.1, -0.1 it will light up all the spatials across that scene on there right hand side? Thanks.

Yes, it is meant likeif you have a usualy level (imagine counter strike) the sun is so far away (theoretically), that you wont see any difference between a pointlight and a directionallight. (But it simplifies calculations)

Ok thanks. One more thing, is setting the directional light vector to -0.1, -0.1, -0.1 any different to setting it to lets say -15.0f, -15.0f, -15.0f since you are not specifying a location and only a direction?

A direction vector has a length of 1

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

@metallicalive said:
Ok thanks. One more thing, is setting the directional light vector to -0.1, -0.1, -0.1 any different to setting it to lets say -15.0f, -15.0f, -15.0f since you are not specifying a location and only a direction?

And, empire already answered this question. If you don't know what "normalized" means then definitely go through the math tutorial normen linked. More than once, probably.

Look at point lights and compare them to directional lights. That might help illuminate things for you (all puns intended).