I'm curious because I was thinking that displacement mapping is done in the shader file only inside the domain shader. Am I correct or is it both implemented in the rendering section of the mesh and shader? So, if I make a cube for an example, I would have to read out the displacement map file then tell what vertices get positioned inside the render or only in the shader file? I'm a bit stuck on that concept.

These are the snap shots done inside the game editor of a plane. I believe the issue lies within the texture but you can always correct me.


This texture was created for the box inside 3DS Max and the UV Mapped, then baked the image.

When I load a sphere, not so much crazy gaps but it's still hasty.

Sphere that is cracky a bit


I would do this by setting the displacement texture and a sampler to the domain shader, than sample that on every vertex on the appropriate mip level (done by SampleLevel in hlsl). So you have a 0.0-1.0 value on your vertex, which you offset along its normal by it (and additionaly multiplied by a scalar), like for example:

pos.xyz += normal.xyz * (sampledValue - 0.5f) * displacementStrength;

And in the "rendering section", the c++ code I only decide if the model should be tessellated or not (based on distance, for example, or size...). If yes, bind the hull and domain shaders and set the resources. (Note that you should sort your models if possible to avoid many state-changes, like binding shaders and clearing device. (I would draw the untessellated meshes first, than setting the hull and domain shaders and proceed with the tessellated ones.)

  • \$\begingroup\$ ok, when I use the normal then the whole mesh blows apart - for instance the cube has it's each side gapped. So, I instead with the Normals I just said \$\endgroup\$ – SICGames2013 Nov 18 '13 at 16:30
  • \$\begingroup\$ pos.xyz += float3(0.0f,1.0f,0.0f) * (sampledValued * 10.0f) and it's more watertight. Any reason for the whole entire mesh to have gaps? In addition, the whole mesh moves and I'm still figuring out why. \$\endgroup\$ – SICGames2013 Nov 18 '13 at 16:32
  • \$\begingroup\$ @SICGames2013 Wherever there is a hard edge in the mesh, you'll get cracks because the surface gets displaced in different directions for different normals. Bryan Dudash's talk My Tessellation Has Cracks has some approaches to solve this. \$\endgroup\$ – Nathan Reed Nov 18 '13 at 16:47
  • \$\begingroup\$ @SICGames2013 As for the whole mesh moving, that's probably because float3(0.0f,1.0f,0.0f) * (sampledValued * 10.0f) is just displacing everything along the y axis. That's not going to work right for surfaces that are oriented parallel to the y axis. \$\endgroup\$ – Nathan Reed Nov 18 '13 at 16:49
  • \$\begingroup\$ Now, I don't have anything moving in all directions. Just have open gaps or cracks. I looked at the My Tessellation Has Cracks and and doing side by side comparisions with Nvidia's Gregory ACC Displacement Sample from the Nvidia SDK 11 Samples. Getting closer though, I'll have to look at the displacement image to see if there's anything I can fix. \$\endgroup\$ – SICGames2013 Nov 18 '13 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.