Sign in to follow this  
dolphin2011

about geometry shader

Recommended Posts

[size="3"]Hello everybody!
[/size]welcome to my first post.I'm a beginner to HLSL,this days I have tryed to write a simple geometry demo in d3d11,
but without using the effect framework, the code just like following,in the geometry shader I want to create one triangle strip as a point sprite,
but it didn't work,nothing display on the screen,why it happens?can anyone give me some suggestion? thanks very much.

[code]

HRESULT hr = S_OK;
ID3DBlob* pd3dBlob = NULL;
hr = CompileShaderFromFile(_T("gstest.fx"), "VS_Proc", "vs_4_0", &pd3dBlob);
if (!SUCCEEDED(hr))
return hr;
hr = pd3d11Device->CreateVertexShader(pd3dBlob->GetBufferPointer(), pd3dBlob->GetBufferSize(), NULL, &g_pVertexShader);
if (!SUCCEEDED(hr))
{
SAFE_RELEASE(pd3dBlob);
return hr;
}
const D3D11_INPUT_ELEMENT_DESC layoutParticle[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}
};
hr = pd3d11Device->CreateInputLayout(layoutParticle, 1, pd3dBlob->GetBufferPointer(), pd3dBlob->GetBufferSize(), &g_playoutInput);
SAFE_RELEASE(pd3dBlob);
if (!SUCCEEDED(hr)) return hr;
if (!SUCCEEDED(hr)) return hr;
hr = CompileShaderFromFile(_T("gstest.fx"), "GS_Proc", "gs_4_0", &pd3dBlob);
if (!SUCCEEDED(hr)) return hr;
hr = pd3d11Device->CreateGeometryShader(pd3dBlob->GetBufferPointer(), pd3dBlob->GetBufferSize(), NULL, &g_pGeometryShader);
SAFE_RELEASE(pd3dBlob);
if (!SUCCEEDED(hr)) return hr;
hr = CompileShaderFromFile(_T("gstest.fx"), "PS_Proc", "ps_4_0", &pd3dBlob);
if (!SUCCEEDED(hr)) return hr;
hr = pd3d11Device->CreatePixelShader(pd3dBlob->GetBufferPointer(), pd3dBlob->GetBufferSize(), NULL, &g_pPixelShader);
SAFE_RELEASE(pd3dBlob);

// next render scene
float fClearColor[4] = {0.0f, 0.0f, 1.0f, 0.0f};
ID3D11DeviceContext* pd3d11DevContext = g_dxManager11.GetD3D11DeviceContext();
IDXGISwapChain* pdxgiSwapChain = g_dxManager11.GetDXGISwapChain();
ID3D11RenderTargetView* pd3d11RTView = g_dxManager11.GetD3D11RenderTargetView();
ID3D11DepthStencilView* pd3d11DSView = g_dxManager11.GetD3D11DepthStencilView();
pd3d11DevContext->ClearRenderTargetView(pd3d11RTView, fClearColor);
pd3d11DevContext->ClearDepthStencilView(pd3d11DSView, D3D11_CLEAR_DEPTH, 1.0f, 0);

pd3d11DevContext->VSSetShader(g_pVertexShader, NULL, 0);
pd3d11DevContext->GSSetShader(g_pGeometryShader, NULL, 0);
pd3d11DevContext->PSSetShader(g_pPixelShader, NULL, 0);

D3D11_MAPPED_SUBRESOURCE d3d11MappedRes;
HRESULT hr = pd3d11DevContext->Map(g_bufMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &d3d11MappedRes);
MatrixBuffer* pbufMatrix = (MatrixBuffer*)d3d11MappedRes.pData;
memcpy(pbufMatrix, &g_mb, sizeof(MatrixBuffer));
pd3d11DevContext->Unmap(g_bufMatrix, 0);

pd3d11DevContext->VSSetConstantBuffers(0, 1, &g_bufMatrix);

pd3d11DevContext->IASetInputLayout(g_playoutInput);

UINT nStride = sizeof(GSTestVertex);
UINT nOffset = 0;
pd3d11DevContext->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &nStride, &nOffset);
pd3d11DevContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
pd3d11DevContext->Draw(4, 0);
pd3d11DevContext->GSSetShader(NULL, NULL, 0);
pdxgiSwapChain->Present(1, 0);


// the fx file:

struct GS_Input
{
float3 fv3Pos : POSITION;
};


struct PS_Input
{
float4 fv4Pos : SV_POSITION;
float4 fv4Color : COLOR;
};

cbuffer MatrixBuffer : register(b0)
{
matrix g_matWorld;
matrix g_matView;
matrix g_matProj;
matrix g_matWVP;
matrix g_matInvView;
matrix g_matInvProj;
}

cbuffer ImmutableBuffer
{
float3 g_fv3Corner[4] =
{
float3(-1.0f, 1.0f, 0.0f),
float3(1.0f, 1.0f, 0.0f),
float3(-1.0f, -1.0f, 0.0f),
float3(1.0f, -1.0f, 0.0f)
};
float4 g_fv4Color[4] =
{
float4(0.0f, 0.0f, 0.0f, 1.0f),
float4(1.0f, 0.0f, 0.0f, 1.0f),
float4(0.0f, 1.0f, 0.0f, 1.0f),
float4(0.0f, 0.0f, 1.0f, 1.0f)
};
}

GS_Input VS_Proc(float3 fv3Pos : POSITION)
{
GS_Input outData;
outData.fv3Pos = fv3Pos;
/*PS_Input outData;
outData.fv4Pos = mul(float4(fv3Pos, 1.0f), g_matWVP);
outData.fv4Color = float4(1.0f, 0.0f, 0.0f, 1.0f);*/
return outData;
}

[maxvertexcount(4)]
void GS_Proc(point GS_Input inData[1], inout TriangleStream<PS_Input> SpriteStream)
{
PS_Input outData[4];
for (int i = 0; i < 4; i++)
{
float3 fv3Corner = g_fv3Corner[i] * 10.0f;
fv3Corner = mul(fv3Corner, (float3x3)g_matInvView) + inData[0].fv3Pos;
float4 fv4Corner = float4(fv3Corner, 1.0f);
outData[i].fv4Pos = mul(fv4Corner, g_matWVP);
outData[i].fv4Color = g_fv4Color[i];
SpriteStream.Append(outData[i]);
}
SpriteStream.RestartStrip();
}

float4 PS_Proc(PS_Input inData) : SV_TARGET
{
return inData.fv4Color;
}
[/code]


Share this post


Link to post
Share on other sites
[quote name='n3Xus' timestamp='1302801364' post='4798472']
Many things can go wrong, your best option is to debug your application with PIX.
[/quote]


thanks.

I tried,but not output to PIX on the application with d3d11.

while i use only vertex shader and pixel shader,the execution toward an anticipated end.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this