After having received my downloadlink to the Unity 3 beta I have tried to port my hacked terrain shaders to the latest built (3.00b5).
Here you can find the results.
VertextLit
As in my shader package for unity 2.x I abuse the VertexLit Shader to render bushes and all kind of foliage that is higher than grass.
Features:
- It supports casting shadows and should support receiving shadows – but somehow it doesn’t. Applying the shader to a normal game object it works perfectly. Doing so with foliage painted within the built in terrain engine it fails to cast shadows… so I think it’s got nothing to do with the shader itself.
- It allows individual bending of each model brought into the terrain engine, but this bending has nothing to do with the terrain wind settings nor the new wind zones.
- It works with a modified lighting term in order to brighten surfaces pointing away from the light.
// hacked lighting term
c.rgb = s.Albedo * (light.rgb * 0.7 + 0.5);
There are much smarter solutions on lighting leaves, but as my capabilities on programming are more than limited I am not able to implement those. Maybe someone else. Some ideas can be found here:
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch04.html
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html
Unfortunately it is not possible to assign more than one texture to any detail mesh within the terrain engine. But lighting depending on the angle between light vector and view vector should be possible.
Usage:
- Just create a new shader, give it any name, and copy the sourcecode. You might have to restart Unity to make it work.
- This time it uses 2 sided geometry in order to avoid having to flip normal for this caused some artifacts in lighting around edges. So just double your geometry, flip the normals and combine both meshes in your 3d app.
- You might have to adjust (reduce!) the phong smoothing angle in order to avoid wrong lighting. Do this in your 3d app or in the Unity importer settings.
Bugs:
-Only works in deferred lighting. Why?
TreeLeaves
TreeLeaves in Unity 3 look pretty weird as they do not use any precalculated lighting any more (although the shader still contains vars for ambient and direct occlussion…): I think the contrast between lit and unlit surfaces is much to high, in addition on the side facing away from the light there are some pretty bright leaves whereas on the lit side you can find some rather dark leaves.
Features:
- It uses the same hacked lighting as the VertexLit shader which gives you a more realistic lighting on the leaves I think.
- In opposite to the VertexLit shader it uses 1 sided geometry and flips the normals if needed. Although this leads to some artifacts and sudden popping in the lighting i stuck with this, as 2 sided geometry didn’t produce a better result: As I wanted the tree bark to still be rendered very smoothly I could not lower the phong smoothing angle which is assigned to the whole model. Maybe there is a way to do this within the shader, but I don’t know.
- It supports casting shadows but does not receive any – like the original shader.
- Original coloring, scaling and the new bending introduced by Unity 3.
Usage:
- Just create a new shader, give it any name, and copy the sourcecode. Then assign the shader to your tree prefabs.
You might have to restart Unity to make it work. - As it still works with 1 sided geometry you can use all the given tree models.
TreeBark
Features:
- Bumpmapping. Finally.
- Original coloring, scaling and the new bending introduced by Unity 3.
Usage:
- Just create a new shader, give it any name, and copy the sourcecode. Then assign the shader to your tree prefabs.
You might have to restart Unity to make it work. - Make sure that your trees are NOT in a folder containing the name “Ambient-Occlusion” – otherwise you won’t have much bumpmapping. This costed me hours on investigating my models to find out…
Splatmaps
Bumpmapping! Well, I have tried hard to get this thing to work – but without much success. Only some pretty wired bumpmapping and only darkening no brighting. I guess it has got something to do with beast lightmapping… Anyway. So it will be up to someones else to make this work with unity 3.
One more thing
Billboards are not affected by fog. I hope Unity fill fix this until the final release.
Conclusion
Although lighting and shadows in Unity 3 now affects grass and although I can have bending trees in different sizes and coloring plus bending detail meshes I still like my results in Unity 2.6 better due to the following facts:
- Detail meshes casting shadows on the terrain.
- Pseudo bumpmapping on the terrain.
- It should not be mentioned but: correct billboards.
Just have a look at:
http://forum.unity3d.com/viewtopic.php?t=45290&postdays=0&postorder=asc&start=0
lars





