Welcome, Guest.
Username: Password: Remember me

TOPIC: Render to Texture and Backbuffer in single pass

Render to Texture and Backbuffer in single pass 7 months 2 weeks ago #1

  • ShoterXX
  • ShoterXX's Avatar
  • Offline
  • Posts: 52
  • Thank you received: 9
I was reading this: github.com/crosire/reshade-shaders/blob/master/REFERENCE.md

Is it possible? I know I supposedly can't read and write to the same texture at the same time, but I was looking at the function parameter qualifiers, it looked like "inout" could allow me to get the buffer, change it, then send it straight back. If so, I can pretty much shorten my whole shader (without defines, textures and all that stuff, ofc) to 2 lines. I've tried it, but not sure if I'm doing something wrong.

And before anyone asks, I'm a rookie as far as graphical stuff goes.

Edit: Ok, I went sideways on my question, so let me clarify it. Can I write to a texture and to the back buffer in the same pass? And how? And how do I use that "inout" parameter properly?
Last Edit: 7 months 2 weeks ago by ShoterXX.
The administrator has disabled public write access.

Render to Texture and Backbuffer in single pass 7 months 2 weeks ago #2

For a shader, you don't have the "in" , the color in the texture before even sampling in the shader, for the argument "inout".
And reshade doesn't take "in" for the shader besides Semantics.

The alternative is to use it in function then load it to shader.

As shown in the reference, you can still have your 2-lines shader with some arrangement.
reference wrote:
// The following pixel shader simply returns the color of the games output again without modifying it (via the "color" output parameter):
void ExamplePS0(float4 pos : SV_Position, float2 texcoord : TEXCOORD0, out float4 color : SV_Target)
{
    color = tex2D(samplerColor, texcoord);
}
To have multiple output texture, you can specify multiple render target, the implement detail is in the reference.
Last Edit: 7 months 2 weeks ago by kingeric1992.
The administrator has disabled public write access.

Render to Texture and Backbuffer in single pass 7 months 2 weeks ago #3

  • ShoterXX
  • ShoterXX's Avatar
  • Offline
  • Posts: 52
  • Thank you received: 9
kingeric1992 wrote:
For a shader, you don't have the "in" , the color in the texture before even sampling in the shader, for the argument "inout".
And reshade doesn't take "in" for the shader besides Semantics.

The alternative is to use it in function then load it to shader.

As shown in the reference, you can still have your 2-lines shader with some arrangement.
reference wrote:
// The following pixel shader simply returns the color of the games output again without modifying it (via the "color" output parameter):
void ExamplePS0(float4 pos : SV_Position, float2 texcoord : TEXCOORD0, out float4 color : SV_Target)
{
    color = tex2D(samplerColor, texcoord);
}
To have multiple output texture, you can specify multiple render target, the implement detail is in the reference.

Problem A: I can't read from sample AND write it to RT at the same time, so if I sample it, I won't be able to output it.

Problem B: If I specify a new render target, it'll no longer use RT0 to send to backbuffer. The issue about it is that BackBuffer is read-only and I have no idea what I should use instead, since that is not specified in the reference. I tried poking around the other shaders and ReShade.fx, but found nothing.
Last Edit: 7 months 2 weeks ago by ShoterXX.
The administrator has disabled public write access.

Render to Texture and Backbuffer in single pass 7 months 2 weeks ago #4

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1385
It is not currently possible. The backbuffer is unbound as soon as a custom rendertarget is bound.
Cheers, crosire =)
The administrator has disabled public write access.
The following user(s) said Thank You: ShoterXX

Render to Texture and Backbuffer in single pass 7 months 2 weeks ago #5

  • ShoterXX
  • ShoterXX's Avatar
  • Offline
  • Posts: 52
  • Thank you received: 9
crosire wrote:
It is not currently possible. The backbuffer is unbound as soon as a custom rendertarget is bound.

Oh. Well, thanks for the reply! Is it possible to add it as a feature then, or is there a reason for it?
The administrator has disabled public write access.

Render to Texture and Backbuffer in single pass 7 months 2 weeks ago #6

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1385
Sure. The reason it's not there is that I could not decide for a syntax for binding the backbuffer to a certain rendertarget slot. Simplest option would be to simply always force target 0 to the backbuffer unless it is explicitly overwritten or a texture with different dimensions is bound to another slot.
Cheers, crosire =)
The administrator has disabled public write access.
The following user(s) said Thank You: ShoterXX

Render to Texture and Backbuffer in single pass 7 months 2 weeks ago #7

  • ShoterXX
  • ShoterXX's Avatar
  • Offline
  • Posts: 52
  • Thank you received: 9
Neat! Thanks!
The administrator has disabled public write access.