Commit ffb174ec authored by chili's avatar chili
Browse files

multiple slots

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