Howdy,
I’m trying to customize Unity’s terrain shader to add some additional textures and tinting to the details/grass shader (BillboardWavingDoublePass.shader). I essentially want to be able to lerp() to a different texture than the one used generated and automatically referenced (_MainTex) in the terrain engine. I’ve added the last four properties (1 texture, 3 floats)
Properties {
_WavingTint("Fade Color", Color) = (.7,.6,.5, 0)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
_WaveAndDistance ("Wave and distance", Vector) = (12, 3.6, 1, 1)
_Cutoff ("Cutoff", float) = 0.5
_FireTex("FireTex", 2D) = "white" {}
_RedTest("RedTest", float) = 0.0
_GreenTest("GreenTest", float) = 1.0
_BlueTest("BlueTest", float) = 0.0
}
This shader is setup as a dependency inside one of the other terrain shaders, so there’s no direct reference to the shader or its properties.
I can change the RGB floats manually using the default property values above and see the changes reflected on my grass but I have not been able to find a way to set the texture called _FireTex.
Is anybody familiar with an approach to dynamically set these properties at runtime?
I’ve tried using Terrain.SetSplatMaterialPropertyBlock, but that only communicates with the “splat” shader that generates the ground texture.
Terrain terrain = GetComponent<Terrain>();
MaterialPropertyBlock terrainMPB = new MaterialPropertyBlock();
terrain.GetSplatMaterialPropertyBlock(terrainMPB);
// update values
terrainMPB.SetTexture("_FireTex", fireTex);
terrainMPB.SetFloat("_RedTest", 0.0);
terrainMPB.SetFloat("_GreenTest", 0.0);
terrainMPB.SetFloat("_BlueTest", 1.0);
// update MPB
terrain.SetSplatMaterialPropertyBlock(terrainMPB);
Thanks so much for any tips/pointers.
Jeremy