I noticed that terrain grass isn’t affected by dynamic lights at all. See for yourself: Create a new scene, add a directional light (set light color to black), then add a terrain and some grass. The grass is full-bright inbetween the dark terrain. This also applies for trees that are displayed as billboards.
I’m trying to fix this problem but I’m quite new to shader programming. I already learned that you can replace the built-in shader and I found out that each grass billboard’s color is calculated in TerrainWaveGrass (file TerrainEngine.cginc). The function takes the color values from the dry/healthy settings and passes is back to the shader (eg. “Hidden/TerrainEngine/Details/BillboardWavingDoublePass”). The shader however doesn’t take lighting into account. I feel like this is no big deal but I have no clue where to start or what to do exactly. Any help is appreciated!
from what I have see - the grass is more effected by a shadow map on the terrain then lights in general. (Example - if the shadow map is red - the grass will be tinted red) Tho I think I remember seeing a “How to” to make the grass be affected by light.
Perhaps burn out your lights to a light map, then have them effect the grass?
Unfortunately I need to dynamically move/change the light so baking lightmaps is not an option (but it would be great if both could be combined, basic lightmaps and additional scene lights). It’d be a great help if you could dig up that example.
you will have to hack the built in terrain shader.
have a look at http://forum.unity3d.com/viewtopic.php?t=45290
there you will find the source for a hacked terrain engine vertexlit 1sided shader. this might be a good starting point.
Thanks, but I’m not getting along at all. I tried something like
UsePass “Diffuse/PPL”
but all I get is the following warning:
Shader wants normals, but the mesh doesn’t have them
My terrain is set to use Pixel Lighting so the normals should be there, right? I really need support on this, it’s too complex for me. I’d even be happy with simple ambient lighting for the grass. Please help!
Yhoko, that looks great. I was trying to get it to work on my end but with no luck. I replaced the built in WavingGrass.cginc with your edited verson, and I restarted unity, but the grass color isn’t affected by the ambient color. can you give a more detailed explanation on your method?
The file <WavingGrass.cginc> is being included by the shader files <WavingGrass.shader> and <WavingGrassBillboard.shader>. You have to add (copy) all of these files to your project, then restart Unity. If it doesn’t work after this, right-click on the shader files and chose “Reimport” - this also needs to be done after any changes to the .cginc file.
Btw. You should not modify the built-in shader files at all.
I’ve been trying to get grass to change with the overall lighting of a scene ever since first picking up Unity. I had finally given up, thinking it was out of reach.
I tweaked some of your settings based on my light setup… I’m blending it with the diffuse color of the main lightsource as well as he ambient color of the scene:
I’m sorry but I can’t agree to your modifications at all. First: You leave out the original o.color completely, thus effecively removing the “color waves” from dry to healthy. Second: Your code does not take the light’s attenuation into account. Try adding a point light near your grass and modify the range value - looks horrible.
I suggest the following code for ambient, point and spot lights: (replaces all previous modifications)
I am a shader noob but want the same effect, can someone please show that full shader’s code, I am not sure where to add the code to the current one to enable this.