I have a lightstruct in C++ which holds the color and direction of the light.
const int NUM_LIGHTS = 1;
struct lightStruct {
XMFLOAT4 Color;
XMFLOAT4 Direction;
};
And this is how I create my buffer and update it.
void PBRMaterial::CreateLightBuffer(ID3D11Device* device, ID3D11Buffer** lightBuffer, std::vector<lightStruct*> lightStructs){
D3D11_BUFFER_DESC cbDesc;
cbDesc.ByteWidth = sizeof(lightStruct) * NUM_LIGHTS;
cbDesc.Usage = D3D11_USAGE_DYNAMIC;
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
cbDesc.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = &lightStructs[0];
InitData.SysMemPitch = 0;
InitData.SysMemSlicePitch = 0;
if (FAILED(device->CreateBuffer(&cbDesc, &InitData, lightBuffer)))
{
throw GameException("ID3D11Device::CreateLightBuffer() failed.");
}
}
void PBRMaterial::SetLightBuffer(ID3D11DeviceContext* deviceContext, ID3D11Buffer** lightBuffer){
deviceContext->VSSetConstantBuffers(0, 1, lightBuffer);
}
On the shader side I declare my variables as such:
#define NUM_LIGHTS 1
struct DIRECTIONAL_LIGHT_DATA {
float4 Color;
float4 Direction;
};
cbuffer cbDirectionalLight : register(b0)
{
DIRECTIONAL_LIGHT_DATA directionalLights[NUM_LIGHTS];
};
Now, I don't get any errors but my shader only outputs black. I have been stuck on this for two days now and I can't come up with a solution. For debug purposes I also tried outputting the light's color directly like this:
OUT.rgb = directionalLights[0].Color.rgb;// ambient + diffuse + specular;
OUT.a = 1;
But that also just shows up black. Anyone have a thought on what the issue might be? Thanks!