Search Unity

Hybrid Renderer and MaterialProperty to change Texture 2d at runtime

Discussion in 'Graphics for ECS' started by vildauget, May 3, 2020.

  1. vildauget

    vildauget

    Joined:
    Mar 10, 2014
    Posts:
    121
    Hi.

    MaterialPropertyFormat doesn't include 2D, so setting MaterialProperty through script is limited to these formats, if I understand correctly;
    upload_2020-5-3_16-46-56.png

    Is there any way to feed a Shader Graph shader a texture 2d from script during runtime?

    If not, is this simply a matter of the MaterialPropertyFormat enum not including texture as an option, or are there underlying good reasons as to why we can't supply a shader with a texture from script?

    My thought / use case is keeping meshes equal, and rather modify them through vertex displacement in shader. This way the entities would use the same Shared component RenderMesh, and stay in the same archetype.
     
    andywatts likes this.
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    This limitation exists for a reason that I couldn't be bothered to try and explain at the moment. But since you are using custom shaders, you could consider using an index into a Texture Array or offsets into a Texture Atlas. Or, if you have only two or three textures, you could just sample all of them and select the sample you want from an index value.
     
  3. vildauget

    vildauget

    Joined:
    Mar 10, 2014
    Posts:
    121
    Thank you for pointing out that there is a reason for the limitation, and for your suggestions, @DreamingImLatios .

    Just struck me that one might be able to sneak the texture in through the Material API, and use your idea of using offesets for modifications in the shader. Will update this thread on any progress.

    EDIT: Hehe, no, I'm biting my tail. Material is part of the RenderMesh shared component. :)
    EDIT2: I guess it would be possible to create custom noise nodes in Shader Graph that use input parameters, but for my use case, it would put too much work on the GPU to save some terrain draw calls, as I'm building complex noise logic, but might be useful later. I'm gonna let my terrain pieces live in each their own chunk for now.
     
    Last edited: May 4, 2020
  4. mochenghh

    mochenghh

    Joined:
    Jun 10, 2021
    Posts:
    26
    Texture Array look likes the only way.Change single texture seems not support in Hybridrender