I'm starting with geometry sahder to simply transform vertex pos/norm in world space and pass this to ouput vertex buffer for sequential rendering.
A unique original model is created with position centered 0,0,0
Then for each model a position is defined and a buffer for output stream is created that match the VBCount of the original model. To be sure the streambuffer is filled at creation with the original model data
Then I apply a permodel translation matrix based on model position with the geometryshader to fill the output streamed vertexbuffer.
I get no debug errors but the model remains all centered 0,0,0 like if the geometry shader was doing nothing
The geometry shader is created with createwithstreamoutput
below some code (c++ directx11)
Layout for vertex input in geometry shader
const D3D11_SO_DECLARATION_ENTRY WNCT_SOLayout[] =
{
{ 0, "POSITION", 0, 0, 3, 0 },
{ 0, "NORMAL", 0, 0, 3, 0 },
{ 0, "COLOR", 0, 0, 4, 0 },
{ 0, "TEXCOORD", 0, 0, 2, 0 }
};
QUESION should we use COLOR0...?
Layout for vertex output in geometry shader/input in vertex shader
typedef struct _WNCTert
{
XMFLOAT4 Pos;
XMFLOAT3 Normal;
XMFLOAT4 Color;
XMFLOAT2 Tex;
}WNCTVert, *LPWNCTVert;
const DWORD SIZE_WNCTVERT = sizeof(WNCTVert);
Shaders creation (vertex and layout are created as well)
ID3D11GeometryShader* pGS = NULL;
UINT stride[1];
stride[0] = UINT(SIZE_WNCTVERT);
hr2 = gpD11->CreateGeometryShaderWithStreamOutput(pGSBlob->GetBufferPointer(), pGSBlob->GetBufferSize(),
WNCT_SOLayout, _countof(WNCT_SOLayout), stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &pGS);
some sttings (not sure gssetsampler is required) geometryshader for pointlist so no need for indexbuffer pS is my shader struct with vertex/geometry/pixel shaders and layout pMeshIn is the vertexbuffer used as input in geometryshader pMeshOut is the vertexbuffer used as streamout in geometryshader and input in vertex shader
gpDC11->GSSetSamplers(0, 1, &gpSampler[cS_Point]);
gpDC11->OMSetDepthStencilState(gpDSSOff, 0);
gpDC11->IASetIndexBuffer(NULL, DXGI_FORMAT_R16_UINT, 0);
gpDC11->IASetInputLayout(pS->pVL);
gpDC11->VSSetShader(pS->pVS, NULL, 0);
gpDC11->GSSetShader(pS->pGS, NULL, 0);
UINT Offset = 0;
gpDC11->SOSetTargets(1, &pMeshOut->VB, &Offset);
gpDC11->IASetVertexBuffers(0, 1, &pMeshIn->VB, &pMeshIn->stride, &Offset);
gpDC11->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
gpDC11->DrawAuto();
now the hlsl
cbuffer cbMesh : register(b1)
{
matrix World;
float4 FactorColor;
};
struct VS_INPUT
{
float3 Pos : POSITION;
float3 Norm : NORMAL;
float4 Col : COLOR0;
float2 Tex : TEXCOORD0;
};
struct VS_SOINPUT
{
float4 Pos : POSITION;
float3 Norm : NORMAL;
float4 Col : COLOR0;
float2 Tex : TEXCOORD0;
};
[maxvertexcount(3)]
void GS_PosToWorld(point VS_INPUT Input[1], inout PointStream<VS_SOINPUT> outStream)
{
VS_SOINPUT Output;
Output.Pos = mul(float4(Input[0].Pos, 1), World);
Output.Norm = normalize(mul(Input[0].Norm, (float3x3)World));
Output.Col = Input[0].Col;
Output.Tex = Input[0].Tex;
outStream.Append( Output);
}
VS_SOINPUT VS_PosToWorld(VS_SOINPUT Input)
{
return Input;
}