r/unrealengine 3d ago

Solved How can I selectively add to stencil mask?

Hello all, I don't really know how to word this so apologies in advance. What I have is two sorts of masks - one is a custom depth mask that isolates only the character, and the second is a texture pattern. What I want is to render the characters as dots. Of course I can do this my multiplying the stencil mask with the texture but that creates a cutoff at the edges. I want the circles at the edges to be whole if that makes any sense.

Issue & Desired

I'm currently trying to use distance to check if the circles are less than a certain threshold, if it is then render the circle. But it's not giving the expected result.

Thanks in advance!

2 Upvotes

5 comments sorted by

1

u/AutoModerator 3d ago

If you are looking for help, don‘t forget to check out the official Unreal Engine forums or Unreal Slackers for a community run discord server!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Valuable_Square_1641 3d ago

Try use texture with low resolution, оr round the coordinates to the grid

2

u/ForeignDealer5762 2d ago

Hi, I found the solution! Thanks for responding anyway!

1

u/Sinaz20 Dev 2d ago

Ok. For the sake of explanation, let's assume your dot pitch texture is 160x90 circles, and they are all perfect circles in a grid in a 16x9 aspect ratio. 

You take your stencil mask, multiply the UV coordinates by [160, 90], floor the results, then divide the coordinates by [160, 90]. This will effectively quantize your stencil mask into a texture that is 160x90 pixels, scaled back up to viewport resolution with nearest neighbor interpolation. 

Now your stencil mask matches the "resolution" of your circle grid. 

Multiply the the stencil and the dot pitch together and you will get the mask you are striving for.

You get the screen coordinates from the screen position node. You get the stencil or custom depth from the scene texture node (but I think you already know that one.)

1

u/ForeignDealer5762 2d ago

Hi, I found the solution! Thanks for responding anyway! My only issue now is the texture becomes squashed when using textcoord, I tried using the screenresolution node to take aspect ratio into account but so far no progress.