Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How to create a texture from file or buffer? Can URP RenderFeature or CommondBuffer used in Tiny?

Discussion in 'Project Tiny' started by AritaDev, Sep 18, 2021.

  1. AritaDev

    AritaDev

    Joined:
    Aug 13, 2019
    Posts:
    13
    How can I create a texture from file or buffer in Tiny?
    Like Resource.Load<Texture>("file://") in legacy Unity project.

    How can I render this texture in scene?
    If I want to use this texture as background of my camera, is it possible?
    (As using commondbuffer to change the render background in legacy Unity project).

    How can I load resources from disk or cloud?(As I know, tiny doesn't support AssetBundle.)
     
  2. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    You can't use anything from UnityEngine namespace in Tiny, namely CommandBuffer.
    I think your best option right now is to create a sprite in you scene and use it as a background and from there on you can load external textures to it.
    I load texture like this:
    Code (CSharp):
    1.     public static Entity CreateTexture(EntityManager em, string path, string name = default) {
    2.       var entity = em.CreateEntity(typeof(Image2D), typeof(Image2DLoadFromFile));
    3. #if UNITY_EDITOR
    4.       if(!string.IsNullOrEmpty(name))
    5.         em.SetName(entity, name);
    6. #endif
    7.       em.AddBuffer<Image2DLoadFromFileImageFile>(entity);
    8.       em.SetBufferFromString<Image2DLoadFromFileImageFile>(entity, path);
    9.       return entity;
    10.     }
    You can then replace the texture entity of the background sprite (Unity.Tiny.Sprite).
     
  3. AritaDev

    AritaDev

    Joined:
    Aug 13, 2019
    Posts:
    13
    Thanks for your reply.
    What format should the path be?
    local files: D://A/B/C/a.png ? or file:///D:/A/B/C/a.png?
    web files: https://a.b.com/a.png
    I have tried these, but none of them works.

    Can I load a image from a native array or pointer?

    One more thing, how to see log in Windows-DotNet building?
     
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    For full path:
    Code (CSharp):
    1. c:\\images\\myimage.png
    if you place the files inside the root of your build and use a relative path
    Code (CSharp):
    1. images\\myimage.png
     
  5. AritaDev

    AritaDev

    Joined:
    Aug 13, 2019
    Posts:
    13
    Thank you for you quick reply.
    How can I load a texture from native buffer/array? (Or pointer.)
     
  6. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    You have to read the raw data into Image2DMemorySource and create an Image2D representing that data.
    I haven't loaded textures using this method but you can look at Unity.Tiny.Rendering.Native\RendererBGFX.cs at around line 1334