Welcome, Guest.
Username: Password: Remember me

TOPIC: BackBuffer and RenderTarget at one pass?

BackBuffer and RenderTarget at one pass? 1 month 3 weeks ago #1

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
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 ]
If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 1 month 3 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 3 weeks ago #2

  • Marty McFly
  • Marty McFly's Avatar
  • Online
  • We've tried nothing and we're all out of ideas!
  • Posts: 983
  • Thank you received: 980
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: 1 month 3 weeks ago by Marty McFly.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 3 weeks ago #3

  • crosire
  • crosire's Avatar
  • Online
  • Posts: 3003
  • Thank you received: 1758
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: 1 month 3 weeks ago by crosire.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 3 weeks ago #4

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
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.
If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 1 month 3 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 3 weeks ago #5

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
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 ]
If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 1 month 3 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 3 weeks ago #6

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
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 :(
If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 1 month 3 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 3 weeks ago #7

  • crosire
  • crosire's Avatar
  • Online
  • Posts: 3003
  • Thank you received: 1758
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? 1 month 3 weeks ago #8

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
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?
If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 1 month 3 weeks ago by Fu-Bama.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 2 weeks ago #9

  • Marty McFly
  • Marty McFly's Avatar
  • Online
  • We've tried nothing and we're all out of ideas!
  • Posts: 983
  • Thank you received: 980
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: 1 month 2 weeks ago by Marty McFly.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 2 weeks ago #10

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
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
If you want to buy me a coffee, www.paypal.me/fubax :)
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 2 weeks ago #11

  • Marty McFly
  • Marty McFly's Avatar
  • Online
  • We've tried nothing and we're all out of ideas!
  • Posts: 983
  • Thank you received: 980
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: 1 month 2 weeks ago by Marty McFly.
The administrator has disabled public write access.

BackBuffer and RenderTarget at one pass? 1 month 2 weeks ago #12

  • crosire
  • crosire's Avatar
  • Online
  • Posts: 3003
  • Thank you received: 1758
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? 1 month 2 weeks ago #13

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
Yes it works :cheer:
Thanks

Code:
Warning: Spoiler! [ Click to expand ]
If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 1 month 2 weeks ago by Fu-Bama. Reason: updated code
The administrator has disabled public write access.