Hi all,
I'm trying to 'extrude' 4 sides of a cube, from a linestrip with 4 vertices.
After playing around I think I'm almost there, but I'm missing something crucial.
This is what I do:
- create 4 vertices (VTX buffer)
- draw them as a linestrip
- execute my Geometry Shader, taking line[2] as input and a trianglestream as output
The result so far is that 2 of the 4 sides of the extracted cube (without 'caps'/ top-bottom) are drawn correct.
It might be something with the normals, not sure.
Here's the code, can someone help me out?
[maxvertexcount(4)]
void GSStrip(line VertexOut gin[2], inout TriangleStream<GeoOut> stream)
{
/* 4 vertices as input, 1 linestrip
1 .-----------. 2 0 = -1, 0, -1
| | 1 = -1, 0, 1
| | 2 = 1, 0, 1
| | 3 = 1, 0, -1
0 .-----------. 3
create 4 new vertices 'above' 0 to 3 and draw sides of the cube using trianglestrips
the input linestrip is dimension[2] -> meaning the GS processes 'per line' / 2 connected vertices
2 .---------. 3
| | Y = up (2 and 3 are XZ == 0 and 1)
| |
0 .---------. 1
Strip1: 2, 3, 0
Strip2: 3, 0, 1
*/
float4 v[4];
v[0] = float4(gin[0].CenterW, 1.0f);
v[1] = float4(gin[1].CenterW, 1.0f);
v[2] = v[0];
v[2].y = 15.0f;
v[3] = v[1];
v[3].y = 15.0f;
GeoOut gout;
[unroll]
for(int i = 0;i<4;++i)
{
gout.PosH = mul(v[i], gViewProj);
gout.PosW = v[i].xyz;
gout.NormalW = float3(-1.0f, 0.0f, 0.0f);
gout.Tex = gTexC[i];
stream.Append(gout);
}
// stream.RestartStrip();
}
// in the code, creating the vtx buffer
vertices[0].Pos = XMFLOAT3(-5.0, 0.0f, -5.0f);
vertices[1].Pos = XMFLOAT3(-5.0, 0.0f, 5.0f);
vertices[2].Pos = XMFLOAT3(5.0, 0.0f, 5.0f);
vertices[3].Pos = XMFLOAT3(5.0, 0.0f, -5.0f);