Adverti horiz upsell
Faking micro-bevel with mentalRay
Faking micro-bevel with mentalRay
hbahnassi, added 2005-10-19 12:23:32 UTC 39,223 views  Rating:
(2 ratings)
Page 2 of 2

Bump input, FX Tree and other stuff

Yes, the bump input port in the material node is the right place for controlling object normals.
Since the idea of bump maps actually depends on perturbing the object�s normals to fake bumpiness, we can use the same concept to make the vector state control the surface normals.

So let�s grab a sphere, open its render tree, and connect a vector state node to its bump input.
Now if we switch the state parameter in the vector state node to �Geometry Normal Vector� and draw a render region, we�ll see how the sphere is now rendered without smoothing the faces.
Of course, it doesn�t make any sense to use state parameters other than the �Geometry Normal Vector� and the �Normal Vector� with the bump input so don�t bother testing other options because you won�t get something meaningful.

Geometry normal vector rendering

Next, we need to find an easy and controllable way to mask the interpolated normals around the object�s edges. Actually, there are many ways to do it. One way that is both simple and controllable is to generate a masking texture map that is controlled via the FX Tree.

The generation of the masking texture map is fairly simple. Just create a unique UV set for the object, and then stamp the texture projection over a black background to a file.

Now this generated texture file can be modified with the FX Tree before it�s used as a masking texture for the normals.

Grab a cube for example, add unique UVs to it either via the �Unique UVs� texture projection or the �Cubic� texture projection.

Next, open the texture editor for the cube and make sure that all the object faces are positioned correctly.
Now import a black picture with a medium resolution (e.g. 1024x1024) and stamp the UVs over it.

Geometry normal vector rendering

Now all the ingredients are ready and what remains is to assemble them in the render tree.

Building the render tree in XSI

We start by creating a new �phong� material for the stamped cube. Next, we call its render tree to build the micro-bevel shader network.

First, get two vector state nodes and set one of them to the �Normal Vector� and the other to �Geometry Normal Vector�.

Rename these nodes to something meaningful so you can recall which one is which later.
Next, grab a �mix_2colors� and import the stamped clip to the render tree.

Now connect the �Geometry Normal Vector� state to the �mix_2colors� base color input, the �Normal Vector� state to color1 input and the stamped image to the weight input. Finally, connect the �mix2_colors� to the bump input in the material node. While connecting nodes you�ll notice some conversion nodes being automatically added for converting vector types to color or the other way. Anyways, you should get a tree very similar to the one in the picture below.

The render network

Now before rendering and testing our work we need first to smooth the object�s normals or we�ll end up with both the normal and geometry normal being identical (unsmoothed).

So open the geometry approximation for the cube and uncheck the automatic discontinuity option under the �Polygon Mesh� tab.

Now if we draw a render region, we�ll see almost no effect at all. This is because the masking lines are so thin that they�re not enough to render the effect clearly.

To control the thickness of the masking lines we�ll depend on the integrated fx tree we have in XSI.
So change one of the viewports to fx tree or open a floating one and open the fx viewer to see the modification results directly on the stamped picture.

Now get the stamped image from the clip menu in the fx tree and grab two fx operators, the �box blur� from the �filter� group and the �Glowing Edges� from the �Painterly 2� group.

Now connect them between the �FromClip� and �ToClip� nodes as shown in the picture below.

The render network

Now to control the masking edges thickness and smoothness all what we need to do is to play the �Edge Width Parameter� in the �Glowing Edges� node and the width and height parameters in the �box blur� node.
Try adjusting these parameters to something close to the picture above, then refresh the render region to see how it looks.

Alrighty� So that�s how we managed to get a nice approximation of micro-beveling in mentalRay without even writing a single line of code. Later, I will show you how to implement the same effect but in real-time using the new version of DSK|ShaderBass.

Final results

click for larger version

One Last Note

This tutorial used only an approximation to the real effect. Since this is actually just a variance over bump mapping, then the geometry itself is not affected by this effect. That means that rounded edges will shade rounded, but will take the same space and silhouette as an un-rounded edge. As long as the beveling thickness remains small, this won�t be a problem. After all, we�re talking about �micro-beveling�, not a �round-edges� shader!

If you�re after perfectly accurate results, then there is no way but to write a custom mentalRay shader along with an XSI plug-in. This can solve the silhouette issue, as well as give more accurate shading over the edges since the smoothed normals can now be calculated locally to the edges instead of the current crude �whole-object� smoothed normals calculation.

That�s it for today� By now!