Skip to content

Commit ab5acef

Browse files
committed
Add sample script for rendering UI Canvas to GPU Texture
FlaxEngine/FlaxEngine#3601
1 parent bd696d8 commit ab5acef

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

manual/ui/canvas/index.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,36 @@
2929
| **Navigate Left** | The name of the input action for performing UI navigation Left (from Input Settings). |
3030
| **Navigate Right** | The name of the input action for performing UI navigation Right (from Input Settings). |
3131
| **Navigate Submit** | The name of the input action for performing UI navigation Submit (from Input Settings). |
32+
33+
## Rendering Canvas to GPU Texture
34+
35+
Canvas can be rendered directly to the GPU Texture for use in materials or VFX. Simply change the `RenderMode` to `GPUTexture` and provide `OutputTexture` that will be used as an output image for the canvas elements. See an example script:
36+
37+
```cs
38+
using FlaxEngine;
39+
40+
namespace Game;
41+
42+
public class RenderCanvasToTexture : Script
43+
{
44+
public GPUTexture MyTexture;
45+
46+
public override void OnEnable()
47+
{
48+
// Allocate a new GPU texture and resize it
49+
MyTexture = new GPUTexture();
50+
var desc = GPUTextureDescription.New2D(300, 200, PixelFormat.R8G8B8A8_UNorm);
51+
MyTexture.Init(ref desc);
52+
53+
// Link texture to the canvas
54+
Actor.As<UICanvas>().OutputTexture = MyTexture;
55+
}
56+
57+
public override void OnDisable()
58+
{
59+
// Release reference and dispose texture memory
60+
Actor.As<UICanvas>().OutputTexture = null;
61+
Destroy(ref MyTexture);
62+
}
63+
}
64+
```

0 commit comments

Comments
 (0)