location based opacity: using output of mask to sample a texture at same location?
I need to carve portals / entrances thru arbitrary geometry at runtime. For that I used the location based opacity tutorial as a starting point: https://wiki.unrealengine.com/Location_Based_Opacity_in_UE4_-_Part_1
In my case, instead of a spheremask I use a box2d mask. That is, I have the following material function:
Which I then use in the material that I apply to the surface being carved like this:
Finally, I have a static mesh actor subclass which updates the center and bounds parameters whenever it moves or changes size. And this works as expected: If I make a rectangular box and make it intersect any static mesh with the above material, the box "carves" into the mesh.
What I'd like to do though, is to not just have a square mask for the cutout. Instead, I have a texture of an irregular shape (made of 1s and 0s for use as an opacity mask) and I want to use the output of the box mask function to sample into this texture, but at the same location as the mask and with the whole texture contained within the bounds of the mask.
The main issue is that I can't figure out how to come up with the right uv coordinates for the mask sampling. Basically I need to be able to sample only for the pixels within the box2d mask (meaning where the box2d outputs 1).
asked Apr 28 '17 at 05:31 AM in Rendering
Ok I got it.
The basic idea is that from the mask area as given by the center and bounds parameters I can figure out how to map to the UV range [0,1]:
With the above I can sample a texture at the area given by the center and bounds parameters. I then used that along with the standard box mask function output to use the texture as a means to shape the opacity mask.
My final material function is like this:
And I use it in my material like so:
answered Apr 28 '17 at 08:19 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here