so im currently on tutorial 6 of the dx sdk (lightning), and im trying to adapt it to my little framework. problem is it seems that the constant buffer only updates a few variables (at least the world matrix) but doesnt update others. the problem is such that i've removed any lightning and i only want to output a solid color, and it still doesnt work. when i hard-code the color on the pixel shader it works, when i try to use a color from the constant buffer it doesnt work..
its even more weird because all my attempts at the previous tutorials worked just fine, even passing a color through the constant buffer worked fine.. but im tired of going through all my code and i cant seem to find anything wrong but it still outputs black (like the constant buffer color is == 0.0f).
ill try to post every relevant code
relevant structs:
// the normal vertex im using
struct NormalVertex
{
XMFLOAT3 Pos;
XMFLOAT3 Normal;
};
//my constant buffer:
struct ConstantBuffer
{
XMMATRIX World;
XMMATRIX View;
XMMATRIX Projection;
XMFLOAT4 lightDir[2];
XMFLOAT4 lightCol[2];
XMFLOAT4 outputColor;
};
at the setup of my cube i create the constant buffer with an empty ConstantBuffer struct:
//create constant buffer:
array <ConstantBuffer, 1> tmpCB = { ConstantBuffer() };
inst.CreateBuffer(D3DEngine::Constant, tmpCB, &constantBuffer);
//the CreateBuffer method:
template <typename T, size_t Size>
void CreateBuffer(BufferType bufferType, const std::array <T, Size>& source, ID3D11Buffer** bufferOut)
{
HRESULT hr = S_OK;
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(T) * source.size();
bd.BindFlags = bufferType;
bd.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA initData;
ZeroMemory(&initData, sizeof(initData));
initData.pSysMem = source.data();
hr = device->CreateBuffer(&bd, &initData, bufferOut);
if(FAILED(hr))
throw std::exception("ID3D11Device::CreateBuffer() -> Failed.");
}
and this worked just fine when i tried a simple 2d triangle
and my render function for the cube:
ConstantBuffer cb;
cb.world = world;
cb.view = view;
cb.projection = projection;
cb.outputColor = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
inst.UpdateBuffer(constantBuffer, cb);
inst.DrawRenderData(36); //36 vertices
//the update buffer method:
template <typename T>
void UpdateBuffer(ID3D11Buffer* buffer, const T& source)
{
deviceContext->UpdateSubresource(buffer, 0, nullptr, &source, 0, 0);
}
i set all the buffers and shaders and etc to the deviceContext at the cube setup.
now my shader:
cbuffer ConstantBuffer : register(b0)
{
matrix World;
matrix View;
matrix Projection;
float4 lightDir[2];
float4 lightCol[2];
float4 outputColor;
};
struct VS_INPUT
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float3 Normal : NORMAL;
};
PS_INPUT VS(VS_INPUT input)
{
PS_INPUT output = (PS_INPUT)0;
output.Pos = mul(input.Pos, World);
output.Pos = mul(output.Pos, View);
output.Pos = mul(output.Pos, Projection);
output.Normal = mul(input.Normal, World);
return output;
}
float4 PS(PS_INPUT input) : SV_TARGET
{
return outputColor;
}
i KNOW it updates a few constantbuffer variables because i can rotate the cube, so at least the world matrix is being updated but it draws the cube black..
if on the pixel shader i do: return float4(1.0f, 0.0f, 0.0f, 1.0f); it works!
this is driving me mad, if anyone can throw a tip ill really appreciate it.
thanks.