Advertisement

Deferred Texture Projections - Gradients

Started by October 23, 2019 06:49 PM
1 comment, last by MJP 5 years, 3 months ago

Hi,

is there any solid solution to get correct texture sampling with mipmaps when projecting a texture deferred? I always get artefacts on the edges when objects are in front of the projections. I think there must be a common way, as other engines also support deferred decals and stuff.. so this also needs to filtered correctly.

 

You can get 100% correct gradients if you store the screen-space X/Y derivatives of depth in your G-Buffer, then use those to reconstruct the surface position derivatives. After that you need to transform the positional derivatives into decal UV derivatives. It adds quite a bit of per-pixel calculations, but it's definitely doable. I did it for my deferred texturing/decals demo and was even able to use anisotropic filtering. Start here, then follow the code through to here.

For something cheaper, you can just build a function that chooses the mip level based on distance from the camera to the pixel as well as the size and scale of the decal texture(s), then pass that mip level to SampleLevel. This will generally give you worse quality mip selection than proper derivatives, and won't let you use anistropic filtering. But it will let you avoid edge artifacts, and it can be pretty cheap.

This topic is closed to new replies.

Advertisement