Game Development Community

Lit' objects are black

by Apurva Amin · in Torque X 2D · 10/30/2007 (8:35 am) · 6 replies

Hi,

I tried searching, but couldn't really find any relevant information. I want to use the light engine in TX to allow me to make a room pitch black with some light emitting from a torch. The torch aspect isn't too important as I can probably figure it out once I get this problem solved. I can't seem to get basic lighting working. At the moment, I have a "Blank Scene Object" as a light emitter. I gave it the LightRegister component so that it could emit light. I then give the surrounding objects a material which has the 'Lighting' box ticked. However, anything that has 'Lighting' ticked comes up black when I run the game. Other objects, which do not have 'Lighting' ticked, are fine. Any ideas what I'm doing wrong? Do I have to add another material on to the original?
Thank you

#1
10/30/2007 (10:14 am)
This should work, but I think you need some more setup on the materials. I'll need to think about it some more.

However, if you want a quick & dirty solution, you might consider something like this. This is a simple effect that took about 10 minutes to put together. Here's how the effect looks in my chopper test game.
aycu34.webshots.com/image/29833/2001914448685741798_rs.jpg
Here's the short steps to get the effect.
1. Create a black square in photoshop or something with a transparent backgound and then cut out a hole in the middle. Save the file as .png to keep the alpha layer.
aycu19.webshots.com/image/31058/2005086348571494360_rs.jpg
2. Add the cutout to Torque X Builder and then drop it in the scene at a low layer level (above items to be hidden).

3. Resize the cutout material to fill the scene. My example sizes it to 175x175.

4. With the cutout selected in the scene, open the Scene Object rollout properties and uncheck the Collision checkbox. (dont want to collide with the cutout)

5. Click the edit mount point for the cutout and set a mount point at the center of the cutout hole.

6. Mount the cutout material to your torch, player, camera, etc. You can do this in Torque X Builder or in code. My example mounts the cutout to the player in Torque X Builder. And in code I mount the camera to the player to follow.

That's it. Now you can roam around the scene and only see whats around you. Kinda torch-like - but without setting up all the lighting material properties.

John K.
#2
10/30/2007 (2:48 pm)
Thanks John, that's a nice way of doing it. I guess that would be fine in my case. However, just for future reference, any ideas as to why the objects come up black?
#3
10/30/2007 (5:45 pm)
It's most likely because you have no normal map.

Try creating an image the same size as whatever you are lighting filled with the color 128, 128, 255 and set it as the normal map.

Either that, or write your own shader that doesn't require it.
#4
10/31/2007 (3:47 am)
Thanks for the reply. I created the image with those colour settings and it worked! Now I just need to mess aroud with the normal map to get nice effects.
#5
11/06/2007 (11:26 pm)
In 1.0 lighting was per-vertex only for whatever reason. Even with the new lighting system in 2.0 (thank Adam) which supports both per-vertex and per-pixel lighting in 2D and 3D, with no normal maps you won't get very descriptive highlights when lighting 2D objects because they are actually planes and have no surface features in 3D space (2D is rendered in semi-3D space with an orthographic projection). With decent normal maps, the new per-pixel lighting looks phenomenal in 2D.

There are also several other bugs in the 1.0 lighting system in regards to light intensity scaling in the opposite way you'd expect when moving lights/objects or adding/removing lights.

EDIT: I realized that I didn't mention this, but the bugs that I pointed out in the second paragraph have been addressed in 2.0. Sorry if that was ambiguous.
#6
11/08/2007 (7:27 pm)
There is per-pixel lighting in 1.0 or the normal maps wouldn't even work.

I'm glad to hear some of the bugs in the lighting system are being taken care of. What I'd most like to see, though, is multi-pass rendering so that unlimited numbers of lights can be used in a scene, because at present, there is a maximum of 6, if I recall correctly, and when any more lights are used, some really funky switching between them occurs due to LightManager.GetBestLights().