Render Textures and Graphics.Blit
A Render Texture is a texture that is filled while the world runs. Use one for a video screen, a snapshot of a drawing, a feedback trail or any picture a shader makes.
Create one with Create → Rendering → Render Texture, then give it to a material, a UI Raw Image or a script field like any other texture.
What fills a Render Texture
| Source | How |
|---|---|
| A video | Set the Video Player's Render Mode to Render Texture (ST Video Player) |
| A drawing | ST Drawing Surface makes its own; read it from texture |
| A script | Graphics.Blit (below) |
Worlds can't contain cameras, so a camera can't render into a Render Texture.
Graphics.Blit
Graphics.Blit(source, destination) copies a texture into a Render Texture. Pass a material to run the copy through
its shader. The shader reads the source as _MainTex. Use it for tints, blurs, feedback trails and snapshots.
public RenderTexture frame; // a Render Texture asset in your world
public Material printMaterial; // optional
public void Snapshot(STDrawingSurface board)
{
Graphics.Blit(board.texture, frame, printMaterial);
}
| Overload | |
|---|---|
Blit(source, dest) | Copies the texture |
Blit(source, dest, material) | Copies it through the material's shader |
Blit(source, dest, material, pass) | The same, with one pass of the shader |
Blit(source, dest, scale, offset) | Copies part of the source, scaled and moved |
Blitting a texture into itself works.
The source can be any texture a script can reach:
- a texture or Render Texture field set in the Inspector,
STDrawingSurface.texture,STAudioAnalyser.spectrumTexture,STImageLoader.result,material.mainTexture.
Showing the result
A Render Texture asset used by a material or Raw Image in the scene needs no code. From a script:
screen.material.mainTexture = frame; // a Renderer's material
screen.material.SetTexture("_BaseMap", frame);
rawImage.texture = frame; // a UI Raw Image
effect.SetTexture("Picture", frame); // a VFX Graph property
width and height give a texture's size in pixels.
Limits
| Limit | Value |
|---|---|
| Render Texture size | at most 2048 × 2048. The world builder stops with an error on a larger Render Texture asset |
| Custom Render Textures | not allowed. The world builder stops with an error |
| Blits per frame | 32, for all scripts in the world together |
| Pixels blitted per frame | 16 million, for all scripts together (four 2048 × 2048 blits) |
Blits over the per-frame limits are skipped, with a warning.
A blit costs GPU time on every device. Blit when something changes (a button press, a beat), not every frame. Keep Render Textures as small as the picture needs. See Best practices.
Not synced
Each device fills its own Render Textures. To show everyone the same picture, run the blit on every device, for
example from a network event or from OnDeserialization. An ST Drawing Surface
syncs its own drawing.
See also
- Drawing Board example: a Snapshot button that prints the board into picture frames.
Graphicsin the API Reference.- Unity API: everything else scripts can use.