# Unity3d tessellation algorithm and number of subdivided triangles.

Hello. I am looking for a way to create tessellation shader which could work as common subdivision level,

for example I have got simple mesh with tessellation scale=1 (2 triangles):

and with tessellation scale=2 I could have this result (8 triangles):

and with tessellation scale=3 I could have 3x3x2=18 triangles etc.

I wonder how can I check triangle count when I apply tessellation shaders in Unity3d, for instance I use tessellation shader from Shader Forge and in active profiler window I can check only real amount of visible triangles from imported mesh without subdivided triangles (I can change tessellation scale and number of triangles is still the same).
Which kind of tessellation algorithm in Unity3D is used by default (flat, PN triangles, Phong) and is there formula for counting number of vertices for every tessellation scale factor ?

I found that I can use this code:

``````struct HS_CONSTANT_OUTPUT
{
float edges[4] : SV_TessFactor;
float inside[2] : SV_InsideTessFactor;
};

HS_CONSTANT_OUTPUT HSConst()
{
HS_CONSTANT_OUTPUT output;

output.edges[0] = 4.0f;
output.edges[1] = 4.0f;
output.edges[2] = 4.0f;
output.edges[3] = 4.0f;

output.inside[0] = 4.0f;
output.inside[1] = 4.0f;

return output;
}
``````

How can i combine this code with tessellation shaders from this thread:

I also tried to run this code:

but I have a lot of compile errors, for example:
Shader error in âTessellation/Vector Displacement Quadâ: undeclared identifier âpatchâ at line 140 (on d3d11) etc.

I need help:(

Someone brought this to my attention and I can confirm: my quad tessellation shader will not work in Unity 5. If more than a few people want this, I could re-visit and try to get it workingâŠ

I canât believe so few people seem to be interested in support for quad tessellation. Why is that? Itâs not on the roadmap either.

Yeah I donât get it either. Iâve been considering reviving my quad tessellation shader, but havenât had the time. Iâll admit that itâs kind of a mess, and hard to hack on. I wasnât taking the project too seriously back when I first worked on it, since there was no way to import a mesh with quads through the normal importer. I had to hack my own OBJ parser to do it.

Now that we can âkeep quadsâ on import, this is a more viable asset for use within Unity. Hopefully Iâll be able to get this working again sometime soon on a rainy day

âkeep quadsâ, nice. You will have at least one happy user =) It would be lovely to know if Unity consider implementing build-in support.

https://docs.unrealengine.com/en-us/Resources/ContentExamples/MaterialProperties/1_8

Hi, sorry to necrobump, but I am curious if this is the same thing? Also sorry if it is irrelevant, I am new to unity shaders, but I am looking for a place to learn, and I am wondering if something like this is resource intensive?

Thanks

1 Like