Render to texture

(Massimiliano Mantione) #1

Hi, is there a way to render a 3D scene to a texture?
I tried looking at the Camera documentation but did not find a way to associate a texture to render on…

1 Like
(Nathan) #2

That’s a great question. I would also like to know the answer.

(Azriel Hoh) #3

For a very simple “insert bytes into an array and load it”, see:

Those ones are loaded once.

Here’s what amethyst_ui does to write font glyphs, – from amethyst_ui/src/glyphs.rs. I’ll list out the “important lines”; finding out how to get the imports / getting the instances of those types from through SystemData is homework / see the first two examples (probably easier).

Steps:

  1. Create a Texture (specify width/height / pixel format): glyphs::create_glyph_texture

  2. Put that into AssetStorage<Texture>: UiGlyphsSystem::run#L161-L164.

    Note: glyph_tex is a Handle<Texture> (lightweight reference) when you insert it, so to get the &mut Texture back, borrow it from the storage again.

  3. Upload the bytes to the backing texture image buffer: UiGlyphsSystem::run#L369-L391.

    This part is “scary” / foreign (including to me) – we’re dealing with bytes. data in that highlighted section of code is what glyph_brush has filled, and we call factory.upload_image, passing in tex.image().clone() which is a rendy concept (an abstraction over gfx-hal).

    If you’re looking for source, here you go:

    • tex.image()
    • image.rs: you have to be familiar with the vulkan / gfx-hal model to understand this.
1 Like