I am writing the part of code that renders a polygon with lightmap in 2 passes. I do not know if I should render the lightmap first or the texture first. I have referred to some sample code, and some of them render lightmap first. If I should render lightmap first, can anyone tell me why? I just want to get clear about it.
If all you’re doing is combining a lightmap L with a texture T, then what you’re calculating is LT. As you should know, this equals TL
If you have multiple lights, it makes more sense to paint all lights first, in accumulate (additive) mode. Once you’ve done that, you can modulate in the base texture map. The nice thing with this design is that it scales to as many lights as you want (with some loss of frame rate each time you get a new texturing pass, of course).
personally i find for light/detail maps using add_signed better than modulating. ie modulating is only gonna make things darker but with add signed u can make things darker + brighter. 0.5 == no change
I’d say, use both.
MODULATE for diffuse lighting and ADD_SIGNED for the ambiant light.
Preprocess the lightmap (diffuse lighting), then use it in texture unit 0 with ADD_SIGNED of some primary color (ambiant light) and modulate with a color map in texture unit 1.
This way, you keep control of both ambiant and diffuse lighting, something you wouldn’t be able to do otherwise.
That’s what I do in my terrain engine. You could also add the ambiant light at preprocessing time, I don’t do that cause I already use the texture combiners fully during preprocessing.