Dzsozi (h03) Posted September 26, 2017 Share Posted September 26, 2017 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
Ren_712 Posted September 26, 2017 Share Posted September 26, 2017 (edited) https://forum.multitheftauto.com/topic/60602-rel-50p-masking-textures-shader/ Edited September 26, 2017 by Ren_712 Link to comment
Dzsozi (h03) Posted September 26, 2017 Author Share Posted September 26, 2017 (edited) 5 hours ago, Ren_712 said: https://forum.multitheftauto.com/topic/60602-rel-50p-masking-textures-shader/ 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: What I would like it to be: Without the black background, but with the fading on the sides. Edited September 26, 2017 by Dzsozi (h03) Link to comment
Ren_712 Posted September 26, 2017 Share Posted September 26, 2017 (edited) change this: color.a = alpha.r*finalAlpha; with that: color.a *= alpha.r*finalAlpha; Edited September 26, 2017 by Ren_712 Link to comment
Dzsozi (h03) Posted September 27, 2017 Author Share Posted September 27, 2017 Works perfectly, thank you for your help and the quick response! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now