Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Custom Terrain Material AddPass Shader

Discussion in 'Scripting' started by hausmaus, Jan 3, 2017.

  1. hausmaus

    hausmaus

    Joined:
    Dec 9, 2011
    Posts:
    105
    I have written a simple custom PBR shader for Unity's terrain that accepts some additional driver textures to allow things like height-based blending and roughness control.

    This approach uses a script to create SplatPrototypes for the normal Terrain Editor to use, and then assigns ProceduralMaterial-derived textures to the custom shader. For that reason, it assumes script access to the material which is being drawn.

    How do I access the properties of the AddPass shader? I am using the same shader dependency setup as Unity's included terrain shaders. It seems like they must be doing some kind of MaterialPropertyBlock swap under the hood between passes since I assume they are reusing samplers and texture IDs between passes. So if I want to assign _Splat4, the fifth texture, that's really _Splat0 of the AddPass, but I don't know how to write to that without also writing to the FirstPass.

    Thanks for any insight,
    Adrian

    P.S. I did look into using a second material for the AddPass shader, but there's no obvious way to prevent the internal redraw and use the new material while still keeping the default SplatProtoypes populated for easy editing.
     
    Last edited: Jan 3, 2017