Billboarding Certain Vertices Within The Vertex Shader


I’m somewhat new to UE so I apologize in advance if this is the wrong place to put this question.

I’m attempting to develop a feature within my material shader which allows me to billboard specific vertices towards the camera (e.g. each leaf card of a tree billboards towards the camera individually).

I’m currently at a little bit of a roadblock and figured asking for help to get in the right direction was probably the way to go from here.

Currently I’m using RotateAboutAxis in my material graph and doing some simple transform math to move all of the vertices around the center axis point of my object so that everything is billboarding around the object (e.g. all of the leaves of my tree spin around the trunk, offsetting them from the branches and stuff which looks kind of goofy).

Ideally I would like to get each card to individually do that rotation math on the triangle rather than moving every vertex point around the same point. I’m a little stumped because using custom nodes I’m missing a lot of the keywords I’d usually use to do the vertex lookup, matrix math and vertex output on a geometry shader. I’ve thought about writing a way to encode vertex points into a texture and just identify the vertex points that make up a triangle that should rotate individually there and decode that over in a material function, but I feel like that might be an overcomplication since I’d need to write a script shelf in Maya or Houdini to bake the texture and make a decoding MF in UE.

If anyone has any ideas as to how I might go about getting the described logic in a material graph outputting to the World Position Offset that would be awesome. I’m a little stumped and a nudge in the right direction, even a technical paper would be super helpful. Looking for the simplest solution possible to save myself from some insanity!


I’m not at my computer to check but there may be a premade material function designed for billboards. But even if there is, I assume you’d still need a way to define the pivot point for each vertex.
The only way I could reasonably see doing it is to cache it as you suggested. You could easily store that info in RGB vertex colors if you aren’t using them for something else.
You’ll still need a very simple method of encoding/decoding the data since vert colors are in 0-1 in unreal. I’d probably encode it is as a percentage of the object’s bounds, where (0.5,0.5.,0.5) is the center (regardless of origin), so that you can use the same setup for any size tree.
While it could be baked as a texture like you suggested, the data is only needed on a per vertex basis anyway.

Encoding would be as simple as making a material that takes desired pivot position divided by bounds to get a percentage in (-1 to 1) space, and remapping that to (0 to 1). Bake that to your vertex colors. In Unreal all you’d have to do to decode is read the vertex colors, remap them back to (-1 to 1) and then multiply by the objects bounds.

Someone actually posted a solution to this in a thread recently:

That’s a really elegant looking solution. I was thinking there would be a way to do it with the UVs but I hadn’t connected all the dots. If you are using more traditional leaf cards I think you might still get away with this, but you may need to create an additional UV channel for your cards so that they have the right texture coordinates
Certainly beats having to pivot cache if it’ll work for you.