Jump to content

Mask and DxDrawImage


h4x7o0r

Recommended Posts

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
  • Moderators

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

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

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

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...