Forward rendering light accumulation for 2D transparent sprites

Started by
-1 comments, last by pondwater 11 years ago

I'm writing a little rendering engine for 2D sprites incorporating dynamic lighting via normal maps. For opaque sprites I’m using deferred rendering. I'm attempting to include forward rendering for transparent sprites.

For the forward rendering, since I cannot take advantage of the depth buffer (since all sprites are on the same Z-plane), I’m not sure how to accumulate lights properly to prevent bright patches where sprites overlap.

What I’ve currently been doing is simply iterating over each transparent object for each light, accumulating the fragments using additive alpha. For this I either turn off depth testing, or set it to GL_LEQUAL. It doesn't really matter because all quads are drawn on the same Z plane so depth testing is irrelevant.

My problem comes into when two transparent objects intersect. Normally for opaque objects the sprite drawn last overwrites whatever is in the G-Buffer, which is what I want. However, for forward rendering, the additive blending of the lights causes bright patches where the sprites overlap.

So my problem boils down to: for individual transparent sprites the light must be accumulated with alpha blending, and between transparent sprites they should be combined using conventional alpha*S + (1- alpha)*D blending.

The only way I can think to accomplish this is to clear and fill an individual FBO for each transparent sprite. I clear the FBO, render an individual transparent object accumulating each light with additive blending, then alpha blend that with my final buffer from my deferred renderer. Clear the FBO, and begin rendering the next transparent object, and so forth.

This seems horrifically inefficient. What is the proper way to do this?

This topic is closed to new replies.

Advertisement