Archive 17/01/2023.

Render scene twice (or write to different render targets)

TheComet

In my game, objects have an emissive map. I want to render all objects just with emissive maps to a separate render target in addition to rendering the scene “normally”.

How do I do this?

Here is my render path:

[code]

<command type="clear" color="fog" depth="1.0" stencil="0" output="viewport" />
<command type="clear" color="fog" depth="1.0" output="RTEmissive" />

<!-- Render scene normally, then do a pass for every light -->
<command type="scenepass" pass="base">
    <output index="0" name="viewport" />
    <output index="1" name="RTEmissive" />
</command>
<command type="forwardlights" pass="light" />

<!-- Alpha is currently not needed
<command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
<command type="scenepass" pass="postalpha" sort="backtofront" />
-->

<command type="scenepass" pass="refract">
    <texture unit="environment" name="viewport" />
</command>

<!--  -->
<command type="quad" vs="BloomEmissive" ps="BloomEmissive" output="viewport">
    <texture unit="diffuse" name="RTEmissive" />
</command>
[/code]

I’m trying to write to gl_FragData[1] (which, from what I understand, would be RTEmissive in the base scene pass), but then the viewport just goes black.

My glsl code is pretty much this:

[code]void PS()
{
/* a whole bunch of shit */

gl_FragData[0] = finalColor;

#if defined(PREPASS)
gl_FragData[1] = emissiveMap;
#endif
}[/code]

And my BloomEmissive shader is currently this (copy RTEmissive framebuffer to viewport):

void PS() { gl_FragColor = vec4(texture2D(sDiffMap, vScreenPos).rgb, 1); }

artgolf1000

You may refer to https://github.com/MonkeyFirst/urho3d-light-scattering, there are lot of things to setup correctly.