Jump to content

Rendertarget with alpha channel becomes visible after applying shader


Dzsozi (h03)

Recommended Posts

Hello!

I have a little problem with render targets that I don't know how to solve. I made a render target with alpha channel enabled, so I won't see the black background. If I draw the render target itself it works fine, I can't see the black background, only problem now is that I am missing a fading effect from the edges. So I applied a mask shader and made a mask for this render target, but if I apply this mask shader on the render target the black background appears. I don't think there is a problem in my script, more likely in the shader file, but I don't know how to edit shaders, I don't know how I could fix it, I guess I would have to change up some things in connection with the source alpha, but I know nothing about shaders.

I would appreciate if someone with shader knowledge could help me out with this!

Here's my mask shader file:

texture tex0;       // texture
texture maskTex0;   // mask
float finalAlpha;

sampler sBase = sampler_state { 
	Texture = (tex0);
	MinFilter = Linear;
	MagFilter = Linear;
	AddressU = Clamp;
	AddressV = Clamp; 
};
sampler sAlpha = sampler_state { Texture = (maskTex0); };

float4 ps( float2 Base : TEXCOORD0 ) : COLOR
{
    float4 color;
    float4 alpha;
    color = tex2D( sBase, Base.xy );
    alpha = tex2D( sAlpha, Base.xy );
    color.a = alpha.r*finalAlpha;
    return color;
}

technique mask
{
    pass p0
    {
		AlphaBlendEnable = TRUE;
		DestBlend = INVSRCALPHA;
		SrcBlend = SRCALPHA;
		VertexShader = null;
        PixelShader = compile ps_2_0 ps();
    }
}

And here's how I use it in scripts:

-- on resource start
local shader = dxCreateShader("_files/mask.fx")
local mask = dxCreateTexture("_files/images/mask.png")
dxSetShaderValue(shader,"maskTex0",mask)
dxSetShaderValue(shader,"finalAlpha",1)

-- inside the render function
dxSetRenderTarget(showAreaRenderTarget, true)
dxSetBlendMode("modulate_add")

-- bla bla drawing stuff

dxSetBlendMode("blend")
dxSetRenderTarget()

dxSetShaderValue(shader,"tex0",showAreaRenderTarget)
dxSetBlendMode("add")
dxDrawImage(showAreaPosX, showAreaPosY-iconSize/4, showAreaSizeX, showAreaSizeY, shader)
dxSetBlendMode("blend")

So, as I wrote, the mask shader works fine, my only problem is that I can see the render target's black background, even when the alpha channel is enabled when creating the render target. How I could solve this?

Link to comment
5 hours ago, Ren_712 said:

I changed the shader file to this and changed the shader values in the script to be correct, but I have the same problem.

Here's a picture what I currently have:

8a7ibnL.png

What I would like it to be:

nk6rNYf.png

Without the black background, but with the fading on the sides.

Edited by Dzsozi (h03)
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...