Lighting on Terrain

Hey guys n gals.

I’m having a lot of fun writing a game, but there’s two things that I can’t figure out - and not for lack of fiddling.

Firstly, the easy one - probably a yes or no. I’m using point lights as brake lights in my vehicle, but the glow seems to go through the body of the car (including underneath). Is there any way to stop it? I’ve tried moving it around and what not, but it doesn’t seem to have any effect. I read that PointLight does not cast shadows - which is fine enough - but does that include the light emitted not being stopped by other meshes?

Secondly, I am using SpotLights for the headlights, but depending on the rotation of the vehicle, it appears to emit the light differently. I assumed it would be the “rotation” but i’ve attached it to the vehicle node using a LightControl - which as far as I am aware solves that problem.

good rotation: http://i.imgur.com/lvoyoUD.jpg
bad rotation: http://i.imgur.com/it0mhkY.jpg

[java]
float lightDip = FastMath.PI / 2; //1.27f;
float lightRotation = 4.6f;
float lightIntensity = 1.75f;
float foreDistance = 1.2f;

Vector3f position = new Vector3f(1.0f, 1.1f, 3.3f);

SpotLight hlrSpotLight = new SpotLight();
hlrSpotLight.setSpotRange(100f); // distance
hlrSpotLight.setSpotInnerAngle(9f * FastMath.DEG_TO_RAD);
hlrSpotLight.setSpotOuterAngle(35f * FastMath.DEG_TO_RAD);
hlrSpotLight.setColor(ColorRGBA.White.mult(lightIntensity));

LightControl hlrLightControl = new LightControl(hlrSpotLight);

Node hlrNode = new Node(“HeadLamp Right Node”);
hlrNode.addControl(hlrLightControl);
hlrNode.setLocalTranslation(-1.0f, 1.1f, 3.3f);
hlrNode.rotate(0f, lightRotation, lightDip);

vehicleNode.attachChild(hlrNode);
[/java]

Thanks in advance :slight_smile:

@jayfella said: Hey guys n gals.

I’m having a lot of fun writing a game, but there’s two things that I can’t figure out - and not for lack of fiddling.

Firstly, the easy one - probably a yes or no. I’m using point lights as brake lights in my vehicle, but the glow seems to go through the body of the car (including underneath). Is there any way to stop it? I’ve tried moving it around and what not, but it doesn’t seem to have any effect. I read that PointLight does not cast shadows - which is fine enough - but does that include the light emitted not being stopped by other meshes?

Well, if light gets stopped by other obects it would cast shadows, wouldn’t it? :wink:

As for number two: when seeing your code i was actually surprised that it even lit’s the terrain, i always assume that light would not lit parent elements in the scenegraph.
How you you generate the terrain? Could be an issue with normals/tangents. Just a shot in the dark

1 Like
@jayfella said: Firstly, the easy one - probably a yes or no. I'm using point lights as brake lights in my vehicle, but the glow seems to go through the body of the car (including underneath). Is there any way to stop it?

Bodies blocking light, that is sort of the definition of shadows, so I kind of suspect that the answer is no :slight_smile:

EDIT: Ninjad by zzuegg :slight_smile:

ok - so the first one is solved - yeah makes total sense lol.

Sorry, I attach the light to the rootNode, and attach the lightControl to the vehicle node. I missed that bit of code. I generate the terrain using noise and dynamically add them to the rootnode.

It was actually the normal map I was using for the grass texture that was causing the issue. I removed it and everything is working as it should. Thanks for the help btw. Surprisingly quick :slight_smile:

And do remember that with each extra light the scene gets rendered another me. By having two taillights and two headlights you are cutting the framerate dramatically.
If you want many lights, deferred rendering might be for you. At it’s own performance hit of course.