Game Development Community

Guys - Need help on advanced lighting question

by Rich Hudson · in Torque X 2D · 03/14/2009 (7:59 am) · 9 replies

I have been messing with material + T2DLightComponent properties, trying to get the lighting "just right" for a dungeon iso game. Man is it hard to tweak it right. I have a screenshot of what I have right now here:


http://photoshare.shaw.ca/view/17180751994-1237042612-64359/

Now what I want is the level to basically be "dark" and have the hero's light source illuminate an area around him. Torches which I have just finished creating should do same, only light up area around them. I want it realistic basically.

Any thoughts?

#1
03/14/2009 (12:05 pm)
Here is my progress, getting closer....

http://photoshare.shaw.ca/view/17180796006-1237057313-22731/

what I am thinking of doing is creating a top layer (below gui obviously) which is solid black tiles, then depending on the light radius of the light source held, making them translucent as the player moves around him - like a fog of war. We will see how that goes.

But still looking for suggestions on what others have done.
#2
03/17/2009 (7:05 am)
Hey Rich, the game looks pretty awesome so far!

For the lighting, do you have any ambient lighting sources? I am thinking if you turn off any ambient lighting in your sources and increase the drop-off rate (linear or whatever you are using) the light should only affect things very near to it.

Also, if you're not already mounting the light to the player, you can do that so it's like the player is 'carrying' the torch. Actually, if you really want to go crazy, you can dynamically adjust the drop-off rates of the light in code to try and emulate the flickering effect of a real torch. But doing so I imagine you run the risk of it being distracting.

- Alex
www.stinkerstudios.com
#3
03/17/2009 (4:30 pm)
Rich,

I'm trying to do something similar in a deep sea sub game. Are there any write ups that you have found helpful? I don't have the 2d lighting tutorial, nor have I found it available anywhere. I'm really having a hard time figuring out how normal maps and the T2DLightComponent works.

I have a player sprite, and I can make normal maps. I've created a blank scene object and given it the T2DLightComponent. I just don't understand how to link the normal maps to the player or any other material that should illuminate.

Any help would be appreciated. Thanks!

Toby
#4
03/17/2009 (6:48 pm)
OK here is what I have done:

I have a sprite with a T2DLightComponent. Its supposed to be a "torch" , here are my settings from top to bottom:

Torch
1.0 - Constant Atenuation
1.0

0
1
8

0
0 - ambients
0

10
6.5 - diffuses
1

(make sure you click the little green button to ADD it to the lights list)

however I am still messing with these numbers. So play with them. The diffuse number = light source color and ambient is the surroundings color.

OK now for the background material. You need to create a normal map (I use a plugin for GIMP 2.0). Once you do that open your material in TXB and enable the "Enable lighting". Then under normal map select your normal map. This will copy it over to your projects data folder so recompile the solution in VS2005. For specular and Intensity I have .750 and .250, play with these for the surfaces reflectiveness.

let me know if you have other questions.

#5
03/17/2009 (7:07 pm)
Alex,

Thanks for comment - seem to spend most of my time on small API related issues =(

Yeah I have ALL my lights set to 0,0,0 for ambient, but color still bleads throughout the level.
#6
03/18/2009 (11:07 am)
@Rich

Try setting your ConstantAttenuation to 0 and your LinearAttenuation to something like 5.0. This should create a very narrow light source.

I am wondering if maybe the width of your camera is small enough that your current Attenuation settings are reaching the edges of the screen before totally cutting off.
#7
03/18/2009 (9:04 pm)
@Rich

Thanks so much for your post. I think we may have very different versions as I don't have some of the options you list. I'm using Torque2D version 1.1.5 and TXB version 1.0. Our kit is controlled by our school so we aren't allowed to upgrade.

At any rate, I've been able to get some minor lighting effects on my player and I'm getting more confident about how it works. I have one issue where one of my materials turns completely black when I enable lighting on it. It has a normal map and looks fine if enable lighting is unchecked. Any ideas?

BTW, I'm using Crazy Bump to make my normal maps.
#8
03/20/2009 (10:40 am)
No I am not sure why that would happen. I am using TX 2.0 so yeah things will be different for us and you might be seeing an old bug in there.
#9
03/22/2009 (6:10 pm)
In case anyone is interested - I finally got a working torch light, which only lights the area around the torch.

So for the TD2LightComponent (in order of setting):

(PointLight)
0.0
4.0

0.0
0.0
5.0 - z

0.0
0.0 - ambients
0.0

4.0
2.6 - diffuse
0.4

enabled = true

This is on a normal map of 4-sample.

Thanks to Alex for pointing me in right direction with first two values.