Welcome, Guest.
Username: Password: Remember me

TOPIC: [HELP] Shader with multiple SamplerColor

[HELP] Shader with multiple SamplerColor 10 months 2 weeks ago #1

  • matsilagi
  • matsilagi's Avatar
  • Online
  • Posts: 199
  • Thank you received: 54
So, im porting a shader for personal use, and i have been trying to solve this basically the entire December + January (yes, im THAT dedicated on solving something).

The texture in its original form (Unity) uses 2 color buffers, but each one renders its stuff (one of them is dedicated of rendering a pass only, without mixing its color changes on the main texture, and the other one is the main).


It has something like this:
float tn = tex2D(_TapeTex, pn).x
But on ReShade, i can only do it in a single SamplerColor, which would be like using _MainTex on it, which equals to:
float tn = tex2D(_MainTex, pn).x //Unity
float tn = tex2D(SamplerColor, pn).x //ReShade

How can i replicate the second SamplerColor (_TapeTex) in ReShade? Doing it like the original code just changing the names didn't work, it gave a broken result just like in Unity if i did it that way.
Loves to test stuff for no reason.
Last Edit: 10 months 2 weeks ago by matsilagi.
The administrator has disabled public write access.

[HELP] Shader with multiple SamplerColor 10 months 2 weeks ago #2

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2452
  • Thank you received: 1391
I don't understand the problem. What do you need a variable called "SamplerColor" for?? Just do something like this:
texture _MainTexture ...;
sampler _MainTex { Texture = _MainTexture; }
texture _TapeTexture ...;
sampler _TapeTex { Texture = _TapeTexture; }

...

tex2D(_MainTex, pn);
tex2D(_TapeTex, pn);
Cheers, crosire =)
The administrator has disabled public write access.

[HELP] Shader with multiple SamplerColor 10 months 2 weeks ago #3

  • matsilagi
  • matsilagi's Avatar
  • Online
  • Posts: 199
  • Thank you received: 54
I already did that, problem is both use COLOR as texture. But on Unity, it is possible to have 2 of those, but one of them(_TapeTex) wont mix in the main image completely.

Ok, so, here's the Unity shader working correctly (Using _TapeTex and _MainTex):


Here's the Unity shader if i choose to use _MainTex only:


Which is the same result i get on ReShade, no matter what:


I don't know how to say this, but the _TapeTex sampler in Unity is the entire Tape pass, plus it renders those color changes (sepia + distortion and tape noise) only on that sampler instead of mixing into the main Color one, i need a way to replicate this in ReShade (2 color samplers but each with its own changes i guess).

Here's the code i use in ReShade for them:
texture2D texColor : COLOR;
texture2D _TapeTex : COLOR;

sampler2D _TapeColor 
{
	Texture = _TapeTex;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
};

sampler2D SamplerColor 
{
	Texture = texColor;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
};

OK, i fixed part of it, the noise now appears, but it still needs to be joined to the other part of the code and still needs to be fixed.
Loves to test stuff for no reason.
Last Edit: 10 months 2 weeks ago by matsilagi.
The administrator has disabled public write access.

[HELP] Shader with multiple SamplerColor 10 months 2 weeks ago #4

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2452
  • Thank you received: 1391
"COLOR" is a semantic and a feature of ReShade FX which in this context allows you to mark a texture to recieve the backbuffer content. It has nothing to do with COLOR in Unity (you cannot put semantics on textures in Unity).

You have not explained what data _TapeTex is supposed to hold. Is it a rendertarget? Is it some image file? Since you mentioned a "Tape pass" I'm guessing it's the former? And _MainTex is probably the backbuffer content (= frame image)? Or is that some rendertarget buffer too?
texture BackBuffer : COLOR;
texture TapeBuffer { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
sampler _MainTex { Texture = BackBuffer ; }
sampler _TapeTex { Texture = TapeBuffer; }

...

float4 PS_Tape(...) : COLOR
{
    ...
}
float4 PS_SomePass(...) : COLOR
{
   tex2D(TapeBuffer, ...);
    ...
}

...

technique MyEffect
{
    pass TapePass
    {
        VertexShader = ...;
        PixelShader = PS_Tape;
        RenderTarget = TapeBuffer;
    }
    pass SomePass
    {
        VertexShader = ...;
        PixelShader = PS_SomePass;
    }
}

Or do you want multi-target rendering?
texture MainBuffer { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
texture TapeBuffer { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
sampler _MainTex { Texture = MainBuffer; }
sampler _TapeTex { Texture = TapeBuffer; }

...

void PS_Tape(..., out float4 colorMainOut : COLOR0, out float4 colorTapeOut : COLOR1)
{
    colorMainOut = ...;
    colorTapeOut = ...;
}

...

technique MyEffect
{
    pass TapePass
    {
        VertexShader = ...;
        PixelShader = PS_Tape;
        RenderTarget0 = MainBuffer;
        RenderTarget1 = TapeBuffer;
    }
    ...
}
Cheers, crosire =)
Last Edit: 10 months 2 weeks ago by crosire.
The administrator has disabled public write access.
The following user(s) said Thank You: matsilagi

[HELP] Shader with multiple SamplerColor 10 months 2 weeks ago #5

  • matsilagi
  • matsilagi's Avatar
  • Online
  • Posts: 199
  • Thank you received: 54
crosire wrote:
"COLOR" is a semantic and a feature of ReShade FX which in this context allows you to mark a texture to recieve the backbuffer content. It has nothing to do with COLOR in Unity (you cannot put semantics on textures in Unity).

You have not explained what data _TapeTex is supposed to hold. Is it a rendertarget? Is it some image file? Since you mentioned a "Tape pass" I'm guessing it's the former? And _MainTex is probably the backbuffer content (= frame image)? Or is that some rendertarget buffer too?
texture BackBuffer : COLOR;
texture TapeBuffer { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
sampler _MainTex { Texture = BackBuffer ; }
sampler _TapeTex { Texture = TapeBuffer; }

...

float4 PS_Tape(...) : COLOR
{
    ...
}
float4 PS_SomePass(...) : COLOR
{
   tex2D(TapeBuffer, ...);
    ...
}

...

technique MyEffect
{
    pass TapePass
    {
        VertexShader = ...;
        PixelShader = PS_Tape;
        RenderTarget = TapeBuffer;
    }
    pass SomePass
    {
        VertexShader = ...;
        PixelShader = PS_SomePass;
    }
}

Or do you want multi-target rendering?
texture MainBuffer { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
texture TapeBuffer { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
sampler _MainTex { Texture = MainBuffer; }
sampler _TapeTex { Texture = TapeBuffer; }

...

void PS_Tape(..., out float4 colorMainOut : COLOR0, out float4 colorTapeOut : COLOR1)
{
    colorMainOut = ...;
    colorTapeOut = ...;
}

...

technique MyEffect
{
    pass TapePass
    {
        VertexShader = ...;
        PixelShader = PS_Tape;
        RenderTarget0 = MainBuffer;
        RenderTarget1 = TapeBuffer;
    }
    ...
}

Sorry for the late reply! Don't get mad but, i fixed it myself :v

Unity engine stores its data in a confusing way, apparently, _TapeTex was a RT that held the resolution of the screen and drew the noise and returned just the noise, the color part was beign manipulated in Pass 1, but applied to the _TapeTex RT. (I hope i didn't get confusing again)

Here's a screenshot:

Sorry for disturbing!
Loves to test stuff for no reason.
Last Edit: 10 months 2 weeks ago by matsilagi.
The administrator has disabled public write access.

[HELP] Shader with multiple SamplerColor 10 months 2 weeks ago #6

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2452
  • Thank you received: 1391
Alright. Glad to hear it's working now =).
Cheers, crosire =)
The administrator has disabled public write access.