Mixing BumpMaps with Vector Mathematics.
by Andy Hayes
As you are aware, bump maps don't blend with mixing nodes in XSI. This tutorial shows how to blend bump maps using maths nodes in the render tree.
The example scene can be found here.
This example scene uses two image maps, a checkerboard picture file (test_check) and a cell-like image (test_cell). Test_Cell has an alpha channel that fades out in a circular nature (below).
Two camera projections are used - one for each texture . The checkerboard image is projected into a mix2node, at the base level and the cell image is projected into the color 1 of the mix2node. The cell image is blended with its alpha channel, so that we have a small patch of the cell image over a checkerboard texture, as below.
click to enlarge
When considering applying the same technique in bump map terms, we have to look at what exactly the mix node is doing. We can create bump maps in vector format, but this limits us to only being able to apply maths to these. If we study the mix node, we can see that there are two mathematical blends actually happening here:
1> The cell image is being faded out so that it blends out to the checkerboard via its alpha channel.
2> The checkboard texture is being faded out in the area covered by the cell image, to prevent both checkerboard and cell image coming throught in the same place.Its using the inverse of the alpha channel.
We can now translate this method into vector maths.First of all, we create two bump map generator nodes, one for each image and reload the sources of the images into these, with corresponding projections, so that we have a bump map version of our colour image nodes. As you can see, these nodes output vector variables(the yellow output) which we can plug directly into the bump map input of the illumination model.
In order to start blending these bump maps, we need a Vector_Vector node from the Maths section of the rendertree.This node allows us to perform mathematical operations on vectors using either other vectors or scalar variables. In this case, we use the scalar input to multiply our vector, almost like an intensity node, using the alpha channel of our cell image.
To do this, select a color_picker node and plug this into the image projection node, and select it to pick the alpha channel. This gives us the alpha channel in a scalar format. Plug the bump map generator that uses the cell image into the vector_vector node ( in to vector_input1). Plug the scalar output of the color_picker into this vector_vector node( into the scalar input). Double click on the vector_vector node and chose "vector input 1 X scalar input1". This has the effect of blending the cell image bump map using the cell alpha channel.
Create another vector_vector node and plug the vector ouput of the bump map generator that is using the checkerboard image into vector input 1. In order to get the opposite effect of the other vector_vector node and fade the checkerboard in the areas of the cell image, we have to invert the cell alpha channel. Rather than converting the alpha channel to an RGB output, then using the invert node, and then converting back to scalar, we can use another maths node. Create a scalar_basic node from the maths section of the rendertree. Effectively, subtracting the alpha channel value from 1 will give us the inverse of the alpha channel, so plug the color picker node into input 2 of the scalar_basic node and set input 1's value to 1.0 in the ppg. Also in the ppg, set the operation of this node to "subtract". This now returns a scalar variable this is the value of 1 minus the alpha channel input value - effectively the inverse. Plug this output into the scalar input of the second vector-vector node, and once again set the vector_vector operation to be "vector input1 x scalar input".
We've now worked on the two bump maps - fading the cell out with the alpha and fading the checkerboard in the opposite way. All we need now to do is add these vectors together to form one vector and we have our final bump map. Create another vector_vector node from the maths section and plug the bump maps into the two vector inputs. Set the operation in this node to "Vector 1 + Vector 2". Take the output of this node and plug it directly into the illumination model. Here's the final tree:
click to enlarge
We have now effectively mixed two bump maps together, its a bit complicated to explain but the principle is rather simple. You could of course pre-docture all the bump map images in photoshop, but using the rendertree is a non destructive method that some people may prefer.
Any questions, alternative suggetions, etc. please mail Andy Hayes