How to merge two shaders?

11 views
Skip to first unread message

AMDx64BT

unread,
Aug 5, 2009, 6:47:12 AM8/5/09
to Blender to RenderMan
How I can merge two different shaders, for example checker and plastic
using a texture image as mask? I suppose that the most easy way is
using vertex groups. But I am interested in a very smooth transition.
Perhaps using layers could be the most correct.

>WHiTeRaBBiT<

unread,
Aug 5, 2009, 2:57:06 PM8/5/09
to Blender to RenderMan
Hey AMBx64BT,

There are many different ways of going about this, but most will
involve modifying shader source. I'll outline a few examples of how to
achieve this effect from simplest to most complex (all examples are
assuming your using the latest CVS of MOSAIC):

1) You can simply use MOSAIC's built in shaders and a checker textures
to simulate this, they support all diffuse and specular shaders, up to
10 texture slots, all texture blending modes/sliders and masking. The
plastic.sl shader is using diffuse() and specular() which is the same
thing as setting Blender's material to CookTorr and Lambert, then use
a checker texture with whatever blending or masking you would normally
do with Blender's material and textures. Of course this is not the
same as a procedurally generated checker but may work depending on
what your doing.

2) If using Aqsis you can cheat by using layered shading, but in order
to make that work you'll need to hack the shader sources a little.
MOSAIC's shaders already have layered shading built-in using the
__surfacein, __surfaceout parameters so if you stick with those you
could mix MOSAIC's and your modified shaders together. So to do this
with your example you would add these to both shaders parameters:

output varying color __surfacein = 0;
output varying color __surfaceout = 0;

and then add some parameters and code to determine how they are mixed
together, heres a blend file with a modified checker and plastic
shader: http://www.dreamscapearts.com/Public/layered_checks.blend
and heres what it should look like: http://www.dreamscapearts.com/Public/layered_checks.jpg
You can find the modified shaders in the text editor as "checked.sl"
and "plastique.sl" with comments around the added code, also notice
that the "mask" parameter on plastique is used to determine blending
between the two shaders and if not set then they are mixed 50/50. Also
note the material in MOSAIC using the checked shader has "Next
Material Layer" set to the material using the plastique shader, this
sets up the material chain checked->plastique with the first material
in the chain the one on the object and the last being the one that
blends the two on the final surface color Ci. This may seem
complicated but only involved 12 lines of added code and less then a
minutes time to setup for anyone who knows RSL!

3) The last approach is the most common as only Aqsis and Gelato
support layered shading... combine the shader sources into one. In
your example the plastic and checked shaders are already using the
same method for getting diffusion, the diffuse() shadeop. This means
its a very small step to just copy the code from plastic and add it to
checked with a texture for mixing. Of course this gets impractical
when mixing two or more really complicated shaders. Most studios get
around this by creating large libraries of support code and put them
in includes files so they can be linked into any shader on demand but
this still involves a lot of per material shader customization. IMHO I
think layered shading is far more elegant and should be included as
standard for all RenderMan renderers!! Here's an example of a modified
checker shader that masks diffusion with added code commented:
http://www.dreamscapearts.com/Public/checked_masked.sl

Anyway the bottom line to all this is unless your layering MOSAIC's
shaders together you'll need to get your hands dirty with some RSL
coding (although I don't think its to hard to do compared to other
things).
Eric Back (WHiTeRaBBiT)
Reply all
Reply to author
Forward
0 new messages