Welcome, Guest.
Username: Password: Remember me

TOPIC: BackBuffer and RenderTarget at one pass?

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #1

Is it possible to write to two outputs at one pass?

I'm trying to make interlaced effect, but current solution has two full-screen resolution render targets.
One to bypass effect and get raw BackBuffer image stored,
second to write that stored raw BackBuffer at the end of the shader to get previous frame without any effects applied.



Code:
Warning: Spoiler! [ Click to expand ]
Last Edit: 5 months 2 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #2

See MXAO code on official github repository how to write to multiple render targets (first pass writes to 3), only limitation is that they have to be of the same resolution. If it's possible to write to backbuffer + other textures, I never checked.
Also:

int(ReShade::ScreenSize.y * UvCoord.y)

is vpos.y.
Last Edit: 5 months 2 weeks ago by Marty McFly.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #3

It's possible to write to multiple textures in one pass. It's not possible to write to the backbuffer and textures at the same time.

Additional documentation beside the code Marty mentioned is here (see the "RenderTarget" pass state):
github.com/crosire/reshade-shaders/blob/...ERENCE.md#techniques
Cheers, crosire =)
Last Edit: 5 months 2 weeks ago by crosire.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #4

I just noticed that vpos : SV_Position is vertically reversed on OpenGL. Is it a bug? It's counting from the bottom to top at Y channel.
Last Edit: 5 months 2 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #5

Thanks for response. :)

Since it's interlaced shader we don't need full-res render targets, only half vertical resolution.
Even better, we can squeeze both render target outputs into one texture of a screen size.
But hey, if we flip flop write Back Buffer odd rows between top and bottom half of the Render Target, the previous frame will survive till second pass. And we can get rid of the third pass.
I managed to reduce it to 2 passes and one render target.

Here's how the render target looks like:


It flip flops current and previous frame from top to bottom at every frame.

The code:
Warning: Spoiler! [ Click to expand ]
Last Edit: 5 months 2 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #6

For some reason it does not work in Assetto Corsa and Alien Isolation. Looks like it does not read the Render Buffer, every odd row is black.
But it works in Mirrors Edge (2007), RAGE and Blender. :huh:
EDIT*
It looks like
ClearRenderTargets = false;
is not working for those :(
Last Edit: 5 months 2 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #7

Fu-Bama wrote:
I just noticed that vpos : SV_Position is vertically reversed on OpenGL. Is it a bug? It's counting from the bottom to top at Y channel.
This is expected. OpenGL has its origin at the bottom left corner of the screen, while DirectX has its origin at the top left corner. ReShade fixes texture coordinates to match DirectX terminology, but doesn't do so for positions.
Cheers, crosire =)
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #8

It looks like DirectX 10 games are clearing render targets, ignoring ClearRenderTargets = false;
When you un-comment at line 57 where there is // Preview RenderTarget you can see flip flop flashing of black texture when in DX10. That means the game does not preserve data from previous shader run, but clears it. Can it be fixed?
Last Edit: 5 months 2 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 2 weeks ago #9

Hm. InterlacedTargetPass reads from InterlacedTargetBuffer and writes to it at the same time, that shouldn't be possible to work. That works for backbuffer only iirc. You still need pingpong textures.
Last Edit: 5 months 2 weeks ago by Marty McFly.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 1 week ago #10

Marty McFly wrote:
Hm. InterlacedTargetPass reads from InterlacedTargetBuffer and writes to it at the same time (...)
Reading from InterlacedTargetBuffer is not necessary in that pass. If I could just leave one half of the target untouched in the memory. BlendEnable = true in pass settings suppose to do that, right? Blend the render target with whatever was present in memory?
But I have no idea how to use it. I don't quite get it from the documentation. github.com/crosire/reshade-shaders/blob/...ERENCE.md#techniques
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 1 week ago #11

Correct. I've never really bothered with blending states as I find them quite fiddly, but in theory this should work:
BlendEnable = true; //to enable blending
BlendOp = ADD; //mimic lerp, A*(1-k) + B*k, where B is current data, A is previous
SrcBlend = SRCALPHA; //B*k so if alpha == 1 we get output of your pass, Src being output of current frame
DestBlend = INVSRCALPHA; //A*(1-k) so if alpha == 0 we get what was originally in the buffer (Dest being previous data)
Now you only need to set the alpha channel value of the pixels you want to change to 1 and leave the rest at 0. Haven't checked if this works but it should. ReShade has a bug with blending states, unsure if it's in the public build already so...
Last Edit: 5 months 1 week ago by Marty McFly.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 1 week ago #12

The fix for blending not working correctly was part of 3.1.1, so it's public.
Cheers, crosire =)
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 5 months 1 week ago #13

Yes it works :cheer:
Thanks

Code:
Warning: Spoiler! [ Click to expand ]
Last Edit: 5 months 1 week ago by Fu-Bama. Reason: updated code
The administrator has disabled public write access.