Projecting Texture Onto Object ("Dynamic Mask")

Hey folks, reposting this here, in hopes that it gets some more exposure: Projecting Texture Onto Object ("Dynamic Mask") - UE4 AnswerHub



I am trying to use materials to dynamically project a texture onto a mesh via material. Unfortunately, I am not having as much luck as I am hoping, even though my calculations appear correct (hint: they’re not). Any help on this subject would be greatly appreciated.

Basically, I take a point around my static mesh, make it face it constantly (This is my “projection plane”):

In my material, I take the information of that plane, its relative position, up, right and forward vectors, and project my static mesh points onto it (calculation for projection found here).

The last thing in the material function is me attempting to get the point’s “plane coordinates”, i.e. its 2D position in the projection plane’s local coordinate system. I then simply use those as the UVs for my mask texture.

This is my end result:

Obviously, this is not what I intended. Anyone got any ideas?

Bump in the night

why don’t you use decals ??

Crivatz - I can’t filter decals per-mesh. Plus, I need this mask to affect the opacity of objects (this blood splatter is just a placeholder) to mask out pieces of the mesh. So decals won’t work unfortunately.

There are a bunch of nodes that do things very similar to this under the engine\content\arttools folder. One is called “BoundingSphereLightTransform”.

The name may be somewhat confusing, but I made it in order to do custom per-object shadowmap projection for trees in the Apple Zen demo. What it basically does is transform the object local space into the input “light vector” which would be your projection vector. You would just do component mask of the UV (which is the same as RG in the mask node) for a 2d texture projection.

There are already parameters that would let you scale the projection texture, but in order to add support offsets from the center of the mesh (rather the center of its bounding sphere as viewed from the projection vector), you would need to add an offset parameter into the mix somewhere. What you would probably need to do is also transform your offset into the “projection vector space” using matrix3x3transform and add the result to the raw worldposition before piping it into the BoundingSphereLightTransform node. Or you could add an offset without transforming it, but the offset will then be less intuitive to set but a bit cheaper.

The function “VolumeShadowMap” is a companion node for performing self shadowing using a depth map of the object from the given vector. There are also some blueprint tools under the RenderToTexture level blueprint that let you bake out a matching depth-map of the mesh from a lights perspective so you can do custom per object shadows.

edit just looked at your math and I’m not sure if you need to do the inverse transforms like that. That would only apply if your BP for setting up the transforms was rotated in addition to the vector component. But I think that would be transform position, not inverse transform… So if you don’t rotate the base BP the original values are the same. Then I think you need to use the inverse transform instead of the matrix3x3transform inside your material. That is basically what the function I suggested does as well.

FWIW I usually test that kind of thing out with vectors made entirely in the material at first. Ie make your projection vector the only parameter then use “CreateThirdOrthogonalVector” with (0,0,1) as the “vector2” and then use the 3 resulting vectors as your 3 axes.

I also suggest you test on a sphere at first since it is much easier to see projection errors on a sphere.

Hey Ryan,

It’s 3:30am right now and I haven’t touched this in a few days so I don’t have it “at hand” now. Point being, what you just explained sounded mostly like gibberish. :smiley:

Tomorrow morning I’ll buckle up and go through the functions you mentioned and analyze them in detail. Thanks a ton!

Best regards,
Damir H.

@RyanB - Sorry to necro this thread, but I’m having a bit of trouble getting a projective texture to offset in the projection vector axis, and I’m afraid I can’t seem to figure out your advice here.

Here’s my material thus far, it’s basically identical to the one you’ve posted before when talking about this subject and referencing your projected shadow

And a pastebin of the nodes:

I’m not really sure what to do with the additional offset to get it to offset the texture in the direction of projection, I’ve tried transforming the offset in various ways and adding it in various ways as well, but haven’t seen it move in the axis of projection.

Any help is much appreciated!