Search Unity

Question Per-Object Shading?

Discussion in 'Shader Graph' started by vast_grace_worthy, Feb 27, 2021.

  1. vast_grace_worthy

    vast_grace_worthy

    Joined:
    Jan 22, 2021
    Posts:
    4
    Hello! New to shadergraph.

    I'm implementing object-highlighting as a part of my game's UI. I have a shader that I've made in the shadergraph that creates the effect I'm after, but it seems to act on all objects with a given material at once.
    My question is: how can I apply an effect to only one object at a time using the Shadergraph? Is it possible?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Look up forum for MaterialProperty keyword on IComponentData.

    There are post explaining this.


    Edit:
    Sorry, ignore me. I was thinking about DOTS.

    You could use materiał property block instead. Part of rendering API.
     
    Last edited: Feb 27, 2021
  3. vast_grace_worthy

    vast_grace_worthy

    Joined:
    Jan 22, 2021
    Posts:
    4
    Can you clarify what you mean by use the Material Property Block ? I've found it in the API but I'm not sure how I would go about linking it up with the shadergraph.
     
  4. vast_grace_worthy

    vast_grace_worthy

    Joined:
    Jan 22, 2021
    Posts:
    4
    Never mind, a little more digging and I have something working.
    Thank you for pointing me in the right direction.

    If someone comes across this later, any property defined in the shadergraph can be edited per-material-instance with the MaterialBlockProperty following the pattern described here. With the extra step that Unity's bools are really just ints in [0|1] yields per-object toggelable shaders.
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    [
    You would need compile your shader graph into script. Then add properties section on the top of shader scrip, which are not there by default. At least wasn't there in previous shader graphite ration. You properties naming must match shader grap variables naming.
    Which also should be visible in the inspector.

    Sorry, I have no example on hand, as I am on the mobile.
    This approach may be a bit intimidating but is functional.

    You would need marry shader graph with for example RenderMeshInstantiated API. If I call it correctly. It may need a bit more digging, but info is there.
     
    vast_grace_worthy likes this.