Using Displacement

01. Introduction

In this exercise we will be covering displacement. For those of you coming from a real time background, displacement might be new to you. It is a technique whereby an image is used to move or “displace” physical geometry at render time. It is similar to a bump map except it is again actual geometry that is being created and moved and not a rendering trick.

From V-Ray’s Displacement Modifier Help Page – bump map on left vs. displacement map on right:

03. Exercise

In this exercise you’re going to learn how to UV Unwrap a wicker object for displacement (a common technique for wicker), how to apply a VRayDisplacementModifier and adjust its settings and how to create wrinkles in fabric using only procedural generation and displacement.

a. Set Up

We have provided the basic model – bring it into your scene using the File -> Merge command.

You will also need to install Soulburn Scripts if you haven’t already. These plugins are super useful, and we will be using TexmapPreview quite a lot in this tutorial! To install Soulburn, go to this website and follow the instructions.

Afterwards we’ll want to make a shortcut on your toolbar. Under Customize -> Customize User Interface, go to Toolbars. Under Category, choose SoulburnScripts and scroll down until you find TexMapPreviewUI. Drag it onto a menu of your choice.

b. Unwrap the Model

You’ll notice that the model already has some UVs. However, and especially for displacement, these UVs are incorrect because they have seams right in the middle of the model. Displacement is especially suspect to incorrectly placed UVs. When a displacement map encounters a texture seam, the division can be very visible. Remap this model to minimize seams to three (not including the feet): the top, bottom, and side. Minimize texture distortion. Hint: the unwrap as it is is already close to usable.

c. Apply the Diffuse Material:

i. Unzip the Material file we have supplied. Inside the zip folder you will find a mat material library and a resources folder with two textures. Place these in your project directory.

To import a new material library, open the material editor (M). Under the Material/Map Browser you will find a small down arrow – click that, then click Open Material Library. Browse to the Material Library and open it. See image to right.

ii. Load DisplacementTutorialWicker into the material editor by dragging and dropping it into your Material Editor. If your material comes in blank, with missing textures as shown below, then you will need to retarget the texture assets to the resources folder.

iii. Press Shift-T to open the Asset Tracking window. Hit the Refresh button on the top left. Select the two textures that are missing by holding shift and left clicking on each.

iv. Once both are selected, right click on them. Select “Set Path” and point the path to where the resources/ folder from the ZIP is located. Once you’ve realigned the paths, you can apply the material to the table model.

You should end up with something like below. Note that this model is slightly faceted. Feel free to add an OpenSubdiv modifier on top of the stack to smooth it out.

d. Adding and Using the Displacement Modifier:

You might have noticed that there is nothing plugged into the displacement slot in the material. That’s because we use the VrayDisplacementModifier instead, because of the greater control it gives us.

i. First, add the modifier to the table from the Modifier drop-down:

ii. Next, we’re going to take the “Bump” texture and drag the noodle into the Texmap slot of the Displacement Modifier. Make sure to use it as an instance.

iii. Leave the Amount at .1 and do a test render. Note that Amount is in workspace units – so 1.0 = 1 inch. Same with Shift and Water level. After the render completes, you should end up with something like this:

iv. Pretty easy to make some complicated detail, right? Notice the silhouette of the table: It now has variation. Unlike bump mapping, displacement will physically add polygons and move them around to add geometric detail.

e. VRayDisplacementModifier Settings:

Let’s take a look at some of the settings. For in-depth details on every setting available, take a look at the V-Ray help docs on displacement.

i. Type

These are different ways that the displacement is calculated. Generally, you should only use 3D Mapping.

ii. Texmap/Texture chan/Filter texmap/Filter blur

These control the texture image that is used for the displacement. You already know what the Texmap box is for. Texture chan determines which UV channel is used for the Texmap. Filter texmap allows you add a small amount of blur and smoothing to the image (controllable with Filter Blur) to smooth out any super-sharp details. Generally, you can check the Filter box and leave it at the default of .001 if you are using a good map for your displacement.

iii. Amount

The amount the displacement pushes out in real-world units.

iv. Shift

You may notice that your displacement will tend to “puff out” the entire model. This is because displacement will take the surface geometry and move them outwards according to the value set in the Amount. If your texture is mostly white, this means that your model can grow in size infinitely depending on what value you set!

We often see rugs get eaten up by a floor if the floor’s displacement value is set too high – again, because the surface is being moved outwards.

To combat this, we can use the Shift value. What this basically does is “move” the surface inwards before starting the displacement, thus limiting the maximum height of the final displaced surface. See the graphic below and watch this video.

v. Water Level

Water level will cut off everything below the value. For example, if you set the amount to 1 and the water level to .5, any low-lying geometry will be culled from the render. You can easily make your model disappear if you set this too high! For example in the render below, the Amount is set to 1 but the water level is set to .5 – so everything from 0 to half an inch is just removed.

vi. Relative to bbox

This will change the way Max calculates the displacement heights. Leave it unchecked.

vii. Texmap min/max

These are useful when using a 16-bit texture as it will allow black to actually displace inwards, grey to be 0, and white to displace outwards. Generally, however we do not use this functionality. If you would like to learn more, watch this Youtube video. Basically when you generate a 16-bit texture, some of the values will actually be negative. These min/max values act as clamps on that value – so if you have a black value of -5 in your texture, then you can set -5 as the minimum value here and it will allow that negative value to act as a displacement. We rarely work with 16 bit textures and this option doesn’t work with procedural textures.

viii. Edge length

Earlier we explained how displacement will automatically subdivide geometry to add more edges. The amount of edges that are added are controlled using this number. If you are getting artifacts or a polygonal look to your displacement, increase this value. It measures the maximum amount of pixels an edge is allowed to occupy before it is subdivided into a smaller triangle. The smaller the number, the more subdivided the model gets.

Edge length set to 20

Edge length set to 4

ix. View-dependant

When checked, the above explanation works. When unchecked, Edge length is in world units instead instead of pixels. So a value of 1 in the Edge length becomes 1 inch before the edge is subdivided again. Generally, you should keep it on.

x. Keep continuity

This is a very important checkbox, but it’s off by default. When a displacement rounds a corner, it can displace the two surfaces on either side of the corner away from each other, creating a gap that will appear in the render as a black area. Enabling this option will make sure that your edges stay together! In the images below you can see when this is disabled (left) vs. when it is enabled (right).

Keep continuity disabled

Keep continuity enabled

xi. Edge thresh

This value controls the blending between different maps on different faces. Keep it low – generally you shouldn’t change it from the default

f. Creating the Tablecloth

Displacement isn’t just useful for adding small geometry changes – it’s also very useful for creating folds in fabric!

i. Create a cylinder and center it to the table. Turn it to an edit poly and inset the top face a couple times. Delete the bottom face and move the bottom edge down to about halfway down the table.

ii. Add some retaining loops and shape the tablecloth to fit over the top of the table. Add an OpenSubdiv modifier.

iii. Add a volume select. Change its Stack Selection Level to Vertex. This will select all vertices within the Volume Select’s bounding box. Click the plus symbol next to the modifier and select the gizmo. Drag it down to the bottom of the table and scale it so it only selects the bottom row of verts and goes about 1/4th the way up the skirt.

iv. Next, add a noise modifier. This will use the vertices selected by the volume select. The noise modifier will vary the bottom edge of the fabric to give it a more natural look. Set the scale to somewhere around 2 and the strength to be around 1 in the Z axis.

v. Now, add an Edit Poly modifier. Select the bottom edge, and then go to Edit Edges -> Create Shape and set the shape to linear. This will create a spline based on your edge selection.

Shape shown with tablecloth hidden for demonstration purposes.

vi. In the Material Editor create a Bercon Noise with its size set to 1. Next, create a VRayDistanceTex and double click it. Under “Objects”, click “Add” and select the shape that you just created.

vii. Next, click and drag the “Far color” onto the “Near color”. A dialogue will appear. Click on “Swap”

We’ve now set up our VRayDistance texture to show white (or anything plugged into “Near Color”) up to 10 inches away from the spline we just created and selected (in my case, Shape002).

viii. Plug the Bercon Noise into the “NearTexture” slot in the VRayDistanceTex. Now instead of showing white, it will show our Bercon Noise. If we had left the near color black, it would not have shown anything near the Shape we selected.

ix. Let’s make a preview look of the BerconNoise map! Launch the TextmapPreviewUI shortcut that you created in Step 1. It is shown to the right.

Basically what this tool does is it will display whatever texture you have selected on a selected model, as it would appear at render time. This is super useful for procedural materials as they will not render correctly (or at all) in the Viewport. Under “Which Objects” you want to make sure you have “Selected Objects” selected. Under “Which Map” you can choose to lock a map you have selected, or it will choose whatever map you have selected at the time. NOTE: This tool will render ONLY the object you have selected.

Self Illumination can be adjusted to make the texture more or less clear.

Finally, under options you want to either set it to Render Current Viewport or Render Locked Viewport (controlled in your render settings). You also want to make sure that “Use Slate Mat Editor” is selected.

Hitting “Do” will run the tool and close the window. Hitting “Apply” will run the tool and keep the window open. We recommend you mostly use the latter.

x. Select the tablecloth and the BerconNoise, then hit Apply. A render window should open up and you should get something like this:

This is how the BerconNoise is appearing at render time on our model. Notice two things:

– This is a lower resolution render that goes very quickly, making this tool much more efficient for testing your texture mapping.

– We did not actually apply this texture to the model. TexmapPreview will take whatever texture you have selected and apply it to the model at render time – regardless of whether or not it is actually applied through the material editor.

xi. Ok so now that we know what the BerconNoise map looks like, let’s tweak it to make it look long and more like folds of fabric. Under “Mapping”, change the Z scale of the BerconNoise to 10, then run TexmapPreview again.

xii. That looks more like fabric – but if this is going to be our displacement, we only want it to show up closer to the bottom of the sheet. That’s where VRayDistanceTex comes in. Double click on the DistanceTex and change the distance to 5. Then, with VRayDistanceTex still active, run TexmapPreview. NOTE: If you see all black, reduce your distance. If you see all white, or no change, increase it.

xiii. So this gives us a rough idea of the fabric folds – but now we need to see what it looks like as displacement. Add a VRayDisplacementModifier to the top of the stack on the tablecloth if you haven’t already. Drag the noodle from VRayDistanceTex to the Texmap option in the VRayDisplacementModifier. Set the Amount to 1 and do a test render.

xiv. Yours might have an issue where the bottom of the cloth is very jagged and polygonal looking. This is because the Edge length isn’t set high enough.

Try changing your Edge length to .5 or 1 (depending on your initial OpenSubdiv level), then do another render.

xv. Cool! But now let’s make those folds go up a little higher. When doing the TexmapPreview, it will also calculate displacement. While this can sometimes be useful, we don’t want it slowing down our render right now – all we want to see is how high up the wrinkle pattern goes. To disable displacement for everything in the scene, go to your render settings. Under V-Ray -> Global Switches, uncheck Displacement.
Note that this is also really useful for diagnosing scenes that take a very long time to render: if unchecking this makes your scene go faster, you know the issue is with displacement!

xvi. Now increase the distance in your VRayDistanceTex and do another TexmapPreview render. I increased mine to 8:

xvii. You can play with the scale settings of the BerconNoise to change the pattern of the fabric wrinkles. Here I have my X and Y at .5 and my Z is still 8.

xviii. Re-enable Displacement and do another render. This is what mine looks like!

xix. Add some material! I used Bumpy_Fabric from the Basic_Upholstery library in the Material Library. Add it to Slate and assign it to the object. Since we have Displacement in the VRayDisplacementModifier it will override any displacement in the material. You can download the final model here (with textures) to compare. Note that there is only a basic, single-color material applied to the tablecloth in this sample file.

02. How it Works

Displacement maps work by subdividing the mesh at render time to create new polygons.

These polygons are then moved according to the map where white is up and black is no change.

In this way it is different from bump maps in that black is a negative change. With that being said, it is possible to mimic this behavior with the VRayDisplacementModifier and it’s shift functionality – though it still doesn’t work exactly the same (see Shift under Section 5 below and watch this video starting at 0:21).

Technically, black can be a negative values like bump, but only when using 16 bit images. For the majority of our work you will not be using this functionality.

To get a little more in-depth on how displacement works, the images below show how it subdivides geometry at low displacement detail (left) and high (right). The red lines are the original geometry – what you would see in the modeling viewport.

Depending on the settings you choose in the V-Ray Modifier, you can adjust how much extra geometry is added via tessellation.