Archive 17/01/2023.

Light scattering

codingmonkey

Hi folks!
How I may to render some of scene’s object into MRT-render target ?
I tried to create an tech NoTextureUnlitMRT1.xml

<technique vs="Unlit" ps="Unlit" psdefines="MRT1" vsdefines="NOUV" >
    <pass name="base" />
    <pass name="prepass" psdefines="PREPASS" />
    <pass name="material" />
    <pass name="deferred" psdefines="DEFERRED" />
</technique>

then i add MRT1 checking with (#if #else #end) barricades in unlit.glsl shader

    #if defined(PREPASS)
        // Fill light pre-pass G-Buffer
        gl_FragData[0] = vec4(0.5, 0.5, 0.5, 1.0);
        gl_FragData[1] = vec4(EncodeDepth(vWorldPos.w), 0.0);
    #elif defined(DEFERRED)
        gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
        gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
        gl_FragData[2] = vec4(0.5, 0.5, 0.5, 1.0);
        gl_FragData[3] = vec4(EncodeDepth(vWorldPos.w), 0.0);
    #else
        #ifndef MRT1 
            gl_FragColor = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
        #else
            gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
            gl_FragData[1] = vec4(1.0);
        #endif
    #endif

fix Transform.glsl to avoid gl_FragData boundary error

// Silence GLSL 150 deprecation warnings
#ifdef GL3
#define varying in

// \todo: should not hardcode the number of MRT outputs according to defines
#if defined(DEFERRED)
out vec4 fragData[4];
#elif defined(PREPASS)
out vec4 fragData[2];
#else
#ifdef MRT1
out vec4 fragData[2];
#else 
out vec4 fragData[1];
#endif
#endif

and finally I got a Render Path

<renderpath>
    <rendertarget name="MRT" sizedivisor="1 1" format="rgba" filter="true" />
    
    <command type="clear" color="fog" depth="1.0" stencil="0" >
        <output index="0" name="viewport" />
        <output index="1" name="MRT" />
    </command>
        
    <command type="scenepass" pass="base" vertexlights="true" metadata="base" >
        <output index="0" name="viewport" />
        <output index="1" name="MRT" />
    </command>
    <command type="forwardlights" pass="light" />
    
    <command type="scenepass" pass="postopaque" />
    <command type="scenepass" pass="refract">
        <texture unit="environment" name="viewport" />
    </command>
    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
    <command type="scenepass" pass="postalpha" sort="backtofront" />
    
    <!-- preview MRT -->  
    <command type="quad" tag="MRTTag" vs="CopyFramebuffer" ps="CopyFramebuffer" blend="replace" output="viewport">
        <texture unit="diffuse" name="MRT" />
    </command>
    
</renderpath>

In last RP commands I just copy MRT into screen for debug view.
but this is not working properly, if I try to decrease size of MRT for example to sizedivisor=“2 2”.

How to fix this?
Is it possible to use MRT various size ?

1vanK

Is it possible to use MRT various size ?

buffers should be same size

[spoiler]http://steps3d.narod.ru/tutorials/mrt-tutorial.html

??? ???, ??? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ? ??? gl_FragColor ? gl_FragData.[/spoiler]

codingmonkey

buffers should be same size
:cry:

current process with mrt

you may finding this there: github.com/MonkeyFirst/urho3d-light-scattering
main changes:
shaders\Transform.glsl (fixed with adding - out vec4 fragData[2]:wink:
shaders\Unlit.glsl (fixed for #ifdef MRT)
shaders\SunMRT.glsl (added)
ForwardSun.xml (added)
ForwardSunFast.xml (added)

Modanung

Looking good! :slight_smile: