View Full Version : Lighting Textures?
09-21-2002, 10:01 AM
OK, I am able to use an actual light to light an area in my 3D engine, but how does one go about making a texture give off light? They mentioned it in the OpenGL Programming Guide, but I spent two fraggin' hours looking for how to specify which texture to give off light and found nothing. All they kept showing me was glMaterialfv() voer and over again with all the details. I know how to use that command, but how do I tell that command I only want texture "Light.tex" to give off light? Rock ground doesn't give off light and neither does Rustwall.
Another thing would be going beyond eight lights. I know it can be done (look at Unreal/UT), but in the guide it says only eight. I've seen over thirteen lights at once in Unreal (heck, I've seen close to forty on a few maps). How is it done? I know it isn't software because Unreal flies, even on the old P2/233 in the bedroom. How can I allow a larger number of lights to be used? Heck, if you can answer this question I may not even bother with the first one.
09-21-2002, 10:59 AM
How can you use more than 8 lights? Easy. There are a few different ways. Some being, multipass, vertex programs, software. But then again, you rarely need more than 8 at a time. Think back to your example UT. Did you really see any polygons being lit by 40 lights? Or did you see lots of polygons being lit by a few lights near to them?
[This message has been edited by DFrey (edited 09-21-2002).]
09-21-2002, 07:49 PM
I can get a screenshot with plenty of lamps in it, all emitting light. "Na Pali Haven" is a prime example. Oh and the mountain fortress has a few scenes with, God, at least eighteen or more! These are single player/coop maps from Unreal/Unreal Gold that I am mentioning.
Anyways, how would these other methods work? The only way I know to enable/initialize a light is in the OpenGL initialization. I initialize OpenGL each time a map loads, and that's it. So if a large map has two-hundred lights in it, how would I do this? This is where I am being thrown. How do I know when to light what?? I also want to know how to make specific textures emmit light, such as a texture named "Light". This way (unless I misunderstood) I can do a lot of level lighting with textures, and then use actual lights for eye-candy.
Seeing objects that represent lights isn't the same as having actual lights. For example, a decorated christmas tree may show 200 lights, but noone is going to render a scene lit by this tree with 200 actual lights.
In order to render a scene with a light you do two things:
1. set up an actual light (or more) that will light the rendered polys
2. draw something that represents the light at the light position (very simple: a white sphere to simulate a lightbulb).
When rendering the light-representation, you may want to disable lighting calculations and draw with a pure assigned color (white or yellowish -- depending on the used color of the light).
Large scenes that use more than a few lights will render groups of polygons while enabling only the relevant lights (i.e. closest to them wrt intensity). Usually just a few lights are really relevant per polygon, so the available 8 are more than enough. When really needing more than 8 lights for a single polygon, you will have to use multipass rendering.
09-23-2002, 03:23 AM
Unreal doesn't use OpenGL lights. Most of the lighting in Unreal/UT is precalculated into lightmaps, textures that contain lighting information. The lighting on dynamic objects like characters running around is done in software, so OpenGL isn't involved at all. Still, I seriously doubt you'll see the difference with more than 8 lights lighting a single character. If you want more info on light maps look in this sites FAQ or search google or flipcode.com.
09-23-2002, 01:16 PM
I map for Unreal/UT, and to make a light, you HAVE to place a light into the map. This of course lights an area based on the luminesance and other settings you choose. How is this a "light map" and exactly what is one? Since my game is OpenGL ONLY (like Morrowind is DX ONLY), I was trying to use OpenGL to the max to both optimize performance and keep the detail high. Fromw hat I understand though, I'll need to write my own software lighting app? If that's the case how the heck do I use OpenGL to render my scene? If it is lit in software just draw it in software. I don't see how two seperate modes can be combined is what I am saying.
Right, the concept you are on about is lightmapping (or as some people, note, darkmapping - but lets not confuse the issue). The principle behind it is a pre-processing step that takes all the time it needs to calculate the light contribution from whatever lights are in the world onto whatever polygons they influence. This contribution is then stored in a (usually greyscale) image. Thus, when rendering your scene with OpenGL you can draw a wall with whatever texture is on it (say brick) and then you multiply this by your greyscale light map image. So you have:
brick * lightmap.
Now, you can imagine that if your light calculation program decided that no contribution came from a light to a surface, it would put black in the lightmap, i.e. zero. So, when you do that multiplication of brick * lightmap for a non-lit polygon, you get zero. Darkness. Absense of light. If your light calculation processing step decided that there was plenty of light on the polygon (say, because in your map editor you'd just put a great big torch next to the wall) the lightmap image would be composed mainly of white, i.e. ones. So, your brick * lightmap calculation would yield a highly visible and lit wall. Understand that this is pre-computed effectively static lighting (you can't influence it at runtime - when was the last time you blew up a light in Unreal?). This lightmapping technique does provide high detail and quick performance, but as I said you are basically limited to non-interactivity with lighting.
It's a bit late here so I hope I havent screwed up too much, but I hope that's cleared up some stuff for you.
09-24-2002, 11:20 AM
Dude, you cleared it up nearly perfectly. I now udnerstand what lightmapping is and how to use it. You CAN blow up lights in Unreal, but I think that when you do, based on what you just told me, it stops applying the lightmap to the textures that the specific light affected. I think I could handle coding that as well. This would save my dynamic lights for things like projectile shots that glow. Thanks a heap, I'll post a new thread if I need any advice.
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.