Has anyone ported the standard_x-tree.. shaders to Open Shader Language?


Jeff Peterson
May 22, 2010
I would like to see how my x-trees look in blender cycles renderer with the faked cylinder effect applied by racer's standard_xtree shader . Ref. http://www.racer.nl/tutorial/xtrees.htm

Supposedly one can script "ad hoc" OSL shaders into the blender shader nodes screen. I think racer's .cg language is the same as Nvidia Cg. Any porting references, cookbooks, or pointers you've found valuable?



Dec 22, 2009
As I understand it the core of the xtree shader is that instead of the normals it picks up lighting based on UV coordinates - the center of the image points straight up and it rounds towards pointing left/right from there. So what you'd do is take a standard shader and replace the normals with (0,1,0)*uv.y + (0,0,2)*(uv.x-0.5) or something. Whichever of the 3 coordinates is 'up/down' and 'left/right' in object space, with the originals being (1,0,0) pointing straight out of the billboard.

Mr Whippy

Apr 13, 2009
Xtree shader looks great for most trees on race courses and things where the trees are perhaps one third of the screen height or less in size (350px tall), since you never really get near enough to notice.
If they get closer than that (going past the windows at the side), then motion blur (when it makes a proper return to the default release of Racer) deals with any detail issues. Obviously if you stop then the illusion is broken a bit.

This seems to be how Gran Turismo works on the PS3 and 99% of the time the trees look great.

Obviously for road courses though then they can show their weaknesses, especially when you stop close by one which is even more likely on a free-roam road course at junctions etc.
They can still look good, but not like 3D ones where you can really appreciate the 3D.

I was just looking at the imposter shader in Beam NG, and having a play around there too. 3D trees really are the way to go for both being cheap on textures/shading (less alpha culling and you can use polygons to add variation which are 'cheaper'), then you can also use imposters for a great deal of trees in the distance that you will eventually get near.

Xtree is still useful though, for trees at say 50m+ away from the driver at all times. Low poly count, much lower alpha culling cost, low texture cost etc.

I'm still struggling with good looking vegetation near the driver though. Beam NG has a really nice set of up-close vegetation props... it really adds to the realism to have all that stuff between your road and over the verges to the tree-lines etc!

Then I wonder if they are using an instancing shader which scatters this stuff!? Hmmmm...