Search Unity

[SOLVED] Pass data from a shader to its Dependency shader? Or set Dependecy shader data?

Discussion in 'Shaders' started by eXonius, Oct 25, 2016.

  1. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    Terrain shaders use dependencies like this:

    Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Standard-AddPass"

    When more than 4 textures are added to a terrain then the AddPass shader is called to render the 5th one and any other textures following.

    I have modified the terrain shaders and gave them extra properties and I wonder if there is any way I can set a property value in a dependency shader?

    For the FirstPass shader I can just add a property and then change that property in the material I attach it to, using the inspector. But you never see the dependency shader properties so how can I set those through script?
     
    Last edited: Oct 25, 2016
  2. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    Okay I got it working.

    Simply use the Terrain.SetSplatMaterialPropertyBlock() like this:

    Terrain terrain = transform.gameObject.GetComponent<Terrain>();
    MaterialPropertyBlock prop = new MaterialPropertyBlock();
    terrain.GetSplatMaterialPropertyBlock(prop);
    prop.SetFloat("_MyValue", 2.0f);
    terrain.SetSplatMaterialPropertyBlock(prop);

    This will set "_MyValue" in both the FirstPass and the AddPass shader if both has that property (or else just in the one that has it).
     
  3. Usmith

    Usmith

    Joined:
    Apr 7, 2013
    Posts:
    20
    Sadly this works only after version 5.5, I can not find it in previous versions of Terrain API.