View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Icosahedron Tessellation

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1~Helgon  Members

Posted 11 December 2012 - 04:18 PM

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[i] = sp.Vertices[i].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];


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;
};
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[i].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
{
}
}


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

Regards ~Helgon

#### Attached Thumbnails

Edited by ~Helgon, 11 December 2012 - 04:19 PM.

from time to time i find time

### #2~Helgon  Members

Posted 11 December 2012 - 04:27 PM

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;
}


from time to time i find time

### #3~Helgon  Members

Posted 11 December 2012 - 06:21 PM

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:

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

from time to time i find time

### #4Quat  Members

Posted 11 December 2012 - 07:11 PM

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.
-----Quat

### #5~Helgon  Members

Posted 11 December 2012 - 07:23 PM

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.

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, 11 December 2012 - 07:24 PM.

from time to time i find time

### #6Quat  Members

Posted 11 December 2012 - 07:30 PM

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.
-----Quat

### #7~Helgon  Members

Posted 11 December 2012 - 07:35 PM

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;
}


from time to time i find time

### #8Nik02  Members

Posted 12 December 2012 - 06:21 AM

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.

Niko Suni

### #9~Helgon  Members

Posted 12 December 2012 - 10:33 AM

Yeah, I've realized after i posted it

from time to time i find time

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.