Help with Vegitation shader?

Hey guys, maybe you can help me out with a problem I’m having. I should preface this all by saying I know little to nothing about scripting or programming, so this question will probably be pretty basic. But I’ve taken a look through the forums, and can’t seem to find anything.

I’m trying to get a shader working for an iPhone game project being done in unity. I need a shader that fulfills the following requirements:

*Accurately displays transparency based on an alpha map; trunk is solid, leaves are transparent, etc.
*Accurately maps light, shadows and texture
*Displays and accurately shades polygon backfaces

I’ve found a few shader scripts on the wiki, but I’m having some problems getting them to work.

http://www.unifycommunity.com/wiki/index.php?title=VegetationVertexLit
This shader works as advertised, except it produces strange transparency artifacts where there is no Alpha Map data to cause it.

http://www.unifycommunity.com/wiki/index.php?title=VegetationTwoPass
This shader negates the artifacts, but the resulting texture is about 50% darker than it should be.
I’ve narrowed this problem down to lines 24 and 41:
combine texture * primary, texture
However, I can’t find any in-script reference to ‘Primary’ anything, and I can’t remove the string without causing lighting errors.

Any thoughts on how to fix this?

(PS: “Copy the polygons and invert them” isn’t an acceptable alternative to having functional backfacing. The game objects are too close to 300 vertices already, and we can’t afford the extra geometry.)

The lighting errors are caused by the fact that primary is the lighting :P. Add the word DOUBLE behind both occurances of primary and you get double intensity.

Unfortunately, “Copy the polygons and invert them” is the only way to get functional backfacing on the iPhone. The ‘Cull Off’ in the second shader is a quick trick that does reveal back faces, but it does nothing towards flipping normals, so backfaces will be lit incorrectly.

Thanks! It sucks when you know what you want to do, you just don’t know the language necessary to do it.

It’s unfortunate that the normals don’t work right, but having applied it to the foliage in-game, it seems to work well enough. The faulty lighting isn’t a glaring issue, and doesn’t detract from the visuals.

For buildings with similar tricks, however, it doesn’t seem like this is going to work. Fortunately, they’re low-poly enough to duplicate the roof, and low enough to batch together, so having a third material for them shouldn’t cause problems.