Code

Code from this week is up at this google drive folder!

Collisions in VFX Graph

A question came up about physical collisions in VFX graph. Because everything is GPU based it's quite constrained -- you can specify geometry like planes or spheres and if you need to collide with objects in the scene the best you can do is collide with a camera's depth buffer.

Volume-Based Post Processing

We looked at post processing and full screen shader effects this week. Unity has a few different approaches, the simplest the "volume framework". You can have multiple volumes in your scenes and each volume can have its own post-processing stack associated with it. Whenever a camera is inside a volume it will take on the post-processing of its volume.

The simplest thing you can do is use the "global" volume that is always available and always active. To get to it, navigate to Settings > PC_RPAsset in your Project tab.

You will see many of the standard post-processing effects there -- like Bloom, Vignette, Depth of Field. They are easy to enable and use right away with no code or shaders if all you need is a simple global always-on effect.

Color Grading

Scrolling down and pressing "Add Override" exposes the remaining built in post-processing effects. There are some subtle but important options here, particularly Color Curves, Lift Gama Gain. You can tweak them as if your game was in Photoshop to adjust the final colors in the render of each frame.

The adjustments you can make here will depend on your game and the look you're going for. Color grading and color theory can fill an entire classes on their own, and you should look up general color grading tutorials -- they will apply in Unity! Here's a Unity specific one I like.

Unity has many overrides and you should experiment with them, depending in your game's needs. A good breakdown from 4 years ago can be found in this video

` # Look Up Tables Related to color grading are look up tables or "LUTs". They are mappings from one color space to another, packaged as 3D textures. They're a great way to apply polish to your renders, similar to color grading but more powerful in

You can make your own by

  1. Taking a screenshot of your game
  2. Loading it in Photoshop
  3. Adjusting its curves, exposure, contrast etc in adjustment layers
  4. Applying the same adjustment layers to a neutral LUT
  5. Using the resulting LUT in a Unity under the "Color Lookup" Override, "Lookup Texture" property

There are also many LUT packs available on the Asset Store for quite cheap

Full Screen Shaders

Volume based post processing is great but limited in that you cannot really make your own effects. For that you need to write a Full Screen Shader effect and load it into Unity's rendering Pipeline

  1. Create a Full Screen Shader in your project with Create > Shader Graph > URP > Fullscreen Shader Graph
  2. Create a Material in your project with Create > Material
  3. Set the Material's Shader to be the Fullscreen Shader Graph shader you just made the way we've done before with normal Shader Graph shaders
  4. In your Project tab navigate to Settings > PC_Renderer to find the Universal Render Data settings in the inspector

  1. At the bottom click "Add Render Feature" to add a full screen render pass
  2. Choose your Fullscreen Shader material as the Pass Material

Now anything you put in the Fullscreen Shader Graph shader will process the pixels of your game! All the normal Shader Graph techniques apply here. Keep in mind that the "URP Sample Buffer" is how you access the pixels of the screen. This was the shader I made to implement an FPS damage effect.

Cameras

A few things about cameras:

You can render any camera to a texture rather than the screen

  1. Create a "Render Texture" in your project with Create > Rendering > Render Texture
  2. Set this render texture as the Output Texture property in your camera's inspector (under Output)

This texture can then be used anywhere you'd use a texture. This can be useful in some post-processing tricks, or for something as simple as an in-game security camera by applying the texture to a mesh.

You can stack cameras

  1. Choose a camera you want to layer on top of another
  2. Set its Render Type to "Overlay"
  3. Choose your main camera
  4. Add the overlay camera to its camera stack

This allows you to layer the images that the cameras render on top of each other. Combined with layers and the cameras' culling masks you can achieve certain effects like minimaps and user interfaces with ease.