Change Terrain textures/vegetation based on lighting

I am trying to come up with a way to render different terrain textures and vegetation within a dynamically lit area. The area could be the cone a spotlight, for example, and will move constantly.

It’s kind of hard to explain exactly, so I’ve hacked together a screenshot in photoshop illustrating what I mean:

I have 12 years of c# and enterprise development, but this is my first time to try making a game so it’s quite a different way of thinking for me. I would appreciate any thoughts or suggestions! :slight_smile:

I thought. Now i have an idea, but i’m not sure, it will work and be fast enough using the standard terrain. You may want to give it a try anyway. You can manipulate splat textures for ground areas and the placed detail objects (like grass, flowers or rocks) through the TerrainData Object.

Use SetAlphamaps to control the texture weights applied to a certain area of the terrain. Since you have to define all potential ground textures for your terrain (using the standard editor) this may cause some speed issues. If i remember correctly, the standard terrain shader can handle 4 textures per pass and introduces more passes for a higher number of textures. Anyway, this should be fast enough, if your updated terrain area is not too big.

Use SetDetailLayers to control the type of detail coverage in a certain area. This basically works the same way as ground textures. It suppose, you can’t control the exact position and rotations for the details placed. If so you may have to switch away from the standard unity terrain details.

Trees work differently and are more complicated, since they usually have colliders on them. You may give this this or this approach a try to work around that.

Good luck!

Thanks for the ideas! I’m going to do some hacking and see what the performance looks like.

I’m also thinking that it might actually be easier and perform better to use a “portal” like approach where I have a hole in the terrain where the light shines in order to composite two camera views together - one from the current view and one from another terrain that is a copy with different textures. Or maybe render to texture on the lit area? The more I think about it, there are definitely a lot of solutions. Hopefully I can find the best one that is a good balance between complexity and performance.