Hi. Here’s the general idea how to use this. The RecordRenderGraph should look something like this:
public override void RecordRenderGraph( RenderGraph renderGraph, ContextContainer frameData )
{
UniversalResourceData resourceData = frameData.Get< UniversalResourceData >();
UniversalCameraData cameraData = frameData.Get< UniversalCameraData >();
if ( resourceData.isActiveTargetBackBuffer )
{
return;
}
RenderTextureDescriptor renderTextureDesc = cameraData.cameraTargetDescriptor;
renderTextureDesc.depthBufferBits = 0;
TextureHandle sceneColor = resourceData.activeColorTexture;
TextureHandle texture1 = UniversalRenderer.CreateRenderGraphTexture( renderGraph, renderTextureDesc, "Texture 1", false );
TextureHandle texture2 = UniversalRenderer.CreateRenderGraphTexture( renderGraph, renderTextureDesc, "Texture 2", false );
AddBlitPass( renderGraph, sceneColor, texture1, "Render only red channel to texture 1", 0 );
int additionalTextureId = Shader.PropertyToID( "_AdditionalTexture" );
TextureBindInfo info = new TextureBindInfo { slot = additionalTextureId, texture = sceneColor };
// This pass will have texture1 bound to _BlitTexture and sceneColor bound to the _AdditionalTexture in your shader
// _BlitTexture is the default name for the source texture and _AdditionalTexture is a parameter you define so it can have whatever name
AddBlitPass( renderGraph, texture1, texture2, "Render red and green channel to texture 2", 1, info );
// sceneColor texture is the texture that is finally displayed on the screen so now we just render back to sceneColor to display our results
renderGraph.AddBlitPass( texture2, sceneColor, Vector2.one, Vector2.zero );
}
And here is an example shader:
Shader "CustomEffects/ExampleShader"
{
SubShader
{
Blend One Zero
Tags
{
"RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"
}
LOD 100
ZWrite Off Cull Off
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
TEXTURE2D( _AdditionalTexture );
#define SAMPLE_BLIT(uv) SAMPLE_TEXTURE2D( _BlitTexture, sampler_LinearClamp, uv )
ENDHLSL
Pass
{
Name "Pass 0"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Pass0
float4 Pass0( Varyings input ) : SV_Target
{
float2 uv = input.texcoord;
float red = SAMPLE_BLIT( uv ).r;
return float4( red, 0, 0, 1 );
}
ENDHLSL
}
Pass
{
Name "Pass 1"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Pass1
float4 Pass1( Varyings input ) : SV_Target
{
float2 uv = input.texcoord;
float red = SAMPLE_BLIT( uv ).r; // This samples from the result of the previous pass
float green = SAMPLE_TEXTURE2D( _AdditionalTexture, sampler_LinearClamp, uv ).g
return float4( red, green, 0, 1 );
}
ENDHLSL
}
}
}
Of course you can do much more in the RecordRenderGraph function like dynamically changing shader parameters (by calling material.SetFloat etc) or dynamically adding or removing entire passes.
(Small disclaimer: I just wrote this code in a text editor without testing it in engine because I haven’t used unity for a few months and don’t have it installed right now but I think it should work fine)