Skip to content

Stepping through post geom deferred rendertargets and uniform sampler binding

Shyotl edited this page Jul 31, 2012 · 2 revisions

//TARGETs are unbound on FLUSH
//About INPUT:
//    The lightMap sampler conditionally either binds mDeferredLight.mTex[0] or mScreen.mTex[0].
//    This is done to avoid binding the same texture thats being written to. (via pingpong)
//    lightMap[0] represents the lightMap sampler having bound mDeferredLight.mTex[0]
//    lightMap[1] represents the lightMap sampler having bound mScreen.mTex[0]
// Additionally, although a table is provided below, there are cases where these uniforms
//    manually have arbiturary textures bound to them. Such exceptions are denoted as "UniformName=BoundTexture"

//This table easily associates uniform indexes(used in code) with uniform names(used in shaders) and textures
// that are normally bound to the uniforms. RTT denotes RenderToTexture, meaning the respective RenderTarget writes to it.

//Uniform index    |    Uniform Name    | Texture(s) bound to uniform:            
DEFERRED_DEPTH         "depthMap"         RTT: mDeferredScreen.mDepth
DEFERRED_NORMAL     "normalMap"         RTT: mDeferredScreen.mTex[2]
DEFERRED_POSITION    "positionMap"        DEAD CODE
DEFERRED_DIFFUSE    "diffuseRect"         RTT: mDeferredScreen.mTex[0]
DEFERRED_SPECULAR    "specularRect"     RTT: mDeferredScreen.mTex[1]
DEFERRED_NOISE        "noiseMap"         Static image mNoiseMap. Random noise. Programmatically generated.
DEFERRED_LIGHTFUNC    "lightFunc"         Static image mLightFunc. Blinn phong lookup table. Programmatically generated.
DEFERRED_LIGHT        "lightMap"         RTT: (mDeferredLight OR mScreen).mTex[0]
DEFERRED_BLOOM        "bloomMap"         RTT: mGlow[1].mTex[0]
DEFERRED_PROJECTION    "projectionMap"    Per-Emitter light texture

PROCEDURE: LLPipeline::renderDeferredLighting
    IF("RenderDeferredSSAO" || "RenderShadowDetail")
        TARGET: mDeferredLight
        CLEAR: White
        SHADER: gDeferredSunProgram (sunLightV+sunLightSSAOF)
        INPUT: "depthMap", "normalMap", "noiseMap" //Also includes shadowmaps if class2.
        OUTPUT: "lightMap[0]"
        FLUSH: mDeferredLight
    END
    IF("RenderDeferredSSAO")
        PASS1:
            TARGET: mScreen
            CLEAR: White
            SHADER: gDeferredBlurLightProgram (blurLightV+blurLightF)
            INPUT: "lightMap[0]", "depthMap", "normalMap"
            OUTPUT: "lightMap[1]"
            FLUSH: mScreen
        END
        PASS2:
            TARGET: mDeferredLight
            CLEAR: White
            SHADER: gDeferredBlurLightProgram (blurLightV+blurLightF)
            INPUT: "lightMap[1]", "depthMap", "normalMap"
            OUTPUT: "lightMap[0]"
            FLUSH: mDeferredLight
        END
    END
    ALWAYS
        TARGET: mScreen
        CLEAR: BLACK
        IF("RenderDeferredAtmospheric")
            TARGET: mScreen
            SHADER: gDeferredSoftenProgram (softenLightV+softenLightF)
            INPUT: "lightMap[0]" "diffuseRect" "specularRect" "normalMap" "depthMap" "environmentMap" "lightFunc"
            OUTPUT: "lightMap[1]"
        END
        CALL: renderGeomPostDeferred
            TARGET: mScreen
            OUTPUT: "lightMap[1]" (Via blend)
        END
        IF("RenderLocalLights")
            TARGET: mScreen
            SHADER: gDeferredLightProgram (pointLightV+pointLightF)
            INPUT: "diffuseRect" "specularRect" "normalMap" "environmentMap" "noiseMap" "depthMap" "lightFunc"
            OUTPUT: "lightMap[1]" (Via blend)
        END
        FLUSH: mScreen
    END
END
PROCEDURE: LLPipeline::renderBloom
    ALWAYS //Glow extract.
        TARGET: mGlow[2]
        CLEAR: Black
        SHADER: gGlowExtractProgram (glowExtractV+glowExtractF)
        INPUT: "lightMap[1]" //Manual bind of mScreen color texture
        OUTPUT: mGlow[2].mTex[0]
        FLUSH: mGlow[2]
    END
    LOOP RenderGlowIterations
        PASS1:
            TARGET: mGlow[0]
            SHADER: gGlowProgram (glowV+glowF)
            IF(FIRST_ITERATON)
                INPUT: mGlow[2].mTex[0]
            ELSE
                INPUT: mGlow[1].mTex[0]
            END
            OUTPUT: mGlow[0].mTex[0]
            FLUSH: mGlow[0]
        END
        PASS2:
            TARGET: mGlow[1]
            SHADER: gGlowProgram (glowV+glowF)
            INPUT: mGlow[0].mTex[0]
            OUTPUT: mGlow[1].mTex[0] AKA "bloomMap"
            FLUSH: mGlow[1]
        END
    END
    IF(RenderDepthOfField)
        ALWAYS //DoF Circle of confusion(CoF)
            TARGET: mDeferredLight
            SHADER: gDeferredCoFProgram (postDeferredNoTCV+cofF)
            INPUT: "diffuseRect=lightMap[1]" "depthMap" "bloomMap"
            OUTPUT: "lightMap[0]"
            FLUSH: mDeferredLight
        END
        ALWAYS //Half-res sampling
            TARGET: mScreen
            SHADER: gDeferredPostProgram (postDeferredNoTCV+postDeferredF)
            INPUT: "diffuseRect=lightMap[0]"
            OUTPUT: "lightMap[1]"
            FLUSH: mScreen
        END
        IF(FXAA)
            TARGET: mDeferredLight
            SHADER: gDeferredDoFCombineProgram (postDeferredNoTCV+dofCombineF)
            INPUT: "diffuseRect=lightMap[1]" "lightMap[0]" <-- sampling lightMap[0] is undefined behavior as mDeferredLight draws to it!
            OUTPUT: "lightMap[0]"
            FLUSH: mDeferredLight
        END
        ELSE
            TARGET: Main Framebuffer
            SHADER: gDeferredDoFCombineProgram (postDeferredNoTCV+dofCombineF)
            INPUT: diffuseRect=lightMap[1]" "lightMap[0]"
            OUTPUT: Main Framebuffer
        END
    END
    ELSE
        IF(FXAA)
            TARGET: mDeferredLight
            SHADER: gDeferredPostNoDoFProgram (postDeferredNoTCV+postDeferredNoDoFF)
            INPUT: "diffuseRect=lightMap[1]" "bloomMap"
            OUTPUT: lightMap[0]
            FLUSH: mDeferredLight
        END
        ELSE
            TARGET: Main Framebuffer
            SHADER: gDeferredPostNoDoFProgram (postDeferredNoTCV+postDeferredNoDoFF)
            INPUT: "diffuseRect=lightMap[1]" "bloomMap"
            OUTPUT: Main Framebuffer
        END
    END
    IF(FXAA)
        ALWAYS //Glow Combine
            TARGET: mFXAABuffer
            SHADER: gGlowCombineFXAAProgram (glowcombineFXAAV+glowcombineFXAAF)
            INPUT: "diffuseRect=lightMap[0]"
            OUTPUT: mFXAABuffer.mTex[0]
            FLUSH: mFXAABuffer
        END
        ALWAYS //FXAA
            TARGET: Main Framebuffer
            SHADER: gFXAAProgram (postDeferredV+fxaaF.glsl)
            INPUT: "diffuseMap=mFXAABuffer.mTex[0]"
            OUTPUT: Main Framebuffer
        END
    END
END

Clone this wiki locally