Unity post-processing is an absolute game-changer in taking your visuals from good to amazing. It is the secret ingredient that can really make a beautiful game go from nice to a visual masterpiece. For the purposes of this deep-dive tutorial, we will be exploring Unity’s post-processing stack, advancing the techniques and best practices on how to take your game’s visuals to the next level.
1. Understanding Post-Processing in Unity
Post-processing refers to the collection of special effects that are put on top of the rendered image once your scene has been fully rendered. These effects pass over the final image so you can provide color-enhancing effects, atmospheric effects, and can even simulate camera properties or even do much more.
History of post-processing in Unity
Unity has been through several iterations of its post-processing system:
- Legacy Image Effects: Legacy – Now deprecated.
- Introduces Post-Processing Stack v1, which comes with Unity 5.6. Better performance and easier to use than v1.
- Post-Processing Stack v2 – a new full rewrite with more effects at better performance than v1.
- Universal Render Pipeline (URP) post-processing is natively included in the pipeline for maximum performance.
- HDRP post-processing offers advanced effects for high-end platforms.
In this article, we’ll focus mostly on the Post-Processing Stack v2 and URP post-processing as these are the most used in current Unity projects.
2. Setting Up the Post-processing in Unity
Before we go into individual effects, let’s set up post-processing in your Unity project:
For the Post-Processing Stack v2 (Built-in Render Pipeline):
Open the Package Manager (Window > Package Manager)
- Search for “Post Processing” and download the latest version
- You add a Post-Process Layer to your camera in your scene
- You add a Post-Process Volume to your scene from GameObject > 3D Object > Post-process Volume
- You add a new Post-Process Profile and assign it to the Volume
For Universal Render Pipeline (URP):
- You ensure you have URP installed and set up in your project
- In your URP Asset, ensure that “Post Processing” is enabled
- You add a Volume component to an empty GameObject in your scene
- Create and attach a Volume Profile
- Enable “Post Processing” in your Camera component
Pro Tip:Â Always use linear color space for the most accurate and high-quality results. You can set this in Edit > Project Settings > Player > Other Settings > Color Space.
3. Essential Post-Processing Effects
Let’s explore some of the most powerful post-processing effects and how to use them effectively:
3.1 Bloom
Bloom creates a kind of glow around the bright areas in your scene, simulating how light bleeds out to areas into surrounding areas in real cameras. It is very effective for dreamy atmosphere creation or deepening sources of light.
// Example Bloom settings (Post-Processing Stack v2) Bloom bloom = postProcessVolume.profile.AddSettings(); bloom.intensity.value = 1f; bloom.threshold.value = 1f; bloom.softKnee.value = 0.5f; bloom.diffusion.value = 7f; bloom.anamorphicRatio.value = 0f; // 0 for circular, 1 for horizontal, -1 for vertical
Best Practices for Bloom:
- Use bloom sparingly; overuse can lead to an unrealistic, overly-stylized look
- Adjust the threshold to control which parts of the image bloom
- Experiment with anamorphic ratio for unique directional bloom effects
3.2 Ambient Occlusion
Ambient Occlusion (AO): it darkens areas that objects meet, or where one object is not allowing light to get through to some other adjacent game object. This effect provides you with depth and realism scenes as it simulates soft shadows that fall into crevices, corners and other contact areas.
// Example Ambient Occlusion settings (Post-Processing Stack v2) AmbientOcclusion ao = postProcessVolume.profile.AddSettings(); ao.intensity.value = 1.5f; ao.radius.value = 0.3f; ao.quality.value = AmbientOcclusionQuality.High; ao.color.value = Color.black;
Best Practices for Ambient Occlusion:
- Balance intensity carefully; too much AO can make your scene look flat or unrealistic
- Adjust the radius based on the scale of your scene
- Use higher quality settings for final builds, but consider performance impact
3.3 Color Grading
Color Grading is a pretty strong effect that lets you control the overall color and contrast and mood of your scene. It’s useful specifically to create a certain atmosphere, as well as to match the visual style of your game to a particular aesthetic.
Color grading in Unity includes several sub-effects:
- Tone Mapping:Â Adjusts how HDR colors are mapped to the final image
- White Balance:Â Adjusts color temperature and tint
- Lift, Gamma, Gain:Â Fine-tune shadows, midtones, and highlights
- Channel Mixer:Â Adjust individual color channels
- Color Wheels:Â Adjust colors for shadows, midtones, and highlights
- LUT (Look-Up Texture):Â Apply a predefined color grading preset
// Example Color Grading settings (Post-Processing Stack v2) ColorGrading colorGrading = postProcessVolume.profile.AddSettings(); colorGrading.gradingMode.value = GradingMode.HighDefinitionRange; colorGrading.tonemapper.value = Tonemapper.ACES; colorGrading.temperature.value = 10f; // Warm up the image colorGrading.tint.value = 5f; // Add a slight magenta tint colorGrading.postExposure.value = 0.5f; // Brighten the image colorGrading.saturation.value = 10f; // Increase color saturation colorGrading.contrast.value = 10f; // Increase contrast
Best Practices for Color Grading:
- Use a neutral LUT as a starting point and adjust from there
- Consider different color grades for different environments or times of day
- Be mindful of color theory and how different color palettes affect mood
- Use split-toning to add depth to shadows and highlights
3.4 Depth of Field
Depth of Field simulates the lens focusing on a specific distance, blurring objects that appear too close or too far. This effect can draw attention to certain parts of your scene and add a cinematic quality to your game.
// Example Depth of Field settings (Post-Processing Stack v2) DepthOfField dof = postProcessVolume.profile.AddSettings(); dof.focusDistance.value = 10f; dof.aperture.value = 5.6f; dof.focalLength.value = 50f; dof.kernelSize.value = KernelSize.Medium;
Best Practices for Depth of Field:
- Use DoF sparingly, as it can be disorienting if overused
- Consider animating focus distance for dramatic effect in cutscenes
- Experiment with different aperture sizes for varying levels of background blur
- Be mindful of performance, especially on mobile devices
4. Advanced Post-Processing Techniques
4.1 Custom Post-Processing Effects
While Unity’s built-in effects are powerful, you can create custom post-processing effects for unique visuals. This involves writing custom shaders and integrating them into the post-processing stack.
// Example custom post-processing effect (simplified) Shader "Hidden/Custom/Pixelate" { Properties { _MainTex ("Texture", 2D) = "white" {} _PixelSize ("Pixel Size", Float) = 0.01 } SubShader { Pass { CGPROGRAM #pragma vertex vert_img #pragma fragment frag #include "UnityCG.cginc" sampler2D _MainTex; float _PixelSize; fixed4 frag (v2f_img i) : SV_Target { float2 uv = i.uv; uv -= fmod(uv, _PixelSize); return tex2D(_MainTex, uv); } ENDCG } } }
4.2 Stacking and Blending Effects
Combining multiple post-processing effects can create complex and unique visual styles. Understanding how effects interact and the order in which they’re applied is crucial for achieving the desired look.
Typical Post-Processing Stack Order:
- Anti-aliasing
- Ambient Occlusion
- Screen Space Reflections
- Depth of Field
- Motion Blur
- Panini Projection
- Bloom
- Lens Distortion
- Chromatic Aberration
- Color Grading
- Vignette
- Grain
4.3 Performance Optimization
While post-processing can greatly enhance visuals, it can also impact performance. Here are some tips for optimizing post-processing:
- Use the profiler to identify performance bottlenecks
- Adjust effect quality based on the target platform
- Consider using fewer effects for mobile or VR projects
- Optimize your scenes to reduce the workload on the GPU
- Use volume blending to transition between different post-processing profiles
Performance Warning: Be especially cautious with screen-space effects like Screen Space Reflections and Ambient Occlusion, as they can be particularly demanding on hardware.
5. Post-Processing for Different Game Genres
Different game genres often benefit from specific post-processing approaches:
Genre | Recommended Effects | Notes |
---|---|---|
Horror | Vignette, Grain, Color Grading | Use dark color grading and vignette to create a claustrophobic atmosphere |
Sci-Fi | Bloom, Chromatic Aberration | Emphasize neon lights and create a futuristic feel |
Fantasy | Bloom, Color Grading, Depth of Field | Create a magical atmosphere with warm colors and soft focus |
Realistic | Ambient Occlusion, Tonemapping, Minimal Color Grading | Aim for subtle enhancements that maintain realism |
6. Future of Post-Processing in Unity
As Unity continues to evolve, we can expect to see advancements in post-processing technology:
- Improved real-time ray tracing integration
- More advanced AI-assisted post-processing techniques
- Better performance optimizations for high-quality effects on mobile devices
- Enhanced VR-specific post-processing effects
Conclusion
Mastering Unity’s post-processing capabilities requires a serious trek to be taken seriously. Really, there is no other way to express it – mastering those capabilities does really step up the visual quality of your games. In that respect, knowing the ins and outs of each effect, testing a few combinations, and optimizing for performance really makes all the difference between something pleasurable to watch and something really taking your breath away.
Remember, subtlety and purpose is the path to fantastic post-processing work. Each effect must play to tell the overall visual story of your game while driving up player experience without distracting your audience from it. The more you practice and hone your craft, the better you will be at finding that magical balance which can bring out the essence of your vision.
That’s all. We hope with this extensive guide, you have all the tools and knowledge needed to bring your Unity game’s visuals to the next level. Happy developing!