Download

Billboard material that takes into account instance rotation?

I have a tree mesh with billboard plane on the last LOD. I’m trying to create a material that will make the billboard always face the camera.
Here, under the ‘Foliage Material’ section we can see a billboard material that works, but in my case it looks like this:

Bez tytułu.png

The billboards rotate with camera, but each one has rotation offset se they don’t face the camera. Each tree instance is randomly Z rotated, so I guess that’s the reason. Is there a way to make them face the camera no matter what Z rotation the object has?
In blueprints it’s easy since we operate on whole object, but I can’t figure out how to achieve it in a material, where it’s all about vertex offseting.

I believe your answer lies within the Kite/Open World Demo Collection.
The HillTree_02 asset has a billboard LOD with camera facing material.
I just tested painting a few HillTree_02 onto a landscape and confirmed that it’s billboard is working with random rotation.

I just so happened to be trying to learn how this material works myself and have cleaned up the material graph to make it easier to follow:

http://drive.google.com/uc?export=view&id=0B0eV5r9stGxaT0V0NGpYU08ydDA

Thanks, this uses the Imposter UV function which needs a billboard sprite sheet. I only have a regular single billboard image and need a simple face-camera rotation. I’ll look inside this function today, maybe there is some logic that rotates the billboard plane to camera.

I’ve found an answer. For others that might face the same issue:
In the free Content Examples project, there is a ‘Math Hall’ level. There you can find some green planes that face camera using material math. The material that you’re looking for is named ‘M_CameraVector_to_Object’.
However, this doesn’t work with instanced meshes like painted foliage. To fix it, replace the ‘Actor Position’ node with ‘Object World Position’ node. Now it should work also with hierarchical instanced meshes, e.g. on painted trees.

EDIT: … This method messes up object’s scale though, so it’s not ideal…
… it has scalar parameters for object width & height, but I need to retain the original scale of billboards, not set it via parameters… It also makes the billboards appear upside-down.

you won’t be able to retain the original scale of billboards because the material, when used as foliage, isn’t aware of the size of each instance. if you use object bounds or object radius or any such sort of material nodes you’ll only get the size of the entire foliage ‘cluster’
there’s a node that gets you the scale of the foliage instance, but that’s only a percentage scale in relation to the original scale - not an absolute value of size

Thanks for the info, I see that now… Looks like there’s just not enough instance info available in materials. I’ve also tried getting instance forward vector by (1,0,0)->Transform Local to World and using it to calculate the offset somehow, but without luck.
What surprised me is that this is an old & common technique - billboard plane on the last LOD of instanced trees - but as we can see it’s very tricky (or impossible?) to do with materials in UE.
Well, I’ll try to figure out something but math is not my strongest side, unfortunately :slight_smile:

You can retrieve pivot position, per-axis scale and orientation vector for individual instances. Just pass transform node results via custom UVs.

Thanks for the hint! There are no nodes for that, so I guess that e.g. (1,0,0) -> Transform Local to World should get instance forward vector? I’d try that, but I’m not sure what do you mean by passing it via custom UVs? Sorry if it’s trivial, my material knowledge is still limited, I’m trying to learn.

Just in case others are looking into this too - there is a node called “FoliageZRotation” which contains the rot of the billboard - subtract that from the calculated angle to get all instances/object to point at you even when rotated.

For anyone who needs clearer instruction, you need to plug this into the RotationAngle node. Thank you for the tip!