world_position_offset_p2

in Tutorials, UE4

World position offset (Part 2)

This is the second part of the tutorial series about world position offset

Part 1: Transform position
Part 2: Scaling objects

If we want to scale our cube model instead of applying a position transform, we can do it too using world position offset. In this second part of the tutorial we are going to learn how to do it.

To able to do that we need to find a solution to send different information to each vertex. If we send the same position offset to all the vertices the cube will only change their position, but if each vertex has a different position offset then the model will obtain a deformation.

cube_deformation

We can say it is a direction vector of the vertex. We can use the magnitude to the vector to increase or reduce the distance of the displacement, and the direction to control the movement direction.

To store this information in the vertices of the model we are going to use the technique of vertex painting.

We can open our model in Blender and enable the Vertex painting view using the view selector

blender_vertex_paint

To select only a vertex we can enable the vertex option right to the view selector, and with the Select Box select the vertex in the 3D view using left mouse click. We can hold shift key to select multiple vertices at the same time.

blender_vertex_select

To select the color just right mouse click on the screen and a color picker appear.

blender_color_picker

Now we can paint all the selected vertices using the menu Paint > Set Vertex Colors

blender_setcolor

Using this steps we are going to paint the superior vertices of our model using white color and the bottom vertices using black color

4cube_vertexpainting

We are using the color like a mask. Black vertices will not move from their position using the world position offset, but white vertices will do. As we are going to define an only vertical world position offset then the cubes will obtain a deformation equals to a scale effect of their vertical axis.

Now we can use this parameter in our UE4 Materials to apply this “mask”.

When a model with Vertex Color info is added to our project we need to check that the option of Vertex Color is set to Replace to import this info from the model.

ue4_import_vertex_color

In our material we can use the Vertex Color node to retrieve this information.

material_vertex_color_node

Now we can modify our previous material to use the vertex color information.

ue4_material_cube_scale

Using this material our model cubes will be scaled instead of moved from the original position

cube_deformation

Tutorial files

Support this blog!

For the past year I've been dedicating more of my time to the creation of tutorials, mainly about game development. If you think these posts have either helped or inspired you, please consider supporting this blog. Thank you so much for your contribution!

Write a Comment

Comment