Jump to content
  • Advertisement
Sign in to follow this  


This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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:

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 :)


Share this post

Link to post
Share on other sites
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.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!