- Posts: 11
How to add png transparency control to shader?
- Lazmarr
-
Topic Author
- Offline
This is my overlay shader so far;
NAMESPACE_ENTER(CFX)
#include CFX_SETTINGS_DEF
texture HudTex < string source = "ReShade/CustomFX/Textures/CFX_hud.png"; > {Width = 1920; Height = 1080; Format = RGBA8;};
sampler HudColor { Texture = HudTex; };
float4 PS_Hud(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float4 hud = tex2D(HudColor, texcoord);
return lerp(tex2D(RFX_backbufferColor, texcoord),hud,hud.a);
}
technique Hud_Tech <bool enabled = RFX_Start_Enabled; int toggle = RFX_ToggleKey; >
{
pass HudPass
{
VertexShader = RFX_VS_PostProcess;
PixelShader = PS_Hud;
}
}
#include CFX_SETTINGS_UNDEF
NAMESPACE_LEAVE()
Please Log in or Create an account to join the conversation.
- crosire
-
- Offline
- Posts: 3836
Your code looks alright for the most part (except that you may want to return a float3 and discard the alpha channel of both the backbuffer and the overlay image after lerping). Check if the alpha channel of the image file was read correctly (ReShade may not understand all PNG formats):
return float4(hud.aaa, 1.0);
Please Log in or Create an account to join the conversation.
- Lazmarr
-
Topic Author
- Offline
- Posts: 11
I probably should've mentioned that I barely know what any of this stuff means. I found the majority of this code online and only edited the bits I need.
I'm not really sure what backbuffer and lerping is.
I have added an alpha channel to my hud png as it did not contain one.
I shall try to add your code snippet in but I am not entirely sure where it goes

Edit: Ok the overlay worked fine, the PNG transparency was read correctly, until I repalced the;
return lerp(tex2D(RFX_backbufferColor, texcoord),hud,hud.a);
return float4(hud.aaa, 1.0);
Is this code you provided to adjust transparency?
I appreciate the help you are giving me

Please Log in or Create an account to join the conversation.
- crosire
-
- Offline
- Posts: 3836
Please Log in or Create an account to join the conversation.
- Lazmarr
-
Topic Author
- Offline
- Posts: 11
With the code I posted this is what it looks like;
With the code to check alpha this is what happens;
The white (HUD elements) on this image is what needs to adjust in transparency :/
I don't know how to add code to the one I posted that will be able to only adjust the transparency of those HUD elements.
Please Log in or Create an account to join the conversation.
- crosire
-
- Offline
- Posts: 3836
If you want to modify individual channels, here's a standalone shader for ReShade 3.0 to give you that:
texture BackBufferTex : COLOR;
texture HudColorTex < source = "hud.png"; > { Width = 1920; Height = 1080; Format = RGBA8; };
sampler BackBuffer { Texture = BackBufferTex; };
sampler HudColor { Texture = HudColorTex; };
uniform float3 TransparencyControl <
ui_type = "drag";
ui_min = 0.0; ui_max = 1.0;
> = float3(1.0, 1.0, 1.0);
void PostProcessVS(uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD)
{
texcoord.x = (id == 2) ? 2.0 : 0.0;
texcoord.y = (id == 1) ? 2.0 : 0.0;
position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}
float3 HudPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float4 hud = tex2D(HudColor, texcoord);
float3 color = tex2D(BackBuffer, texcoord).rgb;
return lerp(color, hud.rgb, hud.aaa * TransparencyControl);
}
technique HUD
{
pass
{
VertexShader = PostProcessVS;
PixelShader = HudPS;
}
}
An alternative using hardware blending (which could be faster, too requires ReShade 3.0):
texture HudColorTex < source = "hud.png"; > { Width = 1920; Height = 1080; Format = RGBA8; };
sampler HudColor { Texture = HudColorTex; };
uniform float TransparencyControl <
ui_type = "drag";
ui_min = 0.0; ui_max = 1.0;
> = 1.0;
void PostProcessVS(uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD)
{
texcoord.x = (id == 2) ? 2.0 : 0.0;
texcoord.y = (id == 1) ? 2.0 : 0.0;
position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}
float4 HudPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float4 hud = tex2D(HudColor, texcoord);
return float4(hud.rgb, hud.a * TransparencyControl);
}
technique HUD
{
pass
{
VertexShader = PostProcessVS;
PixelShader = HudPS;
ClearRenderTargets = false;
BlendEnable = true;
BlendOp = ADD;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;
}
}
Please Log in or Create an account to join the conversation.
- Lazmarr
-
Topic Author
- Offline
- Posts: 11

The first one reshade loads the shader but the overlay does not appear. I have tried changing the source for the texture and changing values for the transparency control but neither have any effect.
The second one gives a red message "unrecognised pass state clear render targets"
Instead of changing the individual channels. Is it possible to change the transparency of the overlay inestead? As I feel that may be simpler to implement instead of messing with channels and the alpha

Please Log in or Create an account to join the conversation.
- JovianStone
-
- Offline
- Posts: 9
crosire wrote: If you want to modify individual channels, here's a standalone shader for ReShade 3.0 to give you that:
Worked for me, I used the first one. I was able to make a dot reticle for Homefront the Revolution. Thanks.
Please Log in or Create an account to join the conversation.
- creiglee
-
- Offline
- Posts: 1
Please Log in or Create an account to join the conversation.
- CMDR-Mase
-
- Offline
- Posts: 1
crosire wrote: You misunderstood me. I first thought you couldn't get transparency to work at all and therefore posted some code to verify the image file.
If you want to modify individual channels, here's a standalone shader for ReShade 3.0 to give you that:texture BackBufferTex : COLOR; texture HudColorTex < source = "hud.png"; > { Width = 1920; Height = 1080; Format = RGBA8; }; sampler BackBuffer { Texture = BackBufferTex; }; sampler HudColor { Texture = HudColorTex; }; uniform float3 TransparencyControl < ui_type = "drag"; ui_min = 0.0; ui_max = 1.0; > = float3(1.0, 1.0, 1.0); void PostProcessVS(uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD) { texcoord.x = (id == 2) ? 2.0 : 0.0; texcoord.y = (id == 1) ? 2.0 : 0.0; position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); } float3 HudPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target { float4 hud = tex2D(HudColor, texcoord); float3 color = tex2D(BackBuffer, texcoord).rgb; return lerp(color, hud.rgb, hud.aaa * TransparencyControl); } technique HUD { pass { VertexShader = PostProcessVS; PixelShader = HudPS; } }
An alternative using hardware blending (which could be faster, too requires ReShade 3.0):texture HudColorTex < source = "hud.png"; > { Width = 1920; Height = 1080; Format = RGBA8; }; sampler HudColor { Texture = HudColorTex; }; uniform float TransparencyControl < ui_type = "drag"; ui_min = 0.0; ui_max = 1.0; > = 1.0; void PostProcessVS(uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD) { texcoord.x = (id == 2) ? 2.0 : 0.0; texcoord.y = (id == 1) ? 2.0 : 0.0; position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); } float4 HudPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target { float4 hud = tex2D(HudColor, texcoord); return float4(hud.rgb, hud.a * TransparencyControl); } technique HUD { pass { VertexShader = PostProcessVS; PixelShader = HudPS; ClearRenderTargets = false; BlendEnable = true; BlendOp = ADD; SrcBlend = SRCALPHA; DestBlend = INVSRCALPHA; } }
Hey there guys, first, im sry for necro this year old thread...
I need some help with the shader example of crosire (the first example), i want to make another one with the same settings but pointing to another texture file. Is that possible?
I tried the "brute man method" just making a copy of the HUD.fx file changing it name and editing the file itself to make it search other image, i saw the new *.fx file in the shaders pipeline as a toggleable in the (ALT+F2) menu but just keep searching the image of the original HUD.fx file

Any help would be awesome.-
Why i want help 1 year later?
Here is the answer
Please Log in or Create an account to join the conversation.