I had another go at playing around with OSL. This time I tried making a Tri Planar (or sometimes also called Round Cube or Blended Box Mapping) shader. It was an interesting thing to try out as it involves a bit more work. What I came up with however merely serves as an experimental try-out rather than being useful for production. It has a few common features that you would most likely find in modern rendering or texturing packages.
What exactly it is is quite nicely explained HERE. You “project” images from 6 sides around your objects onto it and blend between the transitional areas. The nice thing about it is that you can pretty easily texture objects that way without needing to UV unwrap them. Instead of using the UV’s as the texture coordinates it’s using 2 of the positional axis that are perpendicular to the angle you want to project from – i.e. map the texture onto P.x and P.y to get a nicely undistorted projection when you are looking from the Z axis. This is done for all 3 axis. The result of these 3 projections are then layered on top of each other with a mask based on the normals of the object. In my case I took Mari as an example on how it approaches the layering (X over Y over Z). Additionally you can layer it on top of an input texture in the shader itself.
A common problem on round surfaces is usually that the transitional areas may often be too smooth. To break it up a bit I added an additional input which is mixed into the transitional areas (you can for example plug in a noise to get a rougher transition). If the objects in your scene aren’t quite oriented the way you want there’s a cheap rotation control in the shader as well (not very sophisticated as it just layers rotations on top of each other instead of doing it via a matrix).
As it’s written in OSL it can be used with a variety of renderes. I only tested it in Blender and PRMan, but it should work just the same with 3Delight, VRay, Arnold, Clarisse, etc.
Here’s a quick demo showing some of the controls:
The compiled oso can be downloaded HERE.
You can get the original HERE. Don’t take this as a good example when you are learning… I’m not a programmer, I’m just goofing around… :-)