# Icosahedron Tessellation

This topic is 1866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I have following problem.

I generate an Icosahedron and pass it to the tessellation stage but all i get back is just a single triangle subdivided.

Just an other question - I'm not sure if i understood it right so: I can pass a objects with a maximum CONTROL_POINT_PATCHLIST of 32 - what if the polygon i want to pass has more vertices then 32?

But back to my main problem. The vertices are passed here - i think that this should be right

 GeometryGenerator geoGen; GeometryGenerator::MeshData sp; geoGen.CreateGeosphere(25, 0, sp); vc = sp.Vertices.size(); std::vector<XMFLOAT3> vertices(sp.Vertices.size()); std::wostringstream wos; wos << L"Vertices Count: " << sp.Vertices.size() << "\n"; OutputDebugString(wos.str().c_str()); for(int i = 0; i < sp.Vertices.size(); ++i) { vertices = sp.Vertices.Position; } D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_IMMUTABLE; vbd.ByteWidth = sizeof(XMFLOAT3) * 12; vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vinitData; vinitData.pSysMem = &amp;vertices[0]; HR(md3dDevice->CreateBuffer(&amp;vbd, &amp;vinitData, &amp;mQuadPatchVB)); 

and the input topology is:

 md3dImmediateContext->IASetInputLayout(InputLayouts::Pos); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST); 

and the HLSL is - in fact it should work but i don't know why it just displays the first triangle.

 #include "LightHelper.fx" cbuffer cbPerFrame { DirectionalLight gDirLights[3]; float3 gEyePosW; float gFogStart; float gFogRange; float4 gFogColor; }; cbuffer cbPerObject { float4x4 gWorld; float4x4 gWorldInvTranspose; float4x4 gWorldViewProj; float4x4 gTexTransform; Material gMaterial; }; // Nonnumeric values cannot be added to a cbuffer. Texture2D gDiffuseMap; SamplerState samAnisotropic { Filter = ANISOTROPIC; MaxAnisotropy = 4; AddressU = WRAP; AddressV = WRAP; }; struct VertexIn { float3 PosL : POSITION; }; struct VertexOut { float3 PosL : POSITION; }; VertexOut VS(VertexIn vin) { VertexOut vout; vout.PosL = vin.PosL; return vout; } struct PatchTess { float EdgeTess[3] : SV_TessFactor; float InsideTess[1] : SV_InsideTessFactor; }; PatchTess ConstantHS(InputPatch<VertexOut, 12> patch, uint patchID : SV_PrimitiveID) { PatchTess pt; pt.EdgeTess[0] = 15; pt.EdgeTess[1] = 15; pt.EdgeTess[2] = 15; pt.InsideTess[0] = 15; return pt; } struct HullOut { float3 PosL : POSITION; }; [domain("tri")] [partitioning("integer")] [outputtopology("triangle_cw")] [outputcontrolpoints(12)] [patchconstantfunc("ConstantHS")] [maxtessfactor(64.0f)] HullOut HS(InputPatch<VertexOut, 12> p, uint i : SV_OutputControlPointID, uint patchID : SV_PrimitiveID) { HullOut hout; hout.PosL = p.PosL; return hout; } struct DomainOut { float4 PosH : SV_POSITION; float4 Color : COLOR; }; [domain("tri")] DomainOut DS(PatchTess patchTess, float3 uv : SV_DomainLocation, const OutputPatch<HullOut, 12> tri) { DomainOut dout; float3 p = uv.x*tri[0].PosL + uv.y*tri[1].PosL + uv.z*tri[2].PosL; dout.PosH = mul(float4(p, 1.0f), gWorldViewProj); dout.Color = float4(uv.yx, 1-uv.x, 1); return dout; } float4 PS(DomainOut pin) : SV_Target { return pin.Color; } technique11 Tess { pass P0 { SetVertexShader( CompileShader( vs_5_0, VS() ) ); SetHullShader( CompileShader( hs_5_0, HS() ) ); SetDomainShader( CompileShader( ds_5_0, DS() ) ); SetPixelShader( CompileShader( ps_5_0, PS() ) ); } } 

Probably it's just something pretty stupid but i hope someone can help me.

Regards ~Helgon Edited by ~Helgon

##### Share on other sites
I think i found the mistake:

I always index the first 3 entrys but im not sure how to change it because as i learned the DomainShader is called for every vertex so I'm not sure how to calculate the indices. Maybe someone knows the answer?

 [domain("tri")] DomainOut DS(PatchTess patchTess, float3 uv : SV_DomainLocation, const OutputPatch<HullOut, 12> tri) { DomainOut dout; float3 p = uv.x*tri[0].PosL + uv.y*tri[1].PosL + uv.z*tri[2].PosL; // <-- heres the mistake i think dout.PosH = mul(float4(p, 1.0f), gWorldViewProj); dout.Color = float4(uv.yx, 1-uv.x, 1); return dout; } 

##### Share on other sites
Hmm.. i tried to change it in the way that i just send 3 vertices at once
 [domain("tri")] DomainOut DS(PatchTess patchTess, float3 uv : SV_DomainLocation, const OutputPatch<HullOut, 3> tri) { DomainOut dout; float3 p = uv.x * tri[0].PosL + uv.y * tri[1].PosL + uv.z * tri[2].PosL; dout.PosH = mul(float4(p, 1.0f), gWorldViewProj); dout.Color = float4(uv.yx, 1-uv.x, 1); return dout; } 
and my output changed to:

[attachment=12738:tri.png]

That's kinda normal because I just pass 12 vertices and no index buffer so its just 12 / 3 triangles .. as in the picture..

Do i have to send each vertex-triangle combination through the shader stages ? as a replacement for the missing index buffer?

I have no idea and the problem is that there is nothing on the internet. Everything i find is just f***** tessellate just a single triangle or a quad but nothing more complex

##### Share on other sites
You can build the triangle list for the isocahedron, and use 3 control points. Each input primitive is a triangle and the initial vertices are the control points. Then tessellate each triangle, and project the tessellated vertices back on to the unit sphere. The more you tessellate the better the sphere approximation.

##### Share on other sites
thanks for the answer. I've already realized that my whole attempt was kinda stupid. I don't just want to "sub-tessellate" the sides of the icosahedron,in fact i want to tessellate the icosahedron into a sphere.

at least i now got it to draw the icosahedron subdivided.

[attachment=12740:q.png]

but now as u said i have to kinda "drag" the points on the outline of the spehre.. how do i approach the problem? is there a formula?

regards Edited by ~Helgon

##### Share on other sites
Assuming your icosahedron is centered about some coordinate system, then in that coordinate system you can project the vertex onto the unit sphere by normalizing it. To get a point on a sphere with radius R, just scale the unit vector by R.

##### Share on other sites
Dude.. i just tried something like that but with the normal.. its already to late haha

i thank you so incredible much! thanks thanks!

just if someone else ever needs it:
 [domain("tri")] DomainOut DS(PatchTess patchTess, float3 uv : SV_DomainLocation, const OutputPatch<HullOut, 3> tri) { DomainOut dout; float3 p = uv.x * tri[0].PosL + uv.y * tri[1].PosL + uv.z * tri[2].PosL; p = normalize(p); dout.PosH = mul(float4(p, 1.0f), gWorldViewProj); dout.Color = float4(uv.yx, 1-uv.x, 1); return dout; } 

[attachment=12741:s.png]

##### Share on other sites
Regarding the limitation on the number of the control points; you can read from buffers and textures in every shader stage to access more memory. Though the limitation of 32 control points is per patch; you can have a huge amount of these patches per draw call.

##### Share on other sites
Yeah, I've realized after i posted it