Top Related Projects
Unity Graphics - Including Scriptable Render Pipeline
Streaming server for Unity
Testbed project for Unity HDRP (High Definition Render Pipeline)
Post Processing Stack
Lighting effects implemented for the Adam demo: volumetric fog, area lights and tube lights
Quick Overview
HDRP-Custom-Passes is a GitHub repository that provides a collection of custom render passes for Unity's High Definition Render Pipeline (HDRP). It offers various visual effects and rendering techniques that can be easily integrated into HDRP projects, enhancing the visual quality and flexibility of Unity games and applications.
Pros
- Extends HDRP capabilities with additional rendering features
- Easy integration into existing HDRP projects
- Provides a variety of visual effects and post-processing options
- Open-source, allowing for community contributions and modifications
Cons
- Requires Unity HDRP, limiting compatibility with other rendering pipelines
- May impact performance on lower-end hardware due to advanced rendering techniques
- Documentation could be more comprehensive for some custom passes
- Potential learning curve for developers new to HDRP custom passes
Code Examples
- Adding a custom pass to the HDRP render pipeline:
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
[System.Serializable, VolumeComponentMenu("Post-processing/Custom/MyCustomPass")]
public class MyCustomPass : CustomPass
{
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
// Setup code here
}
protected override void Execute(CustomPassContext ctx)
{
// Execution code here
}
}
- Implementing a simple outline effect:
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
public class OutlinePass : CustomPass
{
public Material outlineMaterial;
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
// Ensure the outline material is created
if (outlineMaterial == null)
outlineMaterial = CoreUtils.CreateEngineMaterial("Hidden/Outline");
}
protected override void Execute(CustomPassContext ctx)
{
// Render the outline effect
CoreUtils.DrawFullScreen(ctx.cmd, outlineMaterial);
}
}
- Applying a custom post-processing effect:
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
[System.Serializable, VolumeComponentMenu("Post-processing/Custom/ColorTint")]
public class ColorTintPass : CustomPass
{
public ColorParameter tintColor = new ColorParameter(Color.white);
protected override void Execute(CustomPassContext ctx)
{
var material = new Material(Shader.Find("Hidden/ColorTint"));
material.SetColor("_TintColor", tintColor.value);
CoreUtils.DrawFullScreen(ctx.cmd, material);
}
}
Getting Started
- Clone the HDRP-Custom-Passes repository or download the desired custom pass scripts.
- Add the custom pass scripts to your Unity HDRP project.
- Create a new Custom Pass Volume in your scene (Add Component > Rendering > Custom Pass Volume).
- In the Custom Pass Volume component, add the desired custom pass from the "Add Custom Pass" dropdown.
- Configure the parameters of the custom pass in the Inspector window.
- Adjust the Injection Point to control when the custom pass is executed in the rendering pipeline.
Competitor Comparisons
Unity Graphics - Including Scriptable Render Pipeline
Pros of Graphics
- Official Unity repository, ensuring compatibility and long-term support
- Comprehensive graphics package covering various rendering techniques
- Regular updates and contributions from Unity's development team
Cons of Graphics
- Larger codebase, potentially more complex to navigate and understand
- May include features beyond custom passes, which could be overwhelming
Code Comparison
HDRP-Custom-Passes:
[CustomPassDrawer("My Custom Pass")]
class MyCustomPass : CustomPass
{
protected override void Execute(CustomPassContext ctx)
{
// Custom pass implementation
}
}
Graphics:
[VolumeComponentMenu("Post-processing/Custom Effect")]
public class CustomEffect : VolumeComponent, IPostProcessComponent
{
public BoolParameter enable = new BoolParameter(false);
public bool IsActive() => enable.value;
public bool IsTileCompatible() => false;
}
Summary
Graphics is the official Unity repository for graphics-related features, offering a comprehensive solution with regular updates. HDRP-Custom-Passes focuses specifically on custom rendering passes, providing a more targeted approach. While Graphics offers broader functionality, HDRP-Custom-Passes may be easier to navigate for developers primarily interested in custom passes. The code examples demonstrate the different approaches: HDRP-Custom-Passes uses a dedicated CustomPass class, while Graphics utilizes the VolumeComponent system for post-processing effects.
Streaming server for Unity
Pros of UnityRenderStreaming
- Designed for real-time streaming of Unity content over the web
- Supports WebRTC for low-latency video and audio streaming
- Includes signaling functionality for establishing peer connections
Cons of UnityRenderStreaming
- Focused on streaming, not custom rendering techniques
- May have higher performance overhead due to streaming capabilities
- Less flexibility for custom rendering passes compared to HDRP-Custom-Passes
Code Comparison
HDRP-Custom-Passes:
[System.Serializable, VolumeComponentMenu("Post-processing/Custom/MyCustomPass")]
public sealed class MyCustomPass : CustomPass
{
protected override void Execute(CustomPassContext ctx)
{
// Custom rendering logic here
}
}
UnityRenderStreaming:
public class StreamingHandler : MonoBehaviour
{
private void Start()
{
var streamingManager = GetComponent<StreamingManager>();
streamingManager.Run(WebRTCSettings.SignalingURL);
}
}
The code snippets highlight the different focus areas of each project. HDRP-Custom-Passes allows for custom rendering passes within the High Definition Render Pipeline, while UnityRenderStreaming emphasizes setting up and managing streaming connections.
Testbed project for Unity HDRP (High Definition Render Pipeline)
Pros of TestbedHDRP
- More comprehensive set of HDRP examples and test cases
- Regularly updated with the latest Unity and HDRP versions
- Includes advanced rendering techniques like ray tracing
Cons of TestbedHDRP
- Less focused on custom passes specifically
- May be overwhelming for beginners due to its breadth of content
- Requires more setup and configuration to get started
Code Comparison
TestbedHDRP:
[CustomPassDrawer("My Custom Pass")]
class MyCustomPass : CustomPass
{
protected override void Execute(CustomPassContext ctx)
{
// Custom rendering logic here
}
}
HDRP-Custom-Passes:
[System.Serializable, VolumeComponentMenu("Custom Passes/Example/Outline Pass")]
public class OutlineCustomPass : CustomPass
{
protected override void Execute(CustomPassContext ctx)
{
// Outline rendering logic here
}
}
Both repositories provide examples of implementing custom passes in HDRP, but HDRP-Custom-Passes offers more specialized and focused examples for custom pass implementation, while TestbedHDRP covers a broader range of HDRP features and techniques.
Post Processing Stack
Pros of PostProcessing
- Widely adopted and well-established in the Unity community
- Supports both built-in render pipeline and URP
- Extensive documentation and community support
Cons of PostProcessing
- Limited flexibility for custom effects
- May have performance overhead for some effects
- Not optimized for HDRP-specific features
Code Comparison
PostProcessing:
[PostProcess(typeof(PostProcessRenderer), PostProcessEvent.AfterStack, "Custom/Effect")]
public sealed class CustomEffect : PostProcessEffectSettings
{
public FloatParameter intensity = new FloatParameter { value = 1f };
}
HDRP-Custom-Passes:
class CustomPass : CustomPass
{
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) {}
protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera camera, CullingResults cullingResult) {}
protected override void Cleanup() {}
}
The PostProcessing package uses a more traditional approach with effect settings and renderers, while HDRP-Custom-Passes provides a more flexible and HDRP-specific implementation with custom passes.
Lighting effects implemented for the Adam demo: volumetric fog, area lights and tube lights
Pros of VolumetricLighting
- Official Unity repository, potentially offering better integration and support
- Focuses specifically on volumetric lighting, which may provide more advanced features in this area
- Likely to be more regularly updated and maintained by Unity Technologies
Cons of VolumetricLighting
- Limited to volumetric lighting effects, less versatile than HDRP-Custom-Passes
- May require more setup and configuration for specific use cases
- Potentially more resource-intensive due to its specialized nature
Code Comparison
HDRP-Custom-Passes:
[System.Serializable]
public class CustomPassVolume : MonoBehaviour
{
public List<CustomPass> customPasses = new List<CustomPass>();
}
VolumetricLighting:
[System.Serializable]
public class VolumetricLightingSettings
{
public float scattering = 0.5f;
public float extinction = 0.5f;
}
The code snippets show that HDRP-Custom-Passes offers a more flexible approach with customizable passes, while VolumetricLighting provides specific settings for volumetric lighting effects. HDRP-Custom-Passes allows for a wider range of custom rendering effects, whereas VolumetricLighting is tailored for achieving realistic atmospheric lighting.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
HDRP-Custom-Passes
A bunch of custom passes made for HDRP. This project have been setup for Unity 2022.3 version with HDRP 14.x.
If you're looking for older versions, you can find them in the git branches: 2020.2/3, 2021.2/3.
TIPS Effect:
Features:
- Edge detect
- Draw Mesh
- Compositing with fullscreen pass
Source file link for this effect: TIPS.cs and TIPS.shader
Slight Blur Effect:
Features:
- 2 Pass gaussian blur and a downscale
- Masking to not blur certain part of the screen using meshes
Source file link for this effect: SlightBlur.cs and Blur.shader
Outline Effect:
Source file link for this effect: 02_Selection_Objects.shader and 02_Selection_Fullscreen.shader
Effect made without custom C#, setup in the inspector:
See Through Effect:
Source file link for this effect: SeeThrough.cs and SeeThroughStencil.shader
AR Effect:
Features:
- Early depth pass
- Composite with video in background
Glitch Effect:
Features:
- Display a "bad reception" effect over objects of specified layer, using the following shader:
Scrolling Formulas Effect:
Features:
- Uses a builtin fullscreen custom pass and a custom pass fullscreen shader
- Triplanar mapping
Liquid
Features:
- Meta balls made by bluring normals
- Visual Effect Graph inside a custom pass
- Overriding depth and normals of a fullscreen transparent to emulate a surface
Glass
Features:
- Thickness aproximation using a custom pass rendering backfaces in custom depth
Depth Capture
Features:
- Render objects from a different camera and output their depth in a depth buffer
- Source code: CameraDepthBake.cs
Render With Normal Buffer
Rendering objects in the normal buffer is essential to make objects work with screen space effects. This example show how to create a custom pass that renders an object in the depth, normal and color buffer so the SSAO can correctly be applied (you can see the exagerated SSAO effect in this screenshot)
And this is the same image without rendering the object to the normal buffer:
As you can see the SSAO is completely messed-up
Note that because you need to render the object in both depth-prepass and forward pass, you need two custom passes volume with different injection points:
ScreenSpace Camera UI Blur
This effect blurs the camera color buffer and renders the screenspace UI on top of it. It is intended to be used in the after post process injection point
Note that this custom pass also avoid z test issues when doing this kind of as the transparent objects are rendered after everything.
Render Video Without TAA
This effect allows you to render an object (for example a video player) without TAA. It uses custom post processes to achieve this, so be sure to have the "VideoPlaybackWithoutTAAPostProcess" post process in your HDRP default settings:
.
As you can see in the videos, this pass will remove all artifacts visible when an object doesn't have valid motion vector data (which is the case for most texture animation or video playback):
With TAA:
https://user-images.githubusercontent.com/6877923/116881360-77e10300-ac23-11eb-8a19-f176d2364f11.mp4
Without TAA:
https://user-images.githubusercontent.com/6877923/116881366-78799980-ac23-11eb-97b0-5f8aa18f9b3c.mp4
By default in this effect, the fixDepthBufferJittering
field is disabled because it's a very costly operation (re-render all the objects in the scene into an unjittered depth buffer) but it allows to get rid of all TAA artifacts remaining after you add this effect (mainly depth jittering).
Custom pass effect sources: Assets/CustomPasses/Video Playback Without TAA.
Render Object Motion Vectors
Render the Object motion vectors (not camera motion vectors!) into a render texture
Sources: Assets/CustomPasses/RenderMotionVectors
Copy Buffer
Custom pass that can copy the following buffers to a render texture:
- Color
- Normal
- Roughness
- Depth
- Motion Vectors
Source: Assets/CustomPasses/CopyPass
Screen Space Wetness
Effect that modifies the normal and roughness buffers in screen space to give a "wet" effect to objects. Sources: Assets/CustomPasses/Wetness
It's also compatible with ShaderGraph using the SubGraph "EncodeIntoToNormalBuffer".
https://user-images.githubusercontent.com/6877923/195407733-1e73b63c-5ba6-488f-829d-d4cb0d0b1412.mp4
Current Depth To Custom Depth
Duing HDRP rendering, you only have access to the depth buffer that contains all opaque objects, the depth texture is not updated when rendering transparent with depth pre/post passes.
This custom pass copies the current camera depth (up to date with the current injection point) to the custom depth buffer. The custom depth buffer can then be sampled in a fullscreen shader graph using the custom depth node.
Source file for this effect: CurrentDepthToCustomDepth.cs and CurrentDepthToCustomDepth.shader.
Top Related Projects
Unity Graphics - Including Scriptable Render Pipeline
Streaming server for Unity
Testbed project for Unity HDRP (High Definition Render Pipeline)
Post Processing Stack
Lighting effects implemented for the Adam demo: volumetric fog, area lights and tube lights
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot