Skip to main content
Version: 0.4.1

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​

SourceHow
A videoSet the Video Player's Render Mode to Render Texture (ST Video Player)
A drawingST Drawing Surface makes its own; read it from texture
A scriptGraphics.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​

LimitValue
Render Texture sizeat most 2048 × 2048. The world builder stops with an error on a larger Render Texture asset
Custom Render Texturesnot allowed. The world builder stops with an error
Blits per frame32, for all scripts in the world together
Pixels blitted per frame16 million, for all scripts together (four 2048 × 2048 blits)

Blits over the per-frame limits are skipped, with a warning.

tip

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​