Masking with soft edges

What is the best way to mask with soft edges ,
I’ve tried ClippingNode ,but it will not do the effect that i need ,any idea how can i do that ?

1 Like

Use a masking texture with a custom shader. Or find one pre-built.

@stevetranby
Is it possible to edit current ClippingNode to do that ?

Not really because clipping is done at a coarse pixel is ON or OFF. What you’re looking for requires alpha translucency.
Note: People are resourceful and clever and someone may have a way to use ClippingNode, but I would use a custom node+shader or a prebuilt masked sprite of some kind.

Thank you ,I’ve managed to make it work ,i got small issue how can i update mask Coord .

_glprogramstateCB->setUniformVec2("v_maskCoord",MASKSPRITE COORD);

MASKSPRITE COORD?

i wanna move the mask around .

shader code

#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform sampler2D u_mask;
uniform vec2 v_maskCoord;
void main(void) {
    vec4 texColor =texture2D(CC_Texture0, v_texCoord);
    vec4 maskColor = texture2D(u_mask, v_maskCoord);
   float alpha=maskColor.a-1.0;
    if (alpha<0.0) {
       alpha= alpha*-1.0;
    }
    gl_FragColor = texColor * alpha;
}

You probably need to use something like v_texCoord + v_maskCoord or something instead of just v_maskCoord when sampling the mask texture like that so that every pixel doesn’t use the same mask coordinate.

Thank you , now everything is working perfectly .

1 Like