Sign in to follow this  
pondwater

Forward rendering light accumulation for 2D transparent sprites

Recommended Posts

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this