Offsetting texture UVs via the camera normal |
A good example of this shader is to imagine a building with a window cut into it, allowing the viewer to see through into the room beyond. Instead of modeling out the interior (which can be prohibitive in computer game environments where this trick is often applied) we can use a texture of the room instead, aligned roughly to the outside wall, with an offset to give the viewer a parallax cue in order to make it appear as though the room has some sort of three dimensional depth.
This is easier to understand when we can see things in motion - here's a quick setup scene to help illustrate.
Obviously this technique has some limitations, but when used in mid to background elements in shots where the camera motion isn't too extreme, it may be just the thing needed to help add some quick depth to a 3D scene, cutting down on the time spent modeling, texturing and lighting an interior.
So let's look at how we can go about setting up a shader which can recreate this parallax effect in Maya...
First we will need a texture for the interior. Here's the one I used in the example scene-
Simple cube with extruded face |
The extruded face will serve as our window- select the face, right click and choose 'Assign New Material' from the context sensitive menu. Choose 'Surface Shader'. The rest of the box can retain the default lambert material for now.
In the 'Out Color' of the surface shader, plug in your file texture.
Face with Surface Shader applied |
Note: You'll need to scale in your UVs a bit on the face with the surface shader applied. Doing so will give the texture some overhang or breathing room, otherwise you'll find the texture repeating as you change your angle of view.
In the hypershade, select the surface shader and click the input connections icon. Then under the Maya utilities side panel, look for the 'Set Range' and 'Sampler Info' nodes. Bring one of each into the work area and arrange the nodes roughly into the sequence shown below.
Setting out the nodes for the shader (note: the samplerInfo node icon has changed in Maya 2012 compared to earlier versions) |
Middle click from the 'Sampler Info' node onto the 'Set Range' node. Choose 'Other...' from the menu to enter the Connection Editor.
Look for the 'Normal Camera' output in the left panel, choose 'Normal Camera X' and link it to the 'valueX' Input in the right panel. Repeat this step by linking the 'Normal Camera Y' with 'value Y'. Close the editor.
The next step is to connect the 'Set Range' to the offset U and V of the 'place2dTexture' node of the file texture. You'll need to use the Connection Editor again to make the required connection.
In the outputs (left side) panel inside the Connection Editor, find 'outValue', and connect 'outValueX' to 'offsetU' in the right panel. Do the same for 'outValueY' and 'offsetV'.
The setRange node works here as the control knob for the intensity (or perceived depth) of the texture offset. Bring up the attributes of the setRange node and firstly set the 'Old Min' values for both x and y to -1. Set the 'Old Max' values for x and y to 1.
For the 'New Min' and 'New Max' values, you will need to play around a bit to find out what looks best for your shot. The general idea is the greater the range, the greater the offset will be. Smaller values (such as -.25 for the 'New Min' and .25 for the 'New Max'), will give a shallower parallax.
That's it. :) Hope you can find some good uses for this interesting technique.
Look for the 'Normal Camera' output in the left panel, choose 'Normal Camera X' and link it to the 'valueX' Input in the right panel. Repeat this step by linking the 'Normal Camera Y' with 'value Y'. Close the editor.
Connecting samplerInfo to setRange |
The next step is to connect the 'Set Range' to the offset U and V of the 'place2dTexture' node of the file texture. You'll need to use the Connection Editor again to make the required connection.
In the outputs (left side) panel inside the Connection Editor, find 'outValue', and connect 'outValueX' to 'offsetU' in the right panel. Do the same for 'outValueY' and 'offsetV'.
The setRange node works here as the control knob for the intensity (or perceived depth) of the texture offset. Bring up the attributes of the setRange node and firstly set the 'Old Min' values for both x and y to -1. Set the 'Old Max' values for x and y to 1.
For the 'New Min' and 'New Max' values, you will need to play around a bit to find out what looks best for your shot. The general idea is the greater the range, the greater the offset will be. Smaller values (such as -.25 for the 'New Min' and .25 for the 'New Max'), will give a shallower parallax.
Adjust New Min/New Max values to control the parallax |
That's it. :) Hope you can find some good uses for this interesting technique.
Final Shader |
Another excellent tutorial. Love this technique. As an environment artist, I usually want to model the interior of the rooms but the poly counts, render times, and creation time of the scene usually suffer. This is dead useful.
ReplyDeleteThanks again!
Thanks for taking the time to comment :) More tutorials to come!
ReplyDeletethanks man,very useful!!
ReplyDeleteI have just found this blog and I love it! Thanks for taking the time to write these tutorials! I hope someday you will get your hands on vray for maya as well :)
ReplyDelete