Commit ffb174ec authored by chili's avatar chili
Browse files

multiple slots

parent dac6adaf
......@@ -25,9 +25,10 @@ App::App()
{}
std::unique_ptr<Drawable> operator()()
{
const DirectX::XMFLOAT3 mat = { cdist( rng ),cdist( rng ),cdist( rng ) };
return std::make_unique<Box>(
gfx,rng,adist,ddist,
odist,rdist,bdist
odist,rdist,bdist,mat
);
}
private:
......@@ -38,6 +39,7 @@ App::App()
std::uniform_real_distribution<float> odist{ 0.0f,PI * 0.08f };
std::uniform_real_distribution<float> rdist{ 6.0f,20.0f };
std::uniform_real_distribution<float> bdist{ 0.4f,3.0f };
std::uniform_real_distribution<float> cdist{ 0.0f,1.0f };
};
drawables.reserve( nDrawables );
......
......@@ -10,7 +10,8 @@ Box::Box( Graphics& gfx,
std::uniform_real_distribution<float>& ddist,
std::uniform_real_distribution<float>& odist,
std::uniform_real_distribution<float>& rdist,
std::uniform_real_distribution<float>& bdist )
std::uniform_real_distribution<float>& bdist,
DirectX::XMFLOAT3 material )
:
r( rdist( rng ) ),
droll( ddist( rng ) ),
......@@ -61,6 +62,14 @@ Box::Box( Graphics& gfx,
AddBind( std::make_unique<TransformCbuf>( gfx,*this ) );
struct PSMaterialConstant
{
dx::XMFLOAT3 color;
float padding;
} colorConst;
colorConst.color = material;
AddBind( std::make_unique<PixelConstantBuffer<PSMaterialConstant>>( gfx,colorConst,1u ) );
// model deformation transform (per instance, not stored as bind)
dx::XMStoreFloat3x3(
&mt,
......
......@@ -9,7 +9,8 @@ public:
std::uniform_real_distribution<float>& ddist,
std::uniform_real_distribution<float>& odist,
std::uniform_real_distribution<float>& rdist,
std::uniform_real_distribution<float>& bdist );
std::uniform_real_distribution<float>& bdist,
DirectX::XMFLOAT3 material );
void Update( float dt ) noexcept override;
DirectX::XMMATRIX GetTransformXM() const noexcept override;
private:
......
......@@ -19,7 +19,9 @@ public:
memcpy( msr.pData,&consts,sizeof( consts ) );
GetContext( gfx )->Unmap( pConstantBuffer.Get(),0u );
}
ConstantBuffer( Graphics& gfx,const C& consts )
ConstantBuffer( Graphics& gfx,const C& consts,UINT slot = 0u )
:
slot( slot )
{
INFOMAN( gfx );
......@@ -35,7 +37,9 @@ public:
csd.pSysMem = &consts;
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &cbd,&csd,&pConstantBuffer ) );
}
ConstantBuffer( Graphics& gfx )
ConstantBuffer( Graphics& gfx,UINT slot = 0u )
:
slot( slot )
{
INFOMAN( gfx );
......@@ -50,18 +54,20 @@ public:
}
protected:
Microsoft::WRL::ComPtr<ID3D11Buffer> pConstantBuffer;
UINT slot;
};
template<typename C>
class VertexConstantBuffer : public ConstantBuffer<C>
{
using ConstantBuffer<C>::pConstantBuffer;
using ConstantBuffer<C>::slot;
using Bindable::GetContext;
public:
using ConstantBuffer<C>::ConstantBuffer;
void Bind( Graphics& gfx ) noexcept override
{
GetContext( gfx )->VSSetConstantBuffers( 0u,1u,pConstantBuffer.GetAddressOf() );
GetContext( gfx )->VSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() );
}
};
......@@ -69,11 +75,12 @@ template<typename C>
class PixelConstantBuffer : public ConstantBuffer<C>
{
using ConstantBuffer<C>::pConstantBuffer;
using ConstantBuffer<C>::slot;
using Bindable::GetContext;
public:
using ConstantBuffer<C>::ConstantBuffer;
void Bind( Graphics& gfx ) noexcept override
{
GetContext( gfx )->PSSetConstantBuffers( 0u,1u,pConstantBuffer.GetAddressOf() );
GetContext( gfx )->PSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() );
}
};
\ No newline at end of file
cbuffer LightCBuf
{
float3 lightPos;
float3 materialColor;
float3 ambient;
float3 diffuseColor;
float diffuseIntensity;
......@@ -10,6 +9,11 @@ cbuffer LightCBuf
float attQuad;
};
cbuffer ObjectCBuf
{
float3 materialColor;
};
float4 main( float3 worldPos : Position,float3 n : Normal ) : SV_Target
{
......
......@@ -22,7 +22,6 @@ void PointLight::SpawnControlWindow() noexcept
ImGui::SliderFloat( "Intensity",&cbData.diffuseIntensity,0.01f,2.0f,"%.2f",2 );
ImGui::ColorEdit3( "Diffuse Color",&cbData.diffuseColor.x );
ImGui::ColorEdit3( "Ambient",&cbData.ambient.x );
ImGui::ColorEdit3( "Material",&cbData.materialColor.x );
ImGui::Text( "Falloff" );
ImGui::SliderFloat( "Constant",&cbData.attConst,0.05f,10.0f,"%.2f",4 );
......@@ -41,7 +40,6 @@ void PointLight::Reset() noexcept
{
cbData = {
{ 0.0f,0.0f,0.0f },
{ 0.7f,0.7f,0.9f },
{ 0.05f,0.05f,0.05f },
{ 1.0f,1.0f,1.0f },
1.0f,
......
......@@ -15,7 +15,6 @@ private:
struct PointLightCBuf
{
alignas(16) DirectX::XMFLOAT3 pos;
alignas(16) DirectX::XMFLOAT3 materialColor;
alignas(16) DirectX::XMFLOAT3 ambient;
alignas(16) DirectX::XMFLOAT3 diffuseColor;
float diffuseIntensity;
......
#include "TransformCbuf.h"
TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent )
TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot )
:
parent( parent )
{
if( !pVcbuf )
{
pVcbuf = std::make_unique<VertexConstantBuffer<Transforms>>( gfx );
pVcbuf = std::make_unique<VertexConstantBuffer<Transforms>>( gfx,slot );
}
}
......
......@@ -12,7 +12,7 @@ private:
DirectX::XMMATRIX model;
};
public:
TransformCbuf( Graphics& gfx,const Drawable& parent );
TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot = 0u );
void Bind( Graphics& gfx ) noexcept override;
private:
static std::unique_ptr<VertexConstantBuffer<Transforms>> pVcbuf;
......
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