Deferred Shading and Texturing


I just stumbled across an issue with deferred shading, that I never heard of before.

When I apply the lights to the gbuffer, I draw screen-aligned quads, using an orthographic projection matrix.

Today I realized that this completely breaks mipmap selection for, say projected lights. Since ds/dx and dt/dy are not dependend on the surface I shade (the screen-quad is not the surface!), mipmapping seems to be disabled for the light´s texture (or any other texture I sample in the shading pass)?! The problem becomes especially apparent when sampling an environmap cubemap.

How to circumvent the problem?

And what about storing your derivatives within your gbuffer, at the same time as zbuffer for instance ?

I still have some space in the gbuffer :slight_smile:

So, what values would I have to store and how to use them in order to select the appropriate mipmap level?

I´m not confident in the maths of these derivates :frowning: