Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actual~Helgon

Posted 11 December 2012 - 04:19 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];
    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[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
    {
	    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

#1~Helgon

Posted 11 December 2012 - 04:18 PM

Hey, I have following problem.

I generate a 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 = &vertices[0];
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &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[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
    {
	    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

PARTNERS