Sign in to follow this  
secondwtq

Questing regarding decals in Deferred/Forward+ pipelines.

Recommended Posts

Hi, 
 
I'm currently deciding which kind of shading pipeline to get into. Now that I know the common pros/cons of forward and deferred shading, I'm leaning towards the Forward+ method for the sake of flexibility in materials and transparency (and there are only dozens of lights in my scene, for which I don't think it need to be deferred). But I also want decals which can add lots of interesting details to the scene. IIRC it can be done fast and cleanly with Screen Space Decal (or whatever it's called) with deferred. However as I read in several threads that modern forward shading can render decals too.
 
Is it true? If so, How is it implemented? I have searched around but found no material about how it's done. (most papers and articles focus on how to render thousands of lights in real time, decals is more likely to be an 'addon', rather than a core feature of the pipeline after all) Actually I found something that may be useful like what's used in Doom 2016, but it's still a little vague to me on how it's done specifically.
 
So below is my guess (in pseudo code):
 
CPU Side:
#in each frame
    construct data structures for all lights
    construct data structures for all decals
    for each object in scene:
        render(object)
    do post processing etc.
 
Shader (called for every object):
surfaceData = sample textures etc.

for each decal affecting this pixel:
    decalSurfaceData = something similar to Screen Space Decal
    surfaceData = blend(surfaceData, decalSurfaceData)

for each light affecting this pixel:
    BRDF = computeBRDF(light, surfaceData)
    outColor = blend(outColor, BRDF)
(so basically you do the same as what's done to lights to cull decals, and has two loops in the forward shader, one for decals, another for lights)
 
And just for my curiosity, How is decals handled in a 'classic' forward engine? Is it just some quads sticked onto the surface (and you have to deal with all kinds of problems like surface matching, Z-fighting etc.) ?
Edited by secondwtq

Share this post


Link to post
Share on other sites

What you've described is the gist of it. If you want to see a working implementation of these technique you can check out my deferred texturing demo. It uses DX12, and so it makes use of dynamic texture indexing to sample the approapriate decal texture data given an index. However you can also use texture arrays or atlases if you're working with a platform that doesn't support descriptor indiexing.

 

Old-school details were just transparents rendered on top of the opaque geometry. The hard part was constructing geometry that could do that without z-fighting, which was typically done by duplicating the opaque geometry and clipping. This presentation gives a quick overview of the problems of traditional decals, and also explains how projective decals can nicely avoid that issue. The other issue from old-school details is that you have too full shade, light, and blend the decals into your render target. A deferred decal avoids this entirely by apply the decal before lighting is computed, and also performs the blending in registers instead of in memory.

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