top of page
Search
  • Peter Taschner

Vertex rotator

Updated: Jan 4, 2023

With this shader, you can rotate the mesh with the GPU to free up resources on the CPU. Keep in mind that this rotates only the vertices. The mesh's collider stays in the exact same position and rotation.

In this case the shader above rotates the vertices around the Z axis by 45 degrees. For the "RotateAboutAxis" node's inputs, you should always use the "Absolute World Position" node as "Position" input and use the "Object Pivot Point" node as "PivotPoint" input if you want to rotate the object around the object's pivot point. The "RotationAngle" value should be divided by 360 if the angle is set between 0 - 360 because the "RotateAboutAxis" node's period is 1 by default.


You also have to fix the vertex normals because they are not updated, so light calculations will be wrong. If you have a normal map, just do what you see in the image above.


If you don't have a normal map, follow Epic's recommendation by calculating new normal vectors in the vertex shader (see the descriptions in the "FixRotateAboutAxisNormals" node).

The first step is to connect the "New Tangent Space Vertex Normal" output pin to a customized uv input. You can use the "RG" and "B" output pins directly or you can mask the result of the 3 channel output. All the texture samplers initially use the 0. uv coordinates channel, so do not use the same customized uv channel for saving the fixed normals. For example, if the textures in your material use the first 3 uv coordinates channels, then for the fixed normals use the 4th and 5th uv channels.

The final step is to use "TexCoord" nodes with the appropriate coordinate index numbers (based on the customized uv inputs that you used), append those to create a vector and connect it to the "Normal" material attribute.


If rotating objects in blueprints eats up render thread time, you can check the exact values in the ".UE4STATS" file (that can be made by the "stat startfile" and "stat stopfile" commands) under the "UpdateTransformCommand" event.

Use vertex animation if the collider doesn't need to follow the vertices' movement. It does not have an impact on CPU.

199 views0 comments

Recent Posts

See All
Post: Blog2_Post
bottom of page