- Home /
Other
How to make trees in a terrain transparent in runtime?
Hello everyone, I'm trying to make the trees in a terrain (not isolated trees) fade to transparent in runtime. Actually, I'd like to make only the leaves do that.
The simplest way I thought of doing that, was just fetching the TreePrototypes from the terrain data, getting to the prefab, getting to the material that I want (the optimized leaf material), and changing the material color's alpha to 0. However, that didn't seem to work, maybe because the transparency is only determined by the main texture's alpha.
Then another approach was to change the shader of the material to Transparent\Bumped diffuse, and then change the main color's alpha. This partially works (the leaves fade out gradually), but I get a warning from the editor saying that:
"The tree Tree1 must use the Nature/Soft Occlusion shader. Otherwise billboarding/lighting will not work correctly."
And the result is that the low detail trees disappear and I can only see the ones that are next to me.
If anyone has any idea on how to solve some of these issues, or just how to achieve what I'm looking for, it'd be great!
Thanks in advance.
You probably can't do a 'effect-over-time' here or the lag from constantly hitting/replacing the terrainData treeinstances will be quite evident. You can swap out the prefabs but it's risky and not supported because of the risk of corrupting the terrain. And as you've reported, Terrain trees need specific shaders.