Some possible things that might be the issue and could be explained by someone who is knowledgeable
- Order of my indices, In all I've read, your array of indices for a triangle list is just clockwise order, see below how I ordered it for proof.
- Keep in mind that my code runs fine, no errors, no warnings(that I know of) related to my issue.
I have been banging my head over this issue for far too long. I know the answer is going to be ridiculously simple but somehow it has successfully evaded me.
I've been implementing deferred rendering into my engine and my second pass, the one that actually renders to the swap chain buffer, is staying black (or whatever color I clear it to before rendering).
Now I know the issue has nothing to do with anything associated with the first pass/gBuffer because I am completely bypassing that part, literally commented out the call to it in the game loop.
My 2nd Pass Deferred Vertex Shader is as follows...
float4 main( float4 pos : POSITION ) : SV_POSITION
{
return pos;
}
My 2nd Pass Pixel Shader is as follows... I have omitted the actual lighting code because it is all commented out until I fix the issue.
float4 main(in float4 screenPos : SV_Position) : SV_Target
{
return float4(1.0f,1.0f,1.0f, 1.0f);
}
As you can see I am not doing anything related to lighting or anything, all I'm trying to do is set every pixel to white, I want to see it work.
Here is my renderSecondPass function. this is what I call every frame. Irrelevant code has been omitted.
void DirectX::renderSecondPass()
{
nullShaders();
d3d11DeviceContext->VSSetShader(deferredVertexShader, NULL, 0);
d3d11DeviceContext->PSSetShader(deferredPixelShader, NULL, 0);
HRESULT hr;
float clear[] = { 1.0, 0.5, 0.0, 1.0 };
d3d11DeviceContext->OMSetRenderTargets(1, &d3d11RenderTargetView, NULL);
d3d11DeviceContext->ClearRenderTargetView(d3d11RenderTargetView, clear);
d3d11DeviceContext->IASetInputLayout(InputLayout::Deferred);
d3d11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
for (unsigned int i = 0; i < lightBuffer.size(); i++)
{
UINT stride = sizeof(Vertex::Deferred);
UINT offset = 0;
d3d11DeviceContext->IASetVertexBuffers(0, 1, &deferredQuadVB, &stride, &offset);
d3d11DeviceContext->IASetIndexBuffer(deferredQuadIB, DXGI_FORMAT_R32_UINT, 0);
d3d11DeviceContext->DrawIndexed(deferredQuadIndiceCount, 0, 0);
}
hr = swapChain->Present(0, 0);
if (FAILED(hr))
{
MessageBox(0, L"Swap Chain Present Error.", 0, 0);
}
}
Here is the Input Layout...
namespace Vertex
{
struct Deferred
{
VECTOR<float> Position;
float Position_W;
};
}
// C++ side above
// Shaderside below
namespace InputLayout
{
static ID3D11InputLayout* Deferred;
}
const D3D11_INPUT_ELEMENT_DESC InputLayoutDesc::DEFERRED_VS_INPUTLAYOUT_DESC[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
Creation of the Input Layouts and Loading of the shaders themselves from file. Irrelevant code has been omitted.
bool DirectX::initShaders()
{
std::vector<char> shaderBuffer;
std::string filename;
HRESULT hr;
// deferredVS
filename = "Shaders\\deferredVS.cso";
if (!shaderFileToMemory(filename, shaderBuffer))
{
MessageBox(0, L"Load defaultVS Shader Into Memory Error.", 0, 0);
return false;
}
hr = d3d11Device->CreateVertexShader(&shaderBuffer[0], shaderBuffer.size(), NULL, &deferredVertexShader);
hr = d3d11Device->CreateInputLayout(InputLayoutDesc::DEFERRED_VS_INPUTLAYOUT_DESC, 1, &shaderBuffer[0], shaderBuffer.size(), &InputLayout::Deferred);
// deferredPS
filename = "Shaders\\deferredPS.cso";
if (!shaderFileToMemory(filename, shaderBuffer))
{
MessageBox(0, L"Load deferredPS Shader Into Memory Error.", 0, 0);
return false;
}
hr = d3d11Device->CreatePixelShader(&shaderBuffer[0], shaderBuffer.size(), NULL, &deferredPixelShader);
return true;
}
The Vertex and Index Buffer were created using the following...
bool DirectX::initDeferredQuad()
{
std::vector<Vertex::Deferred> deferredQuadVertices;
std::vector<unsigned int> deferredQuadIndices;
Vertex::Deferred quadVertices[4];
Vertex::Deferred quadVertice;
quadVertice.Position_W = 1.0;
quadVertice.Position = VECTOR<float>(-1.0, 1.0, 0.0);
quadVertices[0] = quadVertice;
quadVertice.Position = VECTOR<float>(1.0, 1.0, 0.0);
quadVertices[1] = quadVertice;
quadVertice.Position = VECTOR<float>(-1.0, -1.0, 0.0);
quadVertices[2] = quadVertice;
quadVertice.Position = VECTOR<float>(1.0, -1.0, 0.0);
quadVertices[3] = quadVertice;
D3D11_BUFFER_DESC vbd;
D3D11_SUBRESOURCE_DATA vinitData;
HRESULT hr;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex::Deferred) * 4;
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
vbd.StructureByteStride = 0;
vinitData.pSysMem = &quadVertices;
hr = d3d11Device->CreateBuffer(&vbd, &vinitData, &deferredQuadVB);
if (FAILED(hr))
{
MessageBox(0, L"Quad Vertex Buffer Creation Error.", 0, 0);
return false;
}
unsigned int quadIndices[] =
{ 1, 2, 3,
3, 2, 4 };
deferredQuadIndiceCount = 6;
D3D11_BUFFER_DESC ibd;
D3D11_SUBRESOURCE_DATA iinitData;
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof(unsigned int) * 6;
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
iinitData.pSysMem = &deferredQuadIndices;
hr = d3d11Device->CreateBuffer(&ibd, &iinitData, &deferredQuadIB);
if (FAILED(hr))
{
MessageBox(0, L"QuadIndex Buffer Creation Error.", 0, 0);
return false;
}
return true;
}
I thought the issue was here. Since my Vertex Shader is feeding the Rasterizer data directly, the Vertex Shader has to output SV_Position in Clip Space. Wouldn't the coordinates I've made for my vertices be correct for a quad composed of 2 triangles that would take up the entire screen? (I've tried changing the z values, no change)
If anyone needs more info, just ask. Thanks