Search Unity

Feature Request Tint by object or by element - hue shift possible?

Discussion in 'Shader Graph' started by newguy123, Dec 9, 2020.

  1. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,248
    Is it possible to have a "tint by object" or "tint by element" node? For example if I apply the same material to 10 objects, could I randomly tint the colours of those objects by for example shifting the hue a bit for each object? For example if I have 10 cars and I want to tint the body paint of each car, but have it as 1 material?

    Similarly, if I have 1 object, made up of various elements. Like a mesh bush for example with leaves. Could I tint each leave a slightly different green, but have that main leaf material as a single material? In 3ds max this is fairly easy and simple by using things like multitexture or vraymultisubtex
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    Yes you can. Just modify shader properties after GameObject was instantiated.

    As an example, here I use only two base meshes. box as branches and sphere as leafs, flowers etc.Then instantiated duplicates. And using Shader Graph, apply colors.



    In case of GameObject, you want access property, using


    Code (CSharp):
    1. MeshRenderer mr = GO.GetComponent <MeshRenderer> () ;
    2.             mr.sharedMaterial.SetColor ( "myShaderPropertyName", Color.cyan ) ;
    3. // Or
    4.             mr.sharedMaterial.SetColor ( shaderID, Color.cyan ) ;
     
  3. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,248

    Its not for an app but mainly for offline rendering with Cinemachine and Timeline, will this technique still work?

    Isnt there a way directly in shader graph without using scripts at runtime?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    I am not sure, what you mean exactly, by offline rendering? You still need start the application anyway. And you will need game objects for rendering, so I expect, it will work. Unless I misunderstand your concept.

    You can create new material for each new object. Otherwise, I am not aware on any other method, with using same material and multiple shader variations.

    You could try look around scriptable objects, but I am not sure, if this will solve the problem.

    If anything fails, what you could do, is to use GO with attached script as a component, with desired shader properties. Script will set material shader properties at GO start. Not the nicest solution, but could do the job.
     
    newguy123 likes this.
  5. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    171
    newguy123 likes this.