# Easiest way to smoothen coarse mesh with HLSL?

I've browsed through a couple of presentations and papers about DX11 tessellation and they all say that one of the most common usages of tessellation is to take a coarse (low poly) mesh, smoothen it and then apply displacement mapping. They mention mainly two smoothening algorithms (although I might be wrong, I'm new to the topic): Catmull-Clark and PN Triangles. The former's algorithm is pretty simple to understand but honestly I don't know how to implement that with HLSL. PN Triangle's algorithm seems pretty straightforward.

But maybe there are other important algorithms. Which one is the easiest to implement? Or maybe one is significantly faster that the others?

Or maybe I'm doing it all wrong? :P

I think phong smoothing is the easiest to implement and it is the most lightweight algorithm for this (as far as I know), though it may produce lower quality results. Implementing it is as easy as copy-pasting this code and applying it in your domain shader (that is if you already have tessellation working):

struct ConstantOutputType //This is what the hull shader outputs
{
float edges[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;

float3 f3B0 : POSITION0;
float3 f3B1 : POSITION1;
float3 f3B2 : POSITION2;

float3 f3N0 : NORMAL0;
float3 f3N1 : NORMAL1;
float3 f3N2 : NORMAL2;
};

//The new functions
float3 project(float3 p, float3 c, float3 n)
{
return p - dot(p - c, n) * n;
}

// Computes the position of a point in the Phong Tessellated triangle
float3 PhongGeometry(float u, float v, float w, ConstantOutputType hsc)
{
// Find local space point
float3 p = w * hsc.f3B0 + u * hsc.f3B1 + v * hsc.f3B2;
// Find projected vectors
float3 c0 = project(p, hsc.f3B0, hsc.f3N0);
float3 c1 = project(p, hsc.f3B1, hsc.f3N1);
float3 c2 = project(p, hsc.f3B2, hsc.f3N2);
// Interpolate
float3 q = w * c0 + u * c1 + v * c2;
// For blending between tessellated and untessellated model:
//float3 r = LERP(p, q, alpha);
return q;
}

// Computes the normal of a point in the Phong Tessellated triangle
float3 PhongNormal(float u, float v, float w, ConstantOutputType hsc)
{
// Interpolate
return normalize(w * hsc.f3N0 + u * hsc.f3N1 + v * hsc.f3N2);
}


Use these functions on your hull shader output vertices to get the smoothed vertices (positions,normals). I think AMD released this code some time ago, though I may not remember correctly.

• I only know of a Phong shading algorithm/model/etc... Can you provide any source/link/info on this Phong smoothing algorithm as I need to know what I'm dealing with? – NPS Feb 23 '14 at 0:01
• perso.telecom-paristech.fr/~boubek/papers/PhongTessellation/… – János Turánszki Feb 23 '14 at 0:37
• Any way this could be used for quad (topology) tessellation? – NPS Feb 23 '14 at 17:20
• Sorry, I am not familiar with that. :( – János Turánszki Feb 23 '14 at 20:15