0

I am building a game in XNA, but this question could apply to most 3D frameworks.

My scene contains several point lights. Each light has a position, intensity, color and radius. It also contains several objects that can be lit by the point lights.

I have successfully used a simple forward renderer to light objects these with up to 8 point lights at a time.

However, I also want to try some other effects, such as lit objects where the light slowly fades away each frame.

I want to use a multipass approach:

  • Each lit object has a texture and a lightmap (a rendertexture)

Then, each frame and for each object:

  • Clear the lightmap (or fade it)
  • Draw each light to the lightmap, with falloff etc.
  • Render the object using texture * lightmap in the pixel shader

My problem is related to texture coordinates. The lightmap should use the same UV mapping as the texture map, so that when I draw the objects, the color is:

tex2D(TextureSampler, uv) * tex2D(LightMapSampler, uv)

Or, put another way, I need to compute the world position of each pixel in the lightmap in the lightmap pixel shader for computing its distance to each light.

What coordinate transforms are required to achieve this?

sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
  • I know you said you don't want to use deferred shading but the process you are describing sounds a lot like deferred shading. Deferred shading operates in screen space and so avoids this problem. – gareththegeek Apr 10 '14 at 10:02
  • Deferred shading would require many changes to my game, and effects such as "lit objects where the light slowly fades" would be harder to achieve with a moving camera. – sdgfsdh Apr 10 '14 at 10:13
  • Usually, in forward rendering you would render each object light combination directly to the framebuffer, compositing the results of subsequent light passes. – gareththegeek Apr 10 '14 at 10:26
  • 1
    Yes. My requirements are unusual though, as I want to store the surface light of objects between frames. – sdgfsdh Apr 10 '14 at 11:37
  • Is your xna game actually 3D in terms of lighting or is it 2D? – selkathguy Apr 10 '14 at 19:01
  • It is in 3D, which makes things a bit more complicated! – sdgfsdh Apr 11 '14 at 08:38

0 Answers0