Commit 28c8da49 authored by AL's avatar AL

pipeline can now handle 'any' number of lights

parent f6a59251
......@@ -6,18 +6,18 @@ PointLight::PointLight( DXGraphics& gfx, PointLightCBuf& pcbData, PointLightPosB
pcbData(pcbData),
pposcdData(pposcdData),
cbuf( gfx ),
poscbuf(gfx)
poscbuf(gfx,5)
{}
void PointLight::UpdatePosition(DXGraphics& gfx, DirectX::FXMMATRIX view)
{
auto dataCopy = pposcdData;
for (size_t i = 0u; i < NUM_OF_LIGHTS; i++)
{
auto dataCopy = pposcdData;
const auto pos = DirectX::XMLoadFloat3(dataCopy.pos);
DirectX::XMStoreFloat3(dataCopy.pos, DirectX::XMVector3Transform(pos, view));
poscbuf.Update(gfx, dataCopy);
const auto pos = DirectX::XMLoadFloat4(&dataCopy.pos[i]);
DirectX::XMStoreFloat4(&dataCopy.pos[i], DirectX::XMVector3Transform(pos, view));
}
poscbuf.Update(gfx, dataCopy);
}
void PointLight::Bind( DXGraphics& gfx) const noexcept
......
......@@ -25,7 +25,7 @@ struct PointLightCBuf
};
struct alignas(16) PointLightPosBuffer
{
alignas(16) DirectX::XMFLOAT3 pos[NUM_OF_LIGHTS];
alignas(16) DirectX::XMFLOAT4 pos[NUM_OF_LIGHTS]; //also oversized
};
class PointLight
......
......@@ -127,7 +127,7 @@ int Game::Go()
td.SubmitText(dt);
fc.Execute(wnd.DXGfx(),dt);
/*if (!wnd.CursorEnabled())
if (!wnd.CursorEnabled())
{
if (wnd.kbd.KeyIsPressed('W'))
{
......@@ -153,7 +153,7 @@ int Game::Go()
{
cam.Translate({ 0.0f,-dt,0.0f });
}
}*/
}
while (const auto delta = wnd.mouse.ReadRawDelta())
{
......
......@@ -40,8 +40,11 @@ private:
void UpdateModel();
private:
const DirectX::XMFLOAT3 xm{ 3.3f, 1.5f, -0.8f };
PointLightPosBuffer p{ xm,xm,xm,xm };
const DirectX::XMFLOAT4 xm0{ 3.3f, 1.5f, -0.8f,0.0f };
const DirectX::XMFLOAT4 xm1{ 2.5f, 1.5f, -0.8f,0.0f };
const DirectX::XMFLOAT4 xm2{ 5.7f, 1.5f, -0.8f,0.0f };
const DirectX::XMFLOAT4 xm3{ 4.7f, 1.5f, -0.8f,0.0f };
PointLightPosBuffer p{ xm0,xm1,xm2,xm3 };
const DirectX::XMFLOAT4 amb{ 0.4f,0.26f,0.2f,0.0f };
const DirectX::XMFLOAT4 dif{ 0.98f,0.4f,0.01f,0.0f };
......
......@@ -7,7 +7,7 @@ struct LightVectorData
float distToL;
};
cbuffer PointLightPosition
cbuffer PointLightPosition : register(b5)
{
float3 viewLightPos[NUM_OF_LIGHTS];
};
......
......@@ -45,5 +45,5 @@ float4 main(float3 viewFragPos : Position, float3 viewNormal : Normal, float3 vi
);
}
// final color
return float4(saturate((diffuse + 8) * dtex.rgb + specular), dtex.a);
return float4(saturate((diffuse + ambient[0]) * dtex.rgb + specular), dtex.a);
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment