Download

Vertex Shader (Find centroid, move and face the camera)

Hi guys,

I would like to import a single FBX file inside Unreal containing a group of meshes (like separate billboards) and for each mesh, find its centroid and let them face the camera and move up and down independently. Do you know how to build up the shader for achieving this?

Thank you!

There are lots of ways to do this.

  1. When installing UE4 from the launcher, there is a box in the start with install options. One of them is “Art Tools”. It include a max script by one of our Technical Artists, Jon Lindquist, that can bake out pivot information exactly like you want. It is usually meant for creating wind shaders for trees and plants but it can also be used just to write pivots per poly etc.

  2. For a simple case like you describe, I usually just use a simple trick. Make the polys very tiny in the model (as tiny as you are comfortable with) and then you use the vertex shader to expand the vertices perpendicular to the camera direction. By making the poly small to start, you avoid needing to know the actual center. There will be a tiny amount of error, and the error will be exactly proportional to the initial size of your polys (which is what you just need to make them small enough to where the projected size is at least 10x bigger etc).

There is a material function called “Sprite” that you can use to do the projection. It hooks to world position offset. You would need to specify “Absolute World Position” as the position, and then control the size etc.

As you may have noticed, if you just use a scalar param for the size, all your polys will project to the same size. If you want to randomize the size per quad, you would actually need to do a random vertex color or something per quad, but the random value would have to match for all the verts on each quad or you’d just see the mesh get all skewed.

Hi Ryan!
Thank you so much for your answer and your tips :slight_smile:

The goal I want to achieve is to make a rain system based on moving meshes which I can customize the velocity, size, distance among each others, ect… through the vertex shader, so it should costs less in computation than making it with a particle system…

That’s who it was done in the last Gears of War game, I’ve also recently done it like that for a VR game, definitely the way to go! In my case I saved XY pivot point position in the UV channel and hat the Z animated in the shader. It works really really well and it’s stupid cheap. :slight_smile:

Hi Norman, thank you for your advice :slight_smile:
I’m tring to follow the method you described and I stored the XY pivot position inside the uv channel, but could I please ask you how you extract the pivot position of each “sub-element” of the mesh into unreal shader? Thx so much!