Lighting

Started by
1 comment, last by pcmattman 15 years, 4 months ago
Hi everyone, I'm facing some problems writing my game with lighting. At the moment, I use the Quake3 BSP format which allows me to also use lightmapping. This is nice, but I also want to use dynamic lights. I've thought about per-pixel lighting and can support it using my shader objects, but I already have an effect file for my maps (which surrounds map geometry rendering). If I want to light the map as well with my per-pixel lights (say, for a simple example at the moment, a flashlight) how do I combine the effect and my vertex/pixel shader combo to get light? Also, how do I get more than one per-pixel light working? As far as I can tell it involves rendering the scene for each light, but that sounds like a lot of processing. As you can probably tell I'm a little confused! Any help would be greatly appreciated.
Advertisement
Light isn't the problem, shadows are :)

Well, lights just sum up. I don't know the q3 engine, so my assumption is, that you got a texture and a separated (gray scaled) lightmap. It is possible to process more than one light with a single pass. Then you have to do something like this:

Convention:
You need one object independent space where you could set the light data (direction or position). World space or camera space is perfect. Lets choose world space.

Vertex Shader extension:
Transform your normal(half-vector), eye-vector and position to world space and tranfer this data to your fragment shader.

Fragment Shader extension:
Each light data(direction or position) has been set as parameter. Now calculate for each light its light data (diffuse, specular...) in world space according to your transfered normal,half-vector,eye-vector and position.

The final color should look like:
vec3 final_color =
//texture color
texture.rgb *
//diffuse factor including ambient and lightmap
(light_data[0].diffuse+ .. +light_data[n].diffuse+ ambient + lightmap) +
// specular
(light_data[0].spec+ .. +light_data[n].spec);

This is just a raw concept, extend and optimize at will :)

--
Ashaman
I completely forgot about the ability to use arrays in shaders. Thanks for bringing that up.

I'll try to implement a single light with constant parameters at first and once I have that working I can work on a more complicated interface that allows me to have multiple lights.

My main worry was trying to do this in an abstract way, but if I simply keep track of all the lights in a level I can tell the shaders for different objects (and level geometry) which lights to use.

Thanks!

This topic is closed to new replies.

Advertisement