Welcome, Guest.
Username: Password: Remember me

TOPIC: How to write to SV_Depth?

How to write to SV_Depth? 1 month 4 weeks ago #1

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
I'm trying to UV-distort the depth buffer along with the image distortion, for effects that follow and use depth.
Problem is that I don't know how to write to the depth buffer SV_Depth.
I tried to write the depth to Pass1 alpha channel, then in second pass, that targets SV_Depth, return the alpha channel from the first one.
But it gives an error undefined variable "_return"

Shader Code:
Warning: Spoiler! [ Click to expand ]
If you want to buy me a coffee, www.paypal.me/fubax :)
The administrator has disabled public write access.

How to write to SV_Depth? 1 month 4 weeks ago #2

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2999
  • Thank you received: 1751
This is not going to work, unfortunately. The depth-stencil buffer bound for writing is not the one you get as input.
In fact ReShade does not guarantee a depth buffer being bound during post-processing at all, it's only defined to at least bind a stencil buffer when the render target size matches that of the game viewport (SMAA needs this). A depth buffer doesn't make much sense during post-processing usually, because we only draw fullscreen primitives that should not be depth sorted.
Depth data you get as input comes straight from the depth texture the game had bound as depth buffer during rendering, but it's considered immutable at this point like all resources ReShade gives access to. The backbuffer is the one and only exception. Giving write access to any other resource would come with a heavy performance penalty and is therefore not allowed nor implemented.
Cheers, crosire =)
The administrator has disabled public write access.

How to write to SV_Depth? 1 month 4 weeks ago #3

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
Thanks for the answer.
If you want to buy me a coffee, www.paypal.me/fubax :)
The administrator has disabled public write access.