Class Blitter
Various blit (texture copy) utilities for the Scriptable Render Pipelines.
Inherited Members
Namespace: UnityEngine .Rendering
Assembly: Unity.RenderPipelines.Core.Runtime.dll
Syntax
public static class Blitter
Remarks
The Blitter class works on textures and targets identified with Texture,
Render
To use the Blitter functionality in the context of custom Scriptable Render Pipelines, you must first create
a blit shader that implements various passes covering the blit variants. To facilitate this, you can create a
modified version of the Universal Render Pipeline CoreBlit.shader
as displayed in the documentation of the
Initialize(Shader, Shader) method.
Prior to using the Blitter, you must call Initialize(Shader, Shader) once. When the render pipeline is to be disposed, you must call the Cleanup() method to dispose of resources created by the Blitter.
Methods
BlitCameraTexture(CommandBuffer, RTHandle, RTHandle, float, bool)
Adds in a Command
Declaration
public static void BlitCameraTexture(CommandBuffer cmd, RTHandle source, RTHandle destination, float mipLevel = 0, bool bilinear = false)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
RTHandle | destination | RTHandle of the destination render target to copy to. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | bilinear | Enable bilinear filtering when copying. |
Remarks
Camera related textures are created with CreatescaleBias
parameter. The copy operation will always write to the full destination render target rectangle.
Examples
// Create an XR texture that has half the width and height of the camera's back buffer.
TextureDesc texDesc = new TextureDesc(new Vector2(0.5f, 0.5f), false, true);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Do a full copy of the texture's first mip level to a destination render target
// scaling with bilinear filtering to the destination render target's full rect.
Blitter.BlitCameraTexture(cmd, source, destination, 0, true);
BlitCameraTexture(CommandBuffer, RTHandle, RTHandle, Material, int)
Adds in a Command
Declaration
public static void BlitCameraTexture(CommandBuffer cmd, RTHandle source, RTHandle destination, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
RTHandle | destination | RTHandle of the destination render target to copy to. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
Camera related textures are created with the CreatescaleBias
parameter of these methods. The copy operation will always write to the full destination render target rectangle.
The "_BlitTexture" shader property will be set to the source
texture and the "_BlitScaleBias" shader
property will be set to the appropriate parameter, prior to the draw.
This overload is equivalent
to BlitloadAction
set to Load and the storeAction
set
to Store.
Examples
// Create a texture that has half the width and height of the camera's back buffer.
TextureDesc texDesc = new TextureDesc(new Vector2(0.5f, 0.5f), false, false);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Do a full copy of a source texture to a destination render target using the first pass
// of a custom material, scaling to the destination render target's full rectangle.
Blitter.BlitCameraTexture(cmd, source, dest, blitMaterial, 0);
BlitCameraTexture(CommandBuffer, RTHandle, RTHandle, Rect, float, bool)
Adds in a Command
Declaration
public static void BlitCameraTexture(CommandBuffer cmd, RTHandle source, RTHandle destination, Rect destViewport, float mipLevel = 0, bool bilinear = false)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
RTHandle | destination | RTHandle of the destination render target to copy to. |
Rect | destViewport | Rect of the destination viewport to write to. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | bilinear | Enable bilinear filtering when copying. |
Remarks
Camera related textures are created with the CreatescaleBias
parameter. The copy operation will write to the destViewport
viewport Rect.
Examples
// Create an XR texture that has half the width and height of the camera's back buffer.
TextureDesc texDesc = new TextureDesc(new Vector2(0.5f, 0.5f), false, true);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Do a full copy of the texture's first mip level to a destination render target
// scaling with bilinear filtering to a custom 512 x 256 pixels viewport.
Blitter.BlitCameraTexture(cmd, source, destination, new Rect(0, 0, 512, 256), 0, true);
BlitCameraTexture(CommandBuffer, RTHandle, RTHandle, RenderBufferLoadAction, RenderBufferStoreAction, Material, int)
Adds in a Command
Declaration
public static void BlitCameraTexture(CommandBuffer cmd, RTHandle source, RTHandle destination, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
RTHandle | destination | RTHandle of the destination render target to copy to. |
Render |
loadAction | Load action to perform on the destination render target prior to the copying. |
Render |
storeAction | Store action to perform on the destination render target after the copying. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
Camera related textures are created with the CreatescaleBias
parameter. The copy operation will always write to the full destination render target rectangle.
The "_BlitTexture" shader property will be set to the source
texture and the "_BlitScaleBias" shader
property will be set to the appropriate value, prior to the draw.
Examples
// Create a texture that has half the width and height of the camera's back buffer.
TextureDesc texDesc = new TextureDesc(new Vector2(0.5f, 0.5f), false, false);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Do a full copy of a source texture to a destination render target using the first pass
// of a custom material, scaling to the destination render target's full rectangle. Since
// the destination will be overwritten, mark the load action as "Don't care".
Blitter.BlitCameraTexture(cmd, source, dest, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, blitMaterial, 0);
BlitCameraTexture(CommandBuffer, RTHandle, RTHandle, Vector4, float, bool)
Adds in a Command
Declaration
public static void BlitCameraTexture(CommandBuffer cmd, RTHandle source, RTHandle destination, Vector4 scaleBias, float mipLevel = 0, bool bilinear = false)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
RTHandle | destination | RTHandle of the destination render target to copy to. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | bilinear | Enable bilinear filtering when copying. |
Remarks
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Create a texture that has half the width and height of the camera's back buffer.
TextureDesc texDesc = new TextureDesc(new Vector2(0.5f, 0.5f), false, false);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Copy the bottom left quadrant of the source texture's second mip level to the
// destination render target, scaling with bilinear filtering to the destination
// render target's full rect.
Blitter.BlitCameraTexture(cmd, source, dest, new Vector4(0.5f, 0.5f, 0f, 0f), 1, true);
BlitCameraTexture2D(CommandBuffer, RTHandle, RTHandle, float, bool)
Adds in a Command
Declaration
public static void BlitCameraTexture2D(CommandBuffer cmd, RTHandle source, RTHandle destination, float mipLevel = 0, bool bilinear = false)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
RTHandle | destination | RTHandle of the destination render target to copy to. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | bilinear | Enable bilinear filtering when copying. |
Remarks
Camera related textures are created with the CreatescaleBias
parameter. The copy operation will always write to the full destination render target rectangle.
Examples
// Create a texture that has half the width and height of the camera's back buffer.
TextureDesc texDesc = new TextureDesc(new Vector2(0.5f, 0.5f), false, false);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Do a full copy of the texture's first mip level to a destination render target
// scaling with bilinear filtering to the destination render target's full rect.
Blitter.BlitCameraTexture(cmd, source, destination, 0, true);
BlitColorAndDepth(CommandBuffer, Texture, RenderTexture, Vector4, float, bool)
Adds in a Command
Declaration
public static void BlitColorAndDepth(CommandBuffer cmd, Texture sourceColor, RenderTexture sourceDepth, Vector4 scaleBias, float mipLevel, bool blitDepth)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | sourceColor | Source color texture to copy from. |
Render |
sourceDepth | Source depth render texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | blitDepth | Enable copying of the source depth texture. |
Remarks
Although the depth render texture can be passed as a parameter, the copying of the depth information is
optional and must be enabled with the blitDepth
parameter.
The copying is done using the blitColorAndDepth
shader passed as the second argument of
the Initialize(Shader, Shader) method.
This overload is meant for textures and render targets which depend on XR output modes by proper handling, when necessary, of left / right eye data copying. This generally corresponds to textures which represent full screen data that may differ between eyes.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of a source texture and depth texture to the render target
// using bilinear sampling, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitColorAndDepth(cmd, sourceColor, sourceDepth, new Vector4(0.5, 0.5, 0, 0), 0, true);
// Copy the top half of mip level 4 of both a source color texture and depth texture to the
// render target using nearest sampling, scaling to the destination render target's full
// rectangle.
Blitter.BlitColorAndDepth(cmd, sourceColor, sourceDepth, new Vector4(1, 0.5, 0, 0.5), 4, true);
BlitColorAndDepth(RasterCommandBuffer, Texture, RenderTexture, Vector4, float, bool)
Adds in a Raster
Declaration
public static void BlitColorAndDepth(RasterCommandBuffer cmd, Texture sourceColor, RenderTexture sourceDepth, Vector4 scaleBias, float mipLevel, bool blitDepth)
Parameters
Type | Name | Description |
---|---|---|
Raster |
cmd | Command Buffer used for recording the action. |
Texture | sourceColor | Source color texture to copy from. |
Render |
sourceDepth | Source depth render texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | blitDepth | Enable copying of the source depth texture. |
Remarks
Although the depth render texture can be passed as a parameter, the copying of the depth information is
optional and must be enabled with the blitDepth
parameter.
The copying is done using the blitColorAndDepth
shader passed as the second argument of
the Initialize(Shader, Shader) method.
This overload is meant for textures and render targets which depend on XR output modes by proper handling, when necessary, of left / right eye data copying. This generally corresponds to textures which represent full screen data that may differ between eyes.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of a source texture and depth texture to the render target
// using bilinear sampling, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitColorAndDepth(cmd, sourceColor, sourceDepth, new Vector4(0.5, 0.5, 0, 0), 0, true);
// Copy the top half of mip level 4 of both a source color texture and depth texture to the
// render target using nearest sampling, scaling to the destination render target's full
// rectangle.
Blitter.BlitColorAndDepth(cmd, sourceColor, sourceDepth, new Vector4(1, 0.5, 0, 0.5), 4, true);
BlitCubeToOctahedral2DQuad(CommandBuffer, Texture, Vector4, int)
Adds in a Command
Declaration
public static void BlitCubeToOctahedral2DQuad(CommandBuffer cmd, Texture source, Vector4 scaleBiasRT, int mipLevelTex)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source cube texture to copy from. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
Remarks
The scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Copy the third mip level of a source cube map texture to the center rect
// of a 3x3 grid on the current render target, like so:
// +-------+ + - + - + - +
// / / | | | | |
// +-------+ | + - +---+ - +
// | | | --> | | X | |
// | | + + - +---+ - +
// | | / | | | |
// +-------+ + - + - + - +
Vector4 center3by3 = new Vector4(1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f);
Blitter.BlitCubeToOctahedral2DQuad(cmd, source, center3by3, 2);
BlitCubeToOctahedral2DQuadSingleChannel(CommandBuffer, Texture, Vector4, int)
Adds in a Command
Declaration
public static void BlitCubeToOctahedral2DQuadSingleChannel(CommandBuffer cmd, Texture source, Vector4 scaleBiasRT, int mipLevelTex)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source cube texture to copy from. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
Remarks
The conversion to a single channel output depends on the source texture's format:
Texture Format | Output conversion |
---|---|
RGB(A) | the RGB luminance is written to the destination in all channels. |
Red | the red value is written to the destination in all channels. |
Alpha | the alpha value is written to the destination in all channels. |
scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Copy the third mip level of a source cube map texture to the center rect
// of a 3x3 grid on the current render target, like so:
// +-------+ + - + - + - +
// / / | | | | |
// +-------+ | + - +---+ - +
// | | | --> | | X | |
// | | + + - +---+ - +
// | | / | | | |
// +-------+ + - + - + - +
Vector4 center3by3 = new Vector4(1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f);
Blitter.BlitCubeToOctahedral2DQuadSingleChannel(cmd, source, center3by3, 2);
BlitCubeToOctahedral2DQuadWithPadding(CommandBuffer, Texture, Vector2, Vector4, int, bool, int, Vector4?)
Adds in a Command
Declaration
public static void BlitCubeToOctahedral2DQuadWithPadding(CommandBuffer cmd, Texture source, Vector2 textureSize, Vector4 scaleBiasRT, int mipLevelTex, bool bilinear, int paddingInPixels, Vector4? decodeInstructions = null)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source cube texture to copy from. |
Vector2 | textureSize | Source texture size in pixels. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
bool | bilinear | Enable bilinear filtering. |
int | paddingInPixels | Padding in pixels to add in all directions to the source rect. |
Vector4? | decodeInstructions | The purpose of this parameter is to blit HDR-encoded values to a non HDR texture. Use values from API that produce HDR-encoded values, for example texture |
Remarks
The source cube map pixels are copied onto the destination rect with extra padding pixels taken from the source texture
but using a specific octahedral mirror repeat mode. Both source rect pixels and padding pixels are blitted inside the destination rect.
See Blit
The scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Copy the third mip level of a source cube map texture to the center rect
// of a 3x3 grid on the current render target, like so:
// +-------+ + - + - + - +
// / / | | | | |
// +-------+ | + - +---+ - +
// | | | --> | | X | |
// | | + + - +---+ - +
// | | / | | | |
// +-------+ + - + - + - +
// Desired padding on the destination rect
int paddingInPixelsOneDirection = 16;
// Multiply by two for the total padding along an axis.
int paddingInPixels = 2 * paddingInPixelsOneDirection;
Vector4 center3by3 = new Vector4(1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f);
Vector2 subTextureSize = new Vector2(sourceWidth, sourceHeight);
// HDR to non-HDR decoding is not necessary here so drop the
// last parameter.
Blitter.BlitCubeToOctahedral2DQuadWithPadding(cmd, source, subTextureSize, center3by3, 2, paddingInPixels);
BlitOctahedralWithPadding(CommandBuffer, Texture, Vector2, Vector4, Vector4, int, bool, int)
Adds in a Command
Declaration
public static void BlitOctahedralWithPadding(CommandBuffer cmd, Texture source, Vector2 textureSize, Vector4 scaleBiasTex, Vector4 scaleBiasRT, int mipLevelTex, bool bilinear, int paddingInPixels)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source texture to copy from. |
Vector2 | textureSize | Source texture size in pixels. |
Vector4 | scaleBiasTex | Scale and bias for sampling the source texture. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
bool | bilinear | Enable bilinear filtering. |
int | paddingInPixels | Padding in pixels to add in the destination rect.
This is the total padding on an axis so to have N pixels added to the left, and N pixels to the right, |
Remarks
Diagram detailing the use of the padding, textureSize, scaleBiasTex and scaleBiasRT.
The source rect is copied to the destination rect along with extra padding pixels taken from the source texture
but, compared to Blit
The scaleBiasTex
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets.
Similarly, the scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Create a 512 x 256 texture.
int sourceWidth = 512;
int sourceHeight = 256;
TextureDesc texDesc = new TextureDesc(sourceWidth, sourceHeight, false, false);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Copy the top right quadrant of the source texture's first mip level to the bottom left
// quadrant of the current render target, without bilinear filtering, with 16 pixels of
// padding.
int paddingInPixelsOneDirection = 16;
// Multiply by two for the total padding along an axis.
int paddingInPixels = 2 * paddingInPixelsOneDirection;
Vector4 topRight = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
Vector4 bottomLeft = new Vector4(0.5f, 0.5f, 0.0f, 0.0f);
Vector2 subTextureSize = new Vector2(sourceWidth, sourceHeight);
Blitter.BlitOctahedralWithPadding(cmd, source, subTextureSize, topRight, bottomLeft, 0, false, paddingInPixels);
BlitOctahedralWithPaddingMultiply(CommandBuffer, Texture, Vector2, Vector4, Vector4, int, bool, int)
Adds in a Command
Declaration
public static void BlitOctahedralWithPaddingMultiply(CommandBuffer cmd, Texture source, Vector2 textureSize, Vector4 scaleBiasTex, Vector4 scaleBiasRT, int mipLevelTex, bool bilinear, int paddingInPixels)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source texture to copy from. |
Vector2 | textureSize | Source texture size in pixels. |
Vector4 | scaleBiasTex | Scale and bias for sampling the source texture. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
bool | bilinear | Enable bilinear filtering. |
int | paddingInPixels | Padding in pixels to add in all directions to the source rect. |
Remarks
The source rect is blended onto the destination rect with a multiplicative blend, with extra padding pixels taken
from the source texture but, compared to Blit
The scaleBiasTex
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets.
Similarly, the scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Create a 512 x 256 texture.
int sourceWidth = 512;
int sourceHeight = 256;
TextureDesc texDesc = new TextureDesc(sourceWidth, sourceHeight, false, false);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Copy the top right quadrant of the source texture's first mip level to the bottom left
// quadrant of the current render target, without bilinear filtering, with 16 pixels of
// padding.
int paddingInPixelsOneDirection = 16;
// Multiply by two for the total padding along an axis.
int paddingInPixels = 2 * paddingInPixelsOneDirection;
Vector4 topRight = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
Vector4 bottomLeft = new Vector4(0.5f, 0.5f, 0.0f, 0.0f);
Vector2 subTextureSize = new Vector2(sourceWidth, sourceHeight);
Blitter.BlitOctahedralWithPaddingMultiply(cmd, source, subTextureSize, topRight, bottomLeft, 0, false, paddingInPixels);
BlitQuad(CommandBuffer, Texture, Vector4, Vector4, int, bool)
Adds in a Command
Declaration
public static void BlitQuad(CommandBuffer cmd, Texture source, Vector4 scaleBiasTex, Vector4 scaleBiasRT, int mipLevelTex, bool bilinear)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source texture to copy from. |
Vector4 | scaleBiasTex | Scale and bias for sampling the source texture. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
bool | bilinear | Enable bilinear filtering. |
Remarks
The scaleBiasTex
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets.
Similarly, the scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Copy the top right quadrant of the source texture's first mip level to the bottom left
// quadrant of the current render target, without bilinear filtering.
Vector4 topRight = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
Vector4 bottomLeft = new Vector4(0.5f, 0.5f, 0.0f, 0.0f);
Blitter.BlitQuad(cmd, source, topRight, bottomLeft, 0, false);
BlitQuadSingleChannel(CommandBuffer, Texture, Vector4, Vector4, int)
Adds in a Command
Declaration
public static void BlitQuadSingleChannel(CommandBuffer cmd, Texture source, Vector4 scaleBiasTex, Vector4 scaleBiasRT, int mipLevelTex)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source texture to copy from. |
Vector4 | scaleBiasTex | Scale and bias for sampling the source texture. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
Remarks
The conversion to a single channel output depends on the source texture's format:
Texture Format | Output conversion |
---|---|
RGB(A) | the RGB luminance is written to the destination in all channels. |
Red | the red value is written to the destination in all channels. |
Alpha | the alpha value is written to the destination in all channels. |
The scaleBiasTex
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets.
Similarly, the scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Copy the top right quadrant of the source texture's first mip level to the bottom left
// quadrant of the current render target, without bilinear filtering.
Vector4 topRight = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
Vector4 bottomLeft = new Vector4(0.5f, 0.5f, 0.0f, 0.0f);
Blitter.BlitQuadSingleChannel(cmd, source, topRight, bottomLeft, 0, false);
BlitQuadWithPadding(CommandBuffer, Texture, Vector2, Vector4, Vector4, int, bool, int)
Adds in a Command
Declaration
public static void BlitQuadWithPadding(CommandBuffer cmd, Texture source, Vector2 textureSize, Vector4 scaleBiasTex, Vector4 scaleBiasRT, int mipLevelTex, bool bilinear, int paddingInPixels)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source texture to copy from. |
Vector2 | textureSize | Source texture size in pixels. |
Vector4 | scaleBiasTex | Scale and bias for sampling the source texture. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
bool | bilinear | Enable bilinear filtering. |
int | paddingInPixels | Padding in pixels to add in the destination rect.
This is the total padding on an axis so to have N pixels added to the left, and N pixels to the right, |
Remarks
Diagram detailing the use of the padding, textureSize, scaleBiasTex and scaleBiasRT.
The source rect is copied to the destination rect along with extra padding pixels taken from the source texture
using the texture's wrap
The scaleBiasTex
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets.
Similarly, the scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Create a 512 x 256 texture.
int sourceWidth = 512;
int sourceHeight = 256;
TextureDesc texDesc = new TextureDesc(sourceWidth, sourceHeight, false, false);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Copy the top right quadrant of the source texture's first mip level to the bottom left
// quadrant of the current render target, without bilinear filtering, but with 16 pixels
// of padding.
int paddingInPixelsOneDirection = 16;
// Multiply by two for the total padding along an axis.
int paddingInPixels = 2 * paddingInPixelsOneDirection;
Vector4 topRight = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
Vector4 bottomLeft = new Vector4(0.5f, 0.5f, 0.0f, 0.0f);
Vector2 subTextureSize = new Vector2(sourceWidth, sourceHeight);
Blitter.BlitQuadWithPadding(cmd, source, subTextureSize, topRight, bottomLeft, 0, false, paddingInPixels);
BlitQuadWithPaddingMultiply(CommandBuffer, Texture, Vector2, Vector4, Vector4, int, bool, int)
Adds in a Command
Declaration
public static void BlitQuadWithPaddingMultiply(CommandBuffer cmd, Texture source, Vector2 textureSize, Vector4 scaleBiasTex, Vector4 scaleBiasRT, int mipLevelTex, bool bilinear, int paddingInPixels)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Texture | source | The source texture to copy from. |
Vector2 | textureSize | Source texture size in pixels. |
Vector4 | scaleBiasTex | Scale and bias for sampling the source texture. |
Vector4 | scaleBiasRT | Scale and bias for the destination quad. |
int | mipLevelTex | Mip level of the source texture to sample. |
bool | bilinear | Enable bilinear filtering. |
int | paddingInPixels | Padding in pixels to add in the destination rect.
This is the total padding on an axis so to have N pixels added to the left, and N pixels to the right, |
Remarks
The source rect is blended to the destination rect with a multiplicative blend, along with extra padding pixels taken from the source texture
using the texture's wrap
The scaleBiasTex
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets.
Similarly, the scaleBiasRT
parameter controls the rectangle of pixels in the render target to write to by manipulating
the destination quad coordinates. The X and Y coordinates store the scaling factor to apply to texture
coordinates, while the Z and W coordinates store the coordinate offsets.
Examples
// Create a 512 x 256 texture.
int sourceWidth = 512;
int sourceHeight = 256;
TextureDesc texDesc = new TextureDesc(sourceWidth, sourceHeight, false, false);
RTHandle source = renderGraph.CreateTexture(texDesc);
// Copy the top right quadrant of the source texture's first mip level to the bottom left
// quadrant of the current render target, without bilinear filtering, with 16 pixels of
// padding.
int paddingInPixelsOneDirection = 16;
// Multiply by two for the total padding along an axis.
int paddingInPixels = 2 * paddingInPixelsOneDirection;
Vector4 topRight = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
Vector4 bottomLeft = new Vector4(0.5f, 0.5f, 0.0f, 0.0f);
Vector2 subTextureSize = new Vector2(sourceWidth, sourceHeight);
Blitter.BlitQuadWithPaddingMultiply(cmd, source, subTextureSize, topRight, bottomLeft, 0, false, paddingInPixels);
BlitTexture(CommandBuffer, RTHandle, Vector4, float, bool)
Adds in a Command
Declaration
public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, float mipLevel, bool bilinear)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | bilinear | Enable bilinear filtering when copying. |
Remarks
Copying is performed using the blit shader passed as the first argument of the Initialize(Shader, Shader) method.
This overload is meant for textures and render targets which depend on XR output modes by proper handling, when necessary, of left / right eye data copying. This generally correspond to textures which represent full screen data that may differ between eyes.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of the source texture to the render target using bilinear
// sampling, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitTexture(cmd, source, new Vector4(0.5, 0.5, 0, 0), 0, true);
// Copy the top half of the source texture's mip level 4 to the render target using nearest
// sampling, scaling to the destination render target's full rectangle.
Blitter.BlitTexture(cmd, source, new Vector4(1, 0.5, 0, 0.5), 4, false);
BlitTexture(CommandBuffer, RTHandle, Vector4, Material, int)
Adds in a Command
Declaration
public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
The source
texture will be bound to the "_BlitTexture" shader property.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of the source texture to the render target using the first
// pass of a custom material, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitTexture(cmd, source, new Vector4(0.5, 0.5, 0, 0), blitMaterial, 0);
// Copy the top half of the source texture mip level 4 to the render target using the
// second pass of a custom material, scaling to the destination render target's full
// rectangle.
Blitter.BlitTexture(cmd, source, new Vector4(1, 0.5, 0, 0.5), blitMaterial, 1);
BlitTexture(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, Material, int)
Adds in a Command
Declaration
public static void BlitTexture(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Render |
source | RenderTargetIdentifier of the source texture to copy from. |
Render |
destination | RenderTargetIdentifier of the destination render target to copy to. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
he source
texture will be bound to the "_BlitTexture" shader property.
This overload is equivalent
to BlitloadAction
set to Load and the storeAction
set to Store.
Examples
// Do a full copy of a source texture to a destination render target using the first pass
// of a custom material, scaling to the destination render target's full rectangle.
Blitter.BlitTexture(cmd, source, dest, blitMaterial, 0);
BlitTexture(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, RenderBufferLoadAction, RenderBufferStoreAction, Material, int)
Adds in a Command
Declaration
public static void BlitTexture(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Render |
source | RenderTargetIdentifier of the source texture to copy from. |
Render |
destination | RenderTargetIdentifier of the destination render target to copy to. |
Render |
loadAction | Load action to perform on the destination render target prior to the copying. |
Render |
storeAction | Store action to perform on the destination render target after the copying. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
The source
texture will be bound to the "_BlitTexture" shader property.
Examples
// Do a full copy of a source texture to a destination render target using the first pass
// of a custom material, scaling to the destination render target's full rectangle. Since
// the destination will be overwritten, mark the load action as "Don't care".
Blitter.BlitTexture(cmd, source, dest, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, blitMaterial, 0);
BlitTexture(CommandBuffer, RenderTargetIdentifier, Vector4, Material, int)
Adds in a Command
Declaration
public static void BlitTexture(CommandBuffer cmd, RenderTargetIdentifier source, Vector4 scaleBias, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Render |
source | RenderTargetIdentifier of the source texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
The source
texture will be bound to the "_BlitTexture" shader property.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of the source texture to the render target using the first
// pass of a custom material, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitTexture(cmd, source, new Vector4(0.5, 0.5, 0, 0), blitMaterial, 0);
// Copy the top half of the source texture mip level 4 to the render target using the
// second pass of a custom material, scaling to the destination render target's full
// rectangle.
Blitter.BlitTexture(cmd, source, new Vector4(1, 0.5, 0, 0.5), blitMaterial, 1);
BlitTexture(CommandBuffer, Vector4, Material, int)
Adds in a Command
Declaration
public static void BlitTexture(CommandBuffer cmd, Vector4 scaleBias, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
This method gives you freedom on how to write your blit shader by just taking a material, assumed to
be properly configured with input textures already bound to the material. In this method, the "_BlitScaleBias" shader
property will be set on the material to the scaleBias
parameter, prior to the draw.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
BlitTexture(RasterCommandBuffer, RTHandle, Vector4, float, bool)
Adds in a Raster
Declaration
public static void BlitTexture(RasterCommandBuffer cmd, RTHandle source, Vector4 scaleBias, float mipLevel, bool bilinear)
Parameters
Type | Name | Description |
---|---|---|
Raster |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | bilinear | Enable bilinear filtering when copying. |
Remarks
Copying is performed using the blit shader passed as the first argument of the Initialize(Shader, Shader) method.
This overload is meant for textures and render targets which depend on XR output modes by proper handling, when necessary, of left / right eye data copying. This generally correspond to textures which represent full screen
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of the source texture to the render target using bilinear
// sampling, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitTexture(cmd, source, new Vector4(0.5, 0.5, 0, 0), 0, true);
// Copy the top half of the source texture's mip level 4 to the render target using nearest
// sampling, scaling to the destination render target's full rectangle.
Blitter.BlitTexture(cmd, source, new Vector4(1, 0.5, 0, 0.5), 4, false);
BlitTexture(RasterCommandBuffer, RTHandle, Vector4, Material, int)
Adds in a Raster
Declaration
public static void BlitTexture(RasterCommandBuffer cmd, RTHandle source, Vector4 scaleBias, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Raster |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
The source
texture will be bound to the "_BlitTexture" shader property.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of the source texture to the render target using the first
// pass of a custom material, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitTexture(cmd, source, new Vector4(0.5, 0.5, 0, 0), blitMaterial, 0);
// Copy the top half of the source texture mip level 4 to the render target using the
// second pass of a custom material, scaling to the destination render target's full
// rectangle.
Blitter.BlitTexture(cmd, source, new Vector4(1, 0.5, 0, 0.5), blitMaterial, 1);
BlitTexture(RasterCommandBuffer, RenderTargetIdentifier, Vector4, Material, int)
Adds in a Raster
Declaration
public static void BlitTexture(RasterCommandBuffer cmd, RenderTargetIdentifier source, Vector4 scaleBias, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Raster |
cmd | Command Buffer used for recording the action. |
Render |
source | RenderTargetIdentifier of the source texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
The source
texture will be bound to the "_BlitTexture" shader property.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of the source texture to the render target using the first
// pass of a custom material, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitTexture(cmd, source, new Vector4(0.5, 0.5, 0, 0), blitMaterial, 0);
// Copy the top half of the source texture mip level 4 to the render target using the
// second pass of a custom material, scaling to the destination render target's full
// rectangle.
Blitter.BlitTexture(cmd, source, new Vector4(1, 0.5, 0, 0.5), blitMaterial, 1);
BlitTexture(RasterCommandBuffer, Vector4, Material, int)
Adds in a Command
Declaration
public static void BlitTexture(RasterCommandBuffer cmd, Vector4 scaleBias, Material material, int pass)
Parameters
Type | Name | Description |
---|---|---|
Raster |
cmd | Command Buffer used for recording the action. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
Material | material | The material to use for writing to the destination target. |
int | pass | The index of the pass to use in the material's shader. |
Remarks
This method gives you freedom on how to write your blit shader by just taking a material, assumed to
be properly configured with input textures already bound to the material. In this method, the "_BlitScaleBias" shader
property will be set on the material to the scaleBias
parameter, prior to the draw.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
BlitTexture2D(CommandBuffer, RTHandle, Vector4, float, bool)
Adds in a Command
Declaration
public static void BlitTexture2D(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, float mipLevel, bool bilinear)
Parameters
Type | Name | Description |
---|---|---|
Command |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | bilinear | Enable bilinear filtering when copying. |
Remarks
Copying is performed using the blit shader passed as the first argument of the Initialize(Shader, Shader) method.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of the source texture to the render target using bilinear
// sampling, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitTexture2D(cmd, source, new Vector4(0.5, 0.5, 0, 0), 0, true);
// Copy the top half of the source texture's mip level 4 to the render target using nearest
// sampling, scaling to the destination render target's full rectangle.
Blitter.BlitTexture2D(cmd, source, new Vector4(1, 0.5, 0, 0.5), 4, false);
BlitTexture2D(RasterCommandBuffer, RTHandle, Vector4, float, bool)
Adds in a Raster
Declaration
public static void BlitTexture2D(RasterCommandBuffer cmd, RTHandle source, Vector4 scaleBias, float mipLevel, bool bilinear)
Parameters
Type | Name | Description |
---|---|---|
Raster |
cmd | Command Buffer used for recording the action. |
RTHandle | source | RTHandle of the source texture to copy from. |
Vector4 | scaleBias | Scale and bias for sampling the source texture. |
float | mipLevel | Mip level of the source texture to copy from. |
bool | bilinear | Enable bilinear filtering when copying. |
Remarks
Copying is performed using the blit shader passed as the first argument of the Initialize(Shader, Shader) method.
The scaleBias
parameter controls the rectangle of pixels in the source texture to copy by manipulating
the source texture coordinates. The X and Y coordinates store the scaling factor to apply to these texture
coordinates, while the Z and W coordinates store the texture coordinate offsets. The operation will always
write to the full destination render target rectangle.
Examples
// Copy the bottom left quadrant of the source texture to the render target using bilinear
// sampling, scaling to the destination render target's full rectangle.
// Configure the scale value to 0.5 because a quadrant has half the width and half the
// height of the texture, and the bias to 0 because the texture coordinate origin is at
// the bottom left.
Blitter.BlitTexture2D(cmd, source, new Vector4(0.5, 0.5, 0, 0), 0, true);
// Copy the top half of the source texture's mip level 4 to the render target using nearest
// sampling, scaling to the destination render target's full rectangle.
Blitter.BlitTexture2D(cmd, source, new Vector4(1, 0.5, 0, 0.5), 4, false);
Cleanup()
Releases all the internal Blitter resources. Must be called when the Blitter object is to be disposed.
Declaration
public static void Cleanup()
GetBlitMaterial(TextureDimension, bool)
Returns the default blit material constructed from the blit shader passed as the first argument of the Initialize(Shader, Shader) method.
Declaration
public static Material GetBlitMaterial(TextureDimension dimension, bool singleSlice = false)
Parameters
Type | Name | Description |
---|---|---|
Texture |
dimension | Dimension of the texture to blit, either 2D or 2D Array. |
bool | singleSlice | Blit only a single slice of the array if applicable. |
Returns
Type | Description |
---|---|
Material | The default blit material for the specified arguments. |
Initialize(Shader, Shader)
Initializes the Blitter resources. This must be called once before any use.
Declaration
public static void Initialize(Shader blitPS, Shader blitColorAndDepthPS)
Parameters
Type | Name | Description |
---|---|---|
Shader | blitPS | The shader to use when using the blitting / copying methods which operate only on color. |
Shader | blitColorAndDepthPS | The shader to use when using the BlitColorAndDepth methods which operate on both color and depth. |
Remarks
Shaders sent to the blitPS
parameter should support multiple passes with the corresponding name:
- Nearest
- Bilinear
- NearestQuad
- BilinearQuad
- NearestQuadPadding
- BilinearQuadPadding
- NearestQuadPaddingRepeat
- BilinearQuadPaddingRepeat
- BilinearQuadPaddingOctahedral
- NearestQuadPaddingAlphaBlend
- BilinearQuadPaddingAlphaBlend
- NearestQuadPaddingAlphaBlendRepeat
- BilinearQuadPaddingAlphaBlendRepeat
- BilinearQuadPaddingAlphaBlendOctahedral
- CubeToOctahedral
- CubeToOctahedralLuminance
- CubeToOctahedralAlpha
- CubeToOctahedralRed
- BilinearQuadLuminance
- BilinearQuadAlpha
- BilinearQuadRed
- NearestCubeToOctahedralPadding
- BilinearCubeToOctahedralPadding
Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl
for each of these pass types.
Similarly, the shaders for the blitColorAndDepthPS
parameter should support two passes with these names:
- ColorOnly
- ColorAndDepth
Examples
Blit color shader for URP which implements all the above passes with a user defined FragmentURPBlit
fragment function to support debug passes
and color space conversion.
Shader "Hidden/Universal/CoreBlit"
{
HLSLINCLUDE
#pragma target 2.0
#pragma editor_sync_compilation
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// DebuggingFullscreen.hlsl for URP debug draw
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingFullscreen.hlsl"
// Color.hlsl for color space conversion
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
// Specialized blit with URP debug draw support and color space conversion support
half4 FragmentURPBlit(Varyings input, SamplerState blitsampler)
{
half4 color = FragBlit(input, blitsampler);
#ifdef _LINEAR_TO_SRGB_CONVERSION
color = LinearToSRGB(color);
#endif
#if defined(DEBUG_DISPLAY)
half4 debugColor = 0;
float2 uv = input.texcoord;
if (CanDebugOverrideOutputColor(color, uv, debugColor))
{
return debugColor;
}
#endif
return color;
}
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
// 0: Nearest
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "Nearest"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragNearest
ENDHLSL
}
// 1: Bilinear
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "Bilinear"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBilinear
ENDHLSL
}
// 2: Nearest quad
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "NearestQuad"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragNearest
ENDHLSL
}
// 3: Bilinear quad
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuad"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinear
ENDHLSL
}
// 4: Nearest quad with padding
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "NearestQuadPadding"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragNearest
ENDHLSL
}
// 5: Bilinear quad with padding
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadPadding"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragBilinear
ENDHLSL
}
// 6: Nearest quad with padding and repeat
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "NearestQuadPaddingRepeat"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragNearestRepeat
ENDHLSL
}
// 7: Bilinear quad with padding and repeat
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadPaddingRepeat"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragBilinearRepeat
ENDHLSL
}
// 8: Bilinear quad with padding (for OctahedralTexture)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadPaddingOctahedral"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragOctahedralBilinearRepeat
ENDHLSL
}
/// Version 4, 5, 6, 7 with Alpha Blending 0.5
// 9: Nearest quad with padding alpha blend (4 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "NearestQuadPaddingAlphaBlend"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragNearest
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 10: Bilinear quad with padding alpha blend (5 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "BilinearQuadPaddingAlphaBlend"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragBilinear
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 11: Nearest quad with padding alpha blend repeat (6 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "NearestQuadPaddingAlphaBlendRepeat"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragNearestRepeat
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 12: Bilinear quad with padding alpha blend repeat (7 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "BilinearQuadPaddingAlphaBlendRepeat"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragBilinearRepeat
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 13: Bilinear quad with padding alpha blend (for OctahedralTexture) (8 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "BilinearQuadPaddingAlphaBlendOctahedral"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragOctahedralBilinearRepeat
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 14. Project Cube to Octahedral 2d quad
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "CubeToOctahedral"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragOctahedralProject
ENDHLSL
}
// 15. Project Cube to Octahedral 2d quad with luminance (grayscale), RGBA to YYYY
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "CubeToOctahedralLuminance"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragOctahedralProjectLuminance
ENDHLSL
}
// 16. Project Cube to Octahedral 2d quad with with A to RGBA (AAAA)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "CubeToOctahedralAlpha"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragOctahedralProjectAlphaToRGBA
ENDHLSL
}
// 17. Project Cube to Octahedral 2d quad with with R to RGBA (RRRR)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "CubeToOctahedralRed"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragOctahedralProjectRedToRGBA
ENDHLSL
}
// 18. Bilinear quad with luminance (grayscale), RGBA to YYYY
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadLuminance"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinearLuminance
ENDHLSL
}
// 19. Bilinear quad with A to RGBA (AAAA)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadAlpha"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinearAlphaToRGBA
ENDHLSL
}
// 20. Bilinear quad with R to RGBA (RRRR)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadRed"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinearRedToRGBA
ENDHLSL
}
// 21. Nearest project cube to octahedral 2d quad with padding
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "NearestCubeToOctahedralPadding"
HLSLPROGRAM
#pragma multi_compile_local _ BLIT_DECODE_HDR
#pragma vertex VertQuadPadding
#pragma fragment FragOctahedralProjectNearestRepeat
ENDHLSL
}
// 22. Bilinear project cube to octahedral 2d quad with padding
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearCubeToOctahedralPadding"
HLSLPROGRAM
#pragma multi_compile_local _ BLIT_DECODE_HDR
#pragma vertex VertQuadPadding
#pragma fragment FragOctahedralProjectBilinearRepeat
ENDHLSL
}
// 23: Bilinear blit with debug draw and color space conversion support
Pass
{
Name "BilinearDebugDraw"
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragmentURPBlitBilinearSampler
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
#pragma multi_compile_fragment _ DEBUG_DISPLAY
half4 FragmentURPBlitBilinearSampler(Varyings input) : SV_Target
{
return FragmentURPBlit(input, sampler_LinearClamp);
}
ENDHLSL
}
// 24: Nearest blit with debug draw and color space conversion support
Pass
{
Name "NearestDebugDraw"
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragmentURPBlitPointSampler
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
#pragma multi_compile_fragment _ DEBUG_DISPLAY
half4 FragmentURPBlitPointSampler(Varyings input) : SV_Target
{
return FragmentURPBlit(input, sampler_PointClamp);
}
ENDHLSL
}
}
Fallback Off
}
Blit color and depth shader for URP.
Shader "Hidden/Universal/CoreBlitColorAndDepth"
{
HLSLINCLUDE
#pragma target 2.0
#pragma editor_sync_compilation
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/BlitColorAndDepth.hlsl"
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
// 0: Color Only
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "ColorOnly"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragColorOnly
ENDHLSL
}
// 1: Color Only and Depth
Pass
{
ZWrite On ZTest Always Blend Off Cull Off
Name "ColorAndDepth"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragColorAndDepth
ENDHLSL
}
}
Fallback Off
}