h4x7o0r Posted February 17, 2014 Share Posted February 17, 2014 Hey guys, i need your help. What i'm trying to do is to create a mask like over a rectangle so that just a part of the rectangle to be visible. I tried a lot of possibilities but looks like it's kinda tricky. So what i did so far was to : create the texture for mask/ the shader /and the rendertarget. after that i setshadervalues and then tried to figure it out how to put all things together. What's the correct syntax considering all I mentioned before ? Thanks in advance. Link to comment
xXMADEXx Posted February 17, 2014 Share Posted February 17, 2014 Umm.. I'm not really sure but have you tried dxDrawImageSection? Link to comment
h4x7o0r Posted February 17, 2014 Author Share Posted February 17, 2014 Well thanks for your reply, i've read about that function but haven't used it. How can i adapt it to what i need to do like only the part that's not covered by the mask to be shown ? Link to comment
denny199 Posted February 17, 2014 Share Posted February 17, 2014 I didn't fully understand you. Do you want to make that only one part of the image is showing, or just like a puzzle that one part is removed, btw, if you already have a code then show it. Link to comment
Moderators Citizen Posted February 17, 2014 Moderators Share Posted February 17, 2014 As far I kow, there is now way to render a part of an image using a mask. If the image is a square/rectangle, then you can just use the dxDrawImageSection function. If it's a circle or some weird shapes, then you can just edit the image to match that shape and let the background transparent. Then you can user dxDrawImage to render it. Is it possible for you to show us the image and the mask and what you want to render using that mask ? Regards, Citizen Link to comment
h4x7o0r Posted February 17, 2014 Author Share Posted February 17, 2014 What i want is to that mask work as an alphamap. An alpha map image is basically a transparency map, it has the information of what areas of the image under it are hidden. In a alpha map black means transparent, and white visible. Example: Click So just to summarize all, i have a couple of visual elements (dxdrawimage' ones) at the same position on the screen (lets say: renderzone1: position x : 100 position y : 200 width: 200 height: 150. What i need to do is to set a frame/mask/alphamap over that all elements on the screen and the same position with width : 400 and height: 300. So if any of the elements (renderzone1) under the mask are moving outside renderzone1 the underneath elements to not be visible. some part of codes: finalAlpha = 210 mask=dxCreateTexture('img/mask.png') shader=dxCreateShader('shader.fx') renderTarget = dxCreateRenderTarget( 310, 250, false ) dxSetShaderValue(shader,'finalAlpha',finalAlpha/255) dxSetShaderValue(shader,'maskTex0',mask) outputChatBox('Textures loaded.',false,255,0,0) and also the shader --shader.fx 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(); } } All good after this now all i need to do is to link things together. Link to comment
Moderators Citizen Posted February 17, 2014 Moderators Share Posted February 17, 2014 Ok, I see but I'm not the guy of the situation since I never used shaders. Sorry, need to wait for someone who knows about shaders Link to comment
50p Posted February 17, 2014 Share Posted February 17, 2014 I'm actually working on a simple class to allow users to apply masks to images but I'm new to shaders so it may take a bit before I learn enough about shaders to actually get it to work in MTA. I want it to be as simple to script as: CMasker: create( "texture.png", "mask.png" ); and then masker:draw( x, y, with, height ); I'll let you know when I finish. EDIT: Oh well, it took less then I thought it will take. Here it is: viewtopic.php?f=108&t=71470 have fun. Link to comment
Moderators Citizen Posted February 18, 2014 Moderators Share Posted February 18, 2014 Oh that's pretty insane ! Link to comment
h4x7o0r Posted February 18, 2014 Author Share Posted February 18, 2014 Thanks a lot for the shader it basically works, i've pmed u regarding a modification or stuff. 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