Tire Tracks in Snow - A Graphics class Project
1. Introduction
Cars and vehicles are becoming popular in Open World games. They play a very important role for the player to navigate through a level or map easily and quickly. Racing games have a different genre altogether. But do all games provide a complete experience of driving the car in the virtual world? The answer to this depends on the attention to detail given to the graphics while creating it. Factors such as the reaction of the vehicle to the environment really matter when developing such an experience for the player. Games such as Forza Horizon series, Gran Tourismo, Dirt Rally, the world famous Need For Speed series have given close attention to creating a breathtaking experience for the players. With increasing hardware development in GPU rendering of graphics, it has become possible for implementing a tiny level of details in games.
In this blog post, I present a project which is built in Unreal Engine 4 to implement a simple technique to deform snow when a vehicle's tire starts rolling on a snow terrain. The technique is simple and can be implemented in Unreal Engine 4 using the Physics Asset Material Editor in Unreal and making heavy use of blueprints for functionality with Render Target. Figure 1. shows the screenshot of the result attained.
In this blog post, I present a project which is built in Unreal Engine 4 to implement a simple technique to deform snow when a vehicle's tire starts rolling on a snow terrain. The technique is simple and can be implemented in Unreal Engine 4 using the Physics Asset Material Editor in Unreal and making heavy use of blueprints for functionality with Render Target. Figure 1. shows the screenshot of the result attained.
There are different scenarios in every level of a racing game. If we take a look at the Dirt Rally by Codemasters, the game has levels in all type of weather conditions. One of which is a snow terrain. This project is flexible enough to implement the same idea in a desert where we would not deform the snow but would deform the sand.
2. Why render Tire tracks in Snow?
Consider a scenario where it starts to snow and a vehicle is moving on the road. The snow starts depositing on the ground. Due to the weight of the vehicle, the tires make an imprint on the road. This is what happens in the real world scenario. Figure 2.1 shows the tire imprints on the road in a real-world scene.
Figure 2.1 Tire tracks in the real world scenario.
We always want a real feel in the games we play, therefore it is necessary to depict these conditions in the game. This project looks at a small problem which is imprinting the tire texture on a static mesh in the landscape of the game. Games are meant for people to experience a real-world scene in a virtual world. Small details provide the players an immersive experience.
3. Requirements
3.1 Enable the Collision UV
To imprint the tire tracks in the snow we need to find the UV coordinates for a collision impact. The project won't work if we can't get the collision UV to trace the texture. So we first need to enable 'Support UV from Hit Results' in the Physics Settings in the Project Settings.
3.2 Adding landscape as a Static Mesh
We need a landscape to test our vehicle and its functionality. Also, we need the snow material on something which should be a static mesh. We can get the collision for the landscape by using the Unreal Engine's inbuilt function to add Collision to the static mesh by setting the Collision Complexity to use as 'Use Complex Collision As Simple'. This way it is easier as well as a quick way to get collision locations accurately.
Figure 3.1. A Landscape as a Static Mesh.
3.3 Vehicle
The most important part of this project is the vehicle itself. This project is flexible enough to use any kind of vehicle or actor as long as it is an object made out of modeling software like 3ds Max, Maya, etc. In this project, I have used the Buggy from the VehicleGame content provided by Unreal.
4. Vehicle Creation
4.1. Creating Vehicle Physics Asset
The vehicle creation has various steps and assets to make the vehicle work as it should in a real world. The vehicle blueprint requires assets such as Skeletal Mest, Wheel Blueprints, a vehicle animation blueprint, etc.
From the Skeletal Mesh, we need to create a Physics Asset. After creating the Physics asset, we need to create the physics bodies as Unreal Engine does not have the best way to handle the recreation of the constraints. Now, in the Physics Asset Tool (PhAT) we will have to create all the physics bodies on the joints of the vehicle to get the desired behavior (such as the antenna, rotation of the wheels, suspension effect, etc.)
The Physics body needs to be added for every joint as we do not want the vehicle to get stuck in the terrain. I added the spheres for all the four wheels, sphyl (capsule shape) to the front and back bumpers, and box to the vehicle itself. We need to keep the settings for the Physics type of the wheel to kinematic. Also, I added a sphyl to the antenna and gave it a swing motion so that it moves to a limited angle while the vehicle experiences any jerk. It is not required but a small addition looks nice while driving the buggy and gives a little bit of realistic feel.
An important factor to be noted at this step was the wheels rotated in a very weird manner. This is fixed in the later part where a vehicle blueprint is created. The Figure 4.1. shows all the Physics or Collision bounding structures around the vehicle created in the PhAT.
Figure 4.1. Vehicle Physics Bodies in PhAT
4.2 Creating Vehicle Blueprint
The wheels should animate while the vehicle is in motion, i.e., clockwise for moving forward and anti-clockwise for moving in reverse. For this, a blueprint is created for the Vehicle Animation. The Animation blueprint has an Anim Graph which contains animation nodes which sample the animation sequences, perform animation blends, control bone transformations. The skeletal mesh gets the resulting pose applied to it for every frame of the game.
The Wheel Handler node will take care of all the animation regarding the wheels like spinning, steering, handbrake and the suspension. The Vehicles Physics Asset and Skeletal mesh both contain bones for the vehicle suspensions so we will create additional nodes to handle the joints that affect the suspension polygons. There is a node which takes care of the requirement which is 'Look At' node. We will create four instances of these nodes for each and every wheel joint such as the; Bone to modify will be Front Left, Front Right, Back Left, and Back Right suspensions & we will look at the joints of Front Left, Front Right, Back Left and Back Right wheel joints respectively.
Also, we need to make blueprints for the Back wheels and Front wheels where we'll edit the properties like shape radius, shape width, affected by handbrake, steering angle and tire type. We need to make sure that the steering angle is 0 for the back wheels and some value for the front wheels.
We would also need a camera to follow our vehicle. This camera will have static properties of its location and rotation as it should follow the vehicle only during its movement.
We would also need a camera to follow our vehicle. This camera will have static properties of its location and rotation as it should follow the vehicle only during its movement.
4.3. Setting up Controls for the vehicle
For setting up the controls in Unreal, it is easy as Unreal has options for Action Mapping and Axis mapping.
- Action Mapping: Only the key presses and releases are mapped in these types of mapping such as pressing and releasing of the spacebar for pulling the handbrake.
- Axis Mapping: They allow inputs to have continuous range and direction like accelerating and directing the vehicle.
We can bind the keys in the classic W, A, S, D format or the Arrow keys. The best feature of Unreal Engine is that it has the option to add any game console controller's key bindings as well.
4.4. Scripting movement behaviors
Scripting the vehicle movement is straightforward as the blueprint has nodes such as 'InputAxis MoveForward', 'InputAxis MoveRight', 'InputAction Handbrake'. All these nodes are easy to setup and also understanding them is quite simple.
5. Flowchart or Algorithm
5.1. Required textures
There are different textures required for the project, I chose three textures, they are:- Black & white textureThe Black and white texture as shown in the Figure 5.1.a. will be used for the roughness of the snow. So in the terrain, it looks like snow and not like a plain texture laid out without any particles formation.
`Figure 5.1.a. Roughness providing texture.This texture can be scaled in the texture blueprint by manipulating the values in the SnowScale parameter. - NormalMapThe normal map is just a texture which has little bumps in it to provide small bumps and dents. It is a good way to have more detail without using more polygons. Figure 5.1.b. shows the small bumps in the texture.
Figure 5.1.b. Normal map texture for bumps.
When the normal map and the roughness texture are multiplied together, it gives a realistic looking snow texture with some bumps and tiny bits of particles deposited on the terrain. - Tire textureWithout the tire texture, nothing would work. The tire pattern decides how the imprint would be. So depending on the tire I chose this pattern to closely match the texture with the tire tracks.Figure 5.1.c. Tire texture.
Figure 5.1.c. shows the zig-zag pattern for the buggy. It is a black & white texture which decides the deformation. The black part is pushed down on the landscape and the white part will remain untouched.
5.2. Project algorithm
The custom event called SnowHit triggers the drawing of the texture on the terrain. For the tire texture intensity, I have declared a variable which provides control over the tracing scale of the tire tracks on the landscape. We will use tesselation as PN triangles to get a maximum detailed look at the texture. Figure 5.1 shows the custom event called SnowHit which is used to draw the material to render target.
Whenever there is a collision of the tire with the static mesh the SnowHit event is going to fire. It will start drawing to the render target which is the snow deform texture. The tire scale is provided by the user which will be static for now but can be made dynamic in the future by implementing complex algorithm and logic. The UV position for the trace is provided by the event tick.
5.3. Event Tick
This is where the collision and the position for the collision are determined. As we use tessellation we can make use of the World Displacement in the Material Node. The idea is really simple to get the UV location from the collision and tracing the texture from it further.
Figure 5.2.2. Flowchart for tracing the texture on the Static Mesh
The socket location is determined from the mesh. We check if the wheel is standing still. If it is standing still we do not do any trace. If the wheel starts moving it get a location and sets a new location. This logic is repeated for each and every wheel and the logic will render the texture at the same time. We can also decide the depth of the snow and check if the wheel is really deep enough to trace the texture. Now we will check if the wheel collides with the static mesh. If it collides with the static mesh then it will get its world location and the node will cast the location and the rotation to the custom event. We choose the Yaw (Z) location as we need the wheel to be in the same direction as the trace texture.
6. Conclusion
In this project, I was able to successfully implement the idea of deforming snow and imprint the tire tracks on a landscape, in this case, a static mesh. Features of controlling the parameters such as the SnowScale, SnowOffset (Depth), TireStrength, TireScale and the affecting range for the tracing texture are implemented to have full control. The project is flexible enough to implement a different kind of texture such as Sand to change the environment to a desert. Also, different Physics Assets can be easily added such as a motocross bike.
7. Future Scope
I see a lot of future implementation of adding a snowy windy weather effect in the map and implementing an algorithm to cover the tracks back again with snow due to inclement weather. Also, the map or the landscape can be created with scaled snow accumulated depth levels to provide more immersive experience as there would be different levels of deformations.
8. References and Links
1. Emperore, K., Sherry, D., (2015), Unreal Engine Physics Essentials, Packt Publishing.
2. Project Repository
3. Demo Video
Comments
Post a Comment