VFX for Vrena
Jens-Stefan Mikson, Hanno Soo
Aim of this project is to create additional visual effects to an already existing game Vrena. Vrena is a virtual reality multiplayer first person shooter. It is a student project and still a work in progress. A video of the game can be seen here.
In total we plan on creating three effects:
- Spark particles
- X-ray vision
- Wind trails
Github repository: https://github.com/mikson60/VisualEffects
Executable (requires VR set): https://drive.google.com/open?id=1SJKSP8Evf7vctXjJZNQ118urIiHNGdN4
Sparks
When a physical object (rigidbody) collides with another object, sparks should emit from the point of contact (imagine angle grinder cutting metal). The end result should look something like in this video.
It is important that the stronger a collision, the more sparks there should be. If rigidbodies slide on each other, sparks should be created only when the velocity of both of the bodies is high enough.
While not necessary it would be nice if the visual effect was accompanied by a sound effect.
Milestone 1 (18.11.2018)
Configured a spark emitter using trails. Also added some collider support.
21.11.2018
Improved collision handling to work better with multiple collisions. Changed direction from cone to sphere.
X-ray
The goal of X-ray is to see objects that are behind some other objects. The user should be able to toggle x-ray on and off. A video of this effect can be seen here.
If x-ray is on, the vision can be defined in the following way:
- The part of the model that is not occluded by anything (and thus, is visible to the camera) should be drawn normally (with the material's default textures). An outline could be around the visible part as well but this is not necessary.
- The part of the model that is occluded should be displayed as a a hologram, with no default material visible.
If time is not an issue, these effects can be added:
- When x-ray is toggled (for on and off), a distortion effect should be played.
- X-ray can be time based. The closer time is to ending the x-ray ability, the stronger the glitch effect of the hologram.
Milestone 1 (18.11.2018)
Hologram shader works, however currently some parts of the default texture are still visible through the wall. Currently, the hologram effect is applied to the model even in areas where the object is visible. This might be left as it is.
On-screen wind trails
On-screen trails should appear when the camera moves fast. The faster the camera moves, the more emphazised the trail effect should be. An example video of the wind trails can be seen here.
Milestone 1 (18.11.2018)
Maximize video to see the trails.
The wind effect in the video was achieved using Unity's particle system, with a semi-transparent material. This needs further testing in virtual reality.
Report
Introduction
The project consists of 3 visual effects, which were successfully implemented. The effects are the sparks effect, xray effect and a wind trail effect. All of these were created using the Unity3D game engine. They were created for a virtual reality game called Vrena. The following video shows all of these 3 effects in action:
Sparks module
This is a Unity3D module/component (prefab + script) that will enable adding this visual effect to any object. Sparks are created when this object collides with any other object in the scene. The intensity and amount of sparks generated depends on the relative velocity of the colliding objects.
The main visual goal was to emulate realistic looking metallic sparks. Metal sparks happen when a metal object grinds against some other hard object. Friction causes small heated metal pieces to fly out from the contact point. After some time in the air the pieces burn up and slow down disappearing to dust. There is a large amount of variance in the speed, direction and duration of each spark. However, most of the sparks will be moving in the same general direction as the object causing the sparks.
To be usable in Vrena this effect had to be suitable for virtual reality applications. To make the effect look good from all perspectives it had to exist in full three dimensions, no shortcuts using sprites.
Finally, the effect should be easy to integrate into any other Unity3D project as a simple module. Real case performance should still be measured.
Used tools and tech
Sparks are essentially small particles so we used Unity3D's particle system tool. This allowed fully configuring an object that generates a varied amount of tiny similar objects with short lifespans. Large amount of this effect was configuring this particle system tool to emit spark like particles. The particles themselves are not actually visible but we attached trails to them. This allows creating various length particles that curve with gravity. This simulates a fast moving spark looking like a trail of light to the human eye.
Controlling the emission rate and direction of sparks was done by a Unity3D script written in C#. This script is based on collision events enter, stay and exit. A copy of the pre-configured particle system is used and modified during the collision.
Main complications
It was my first time using Unity3D so it took a lot of time an effort to be able to use it in the first place. Using and connecting VR equipment to the project was not quite trivial as well. All in all it took around the same amount of effort to set up a development and testing environment as it took to actually create the visual effects.
X-ray
X-ray effect enables the user to see certain objects through other objects, creating a colored silhouette around the target, which looks similar to a hologram. The purpose of this effect was to give players in Vrena an ability to see through the walls and thus giving advantage to the player using the x-ray vision. While speaking about x-rays in real life, people image seeing bones of other living beings, however in this project, only the see-through effect of x-rays is considered. No actual bones of objects in the scene are rendered.
Used tools and tech
In order for the Unity3D game engine to render objects for the camera, every visible object has a mesh (a set of vertices), a material and a shader. The material is used to modify shader parameters and is used by the mesh to display the 3D model. Shaders are most typically used to calculate the lighting on objects, which they are applied on, and thus give these objects their appearance. In order to get the x-ray working, a shader was written in Shader Lab using the Cg / HLSL language, which was applied to a material used on a model.
The shader was written in 2 parts. The first part calculates the visibility and lighting of the object when occluded by some other object and the second part calculates lighting when object is not occluded by anything. This separation (using shader passes), using mostly depth buffer, is what gives the ability to render objects completely differently when occluded by something or not. When an object is not occluded by anything, a simple diffuse shader with shadows is used. However, when a part of the mesh is behind an object, the edge of the object is calculated (using the dot product between the edge fragment's normal and camera view direction) and colored based on the edge/rim strength and user defined color. The rest of the fragments (away from the edge) are transparent or semi-transparent.
Main complications
Even though shaders were written throught the CG course, I personally am still quite unskilled in writing shaders in Unity, so it took some time to get used to the workflow of the shader and the way it is written. Calculating the edges of the mesh and coloring them was done quite quickly, because the logic behind it is quite simple. However, the first milestone resulted in a shader that created hologram edges for the object even when it was not occluded by anything and had errors when seen through other objects. Fixing these errors and using multiple shader passes, were what made this task a bit more complicated than it initially seemed to be. Understanding the concepts of blending and depth buffer were required to finish this effect.
Wind trails
Wind trails are on screen lines that appear on the camera as players move around the scene. The faster they move, the more emphasized the lines are, creating kind of a tunnel vision effect. It is a visual effect used commonly in science fiction, especially giving a view through the window of a space ship (especially if the space ship travels at FTL speeds). Another good example would be the wind trail effect in a VR title called Eagle Flight.
The physical reason for this would be that as a camera or a person in real life moves faster, the particles of air or other objects start to appear to visually stretch. The faster the movement, the more the object is stretched. If the object is small enough, and speed high enough, the stretched object might appear to be a line instead.
The purpose of this effect was to provide feedback to the user about their movement speed and reduce motion sickness in VR, induced by moving at high speeds with little to no existence of frames of reference. The more emphasized the effect, the better and clear the frame of reference, and the smaller the field of view, which in turn helps reduce motion sickness in VR.
Used tools and tech
Initially the plan was to use multiple textures with wind trails on them, and based on the velocity of the player, the textures would blend between each other, giving the effect of appearing and disappearing wind trails. The biggest downfall of this was that when the player's viewing direction did not match the movement direction, the effect would look flawed. When moving at high speeds, then in the direction of the movement should display lines coming straight at the player. When looking to the left side, for example, the lines should appear to be moving from the right edge of the screen to the left. However, using the blending technique would require some more advanced techniques to blend textures based on player's rotation.
In order to actually complete this task, Unity's built-in particle system was used. The intensity of the effect based on the speed of the player. And the direction of the wind trails was also in relation with the direction of the movement, no matter where the player looked. 2D sprites in a 3D world were used as lines that flew towards the player. If the player moves at high speeds and looks behind him, he could see the white trails moving away from him. The achieved result looks good and interesting in VR. the 2D sprites do not break immersion.
Main complications
Out of all three effects, this one was the easiest to develop. Most of the time was spent on tweaking the effect and its visual appearance based on the speed of the player.