Download

Easy way to modify my mask?

I have a black and white mask with sharp borders. What I want is to slightly increase the white area outwards and then blur the border. I want to do it in the material, but as a bonus I’m interested how could i do it in photoshop.

I assume there is a not too complicated way to do this, thanks for the help in advance.

What you’re describing is a gradient. look into the documentation for gradient nodes in the material editor they’re easy to use

I still could not figure it out, I tried the various gradient maps but none of those worked for me.

As far as i’m aware you can’t get a “smooth” gradient on a mask without using some trickery like Alpha Dithering, if you want no compromises then you’re going to have to use a regular translucent material ( which is more expensive than a mask material ).

Without custom code, this would be very cumbersome. The material editor doesn’t offer an easy way to do loops, and you need to sample lots of pixels. Here’s a morphological dilation material I made a few months ago. Top one is rectangular, bottom one is circular. Paste this code in the corresponding custom node.

8b7560724b12da07f5c78cc659e3fd6f8739c734.jpeg


\\DilationRect
 
 
float2 UVPixSize=1/TextureSize;
float2 PixUV=(floor(UV*TextureSize)+0.5)/TextureSize;
float PixValue=0;
 
for(int i=int(-DilationPixels.x);i<DilationPixels.x;i++)
{
for(int j=int(-DilationPixels.y);j<DilationPixels.y;j++)
{
PixValue+=Texture2DSampleLevel(MaskTex,MaskTexSampler,float2(PixUV.x+i*UVPixSize.x,PixUV.y+j*UVPixSize.y),0);
}
}
return ceil(clamp(PixValue,0,1));
 
 
\\DilationCirc
 
 
float2 UVPixSize=1/TextureSize;
float2 PixUV=(floor(UV*TextureSize)+0.5)/TextureSize;
float PixValue=0;
 
for(int i=int(-DilationPixels);i<DilationPixels;i++)
{
for(int j=int(-DilationPixels);j<DilationPixels;j++)
{
PixValue+=lerp(0,1,sqrt(pow(i,2)+pow(j,2))<DilationPixels)*Texture2DSampleLevel(MaskTex,MaskTexSampler,float2(PixUV.x+i*UVPixSize.x,PixUV.y+j*UVPixSize.y),0);
}
}

If you want to combine this with a blur, it gets a little trickier. You could do something like: Create a second variable like PixValue, which adds all pixels in the kernel, but divides by the number of pixels in the kernel to get an average. Then lerp in favor of the second value as the distance((i,j),(0,0))/radius approaches 1.

Thanks for the help… somehow I thought it would be an easy thing to do… but maybe it’s better if I do it in PS somehow so it would go easier on the shader.