Jump to content
  • Advertisement
Sign in to follow this  
slugonamission

Lighting Systems

This topic is 4218 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

I've hit a bit of a stumbling block when trying to make a game engine. The problem here is lighting, and it needs to be done completely in HLSL. The problem is, how do I manage multiple light sources? I had an idea of storing them in a HLSL array, and then finding the closest lights to the object and passing them to the shader. The problem of simple directional lights, and spotlights facing in the wrong direction. What is the best way of implementing this kind of problem, and is there a different way to do it using a few rendering passes? Thanks in advance - Slug

Share this post


Link to post
Share on other sites
Advertisement
You could check out "deferred lighting" (aka deferred shading), which is a lighting technique that allows for any number of lights in a scene.

It also has the interesting property where 20 small spot lights can be faster than 1 large directional light (which is good or bad depending on your needs).

I'm currently playing with Horde3D, which currently comes with a GLSL implementation of this technique.

Share this post


Link to post
Share on other sites
Quote:
Original post by slugonamission
I've hit a bit of a stumbling block when trying to make a game engine. The problem here is lighting, and it needs to be done completely in HLSL.

The problem is, how do I manage multiple light sources? I had an idea of storing them in a HLSL array, and then finding the closest lights to the object and passing them to the shader. The problem of simple directional lights, and spotlights facing in the wrong direction.

What is the best way of implementing this kind of problem, and is there a different way to do it using a few rendering passes?

Thanks in advance - Slug


You can't do everything in HLSL. The rendering itself, yes, but you'll need to do some CPU work to do some basic light culling to determinate which lights affect which pieces of geometry.

The basic approach is:

- Write a shader which renders a single light, and reads the lights parameters from the constant registers.
- Turn additive blending on, then draw the said geometry once for each light, changing the shader constants for each light, based on their properties (position, color, radius, etc).

Before drawing the lights you either draw your geometry with some sort of ambient color, ambient lightmap or simply don't use the blending for the first light.

You can optimize things by using shaders which can draw more than one light at once (2, 3 or maybe more depending on your lighting shader complexity and shader model) to reduce the amount of passes, but this can get tricky if you have different types of lights (point, spot, directional).

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!