diff --git a/Entity.cpp b/Entity.cpp index 22e38d2..45a022e 100644 --- a/Entity.cpp +++ b/Entity.cpp @@ -16,6 +16,8 @@ eg3d::Entity::Entity(const Entity& other): Geometry(other.device) } void eg3d::Entity::loadDefaults() { + mConstBuf.color = { 1.0f, 1.0f, 1.0f, 1.0f }; + XMStoreFloat4x4(&mConstBuf.worldMatrix, XMMatrixIdentity()); // egységmátrix betöltése a világ-mátrixba mSRTProps.loadDefaults(); constructWorldMatrix(); @@ -54,7 +56,7 @@ void eg3d::Entity::constructWorldMatrix() { XMStoreFloat4x4(&mConstBuf.worldMatrix, w); // konstansbuffer felmásolása a videokártyára - bufferMapCopy(mConstBufRes, static_cast(&mConstBuf), sizeof(CB_Entity)); + updateConstantBuffer(); } void eg3d::Entity::createConstantBuffer() @@ -62,6 +64,16 @@ void eg3d::Entity::createConstantBuffer() mConstBufRes = createBuffer_UH(device, calc256AlignedSize(sizeof(CB_Entity))); } +void eg3d::Entity::updateConstantBuffer() +{ + bufferMapCopy(mConstBufRes, static_cast(&mConstBuf), sizeof(CB_Entity)); +} + +void eg3d::Entity::setColor(float r, float g, float b) +{ + mConstBuf.color = { r, g, b, 1.0f }; + updateConstantBuffer(); +} // ---------------------- diff --git a/Entity.h b/Entity.h index 8d0aa6b..b2d617c 100644 --- a/Entity.h +++ b/Entity.h @@ -31,6 +31,7 @@ namespace eg3d { // TODO konstansbuffer létrehozása, feltöltése void createConstantBuffer(); // konstansbuffer létrehozása + void updateConstantBuffer(); // konstansbuffer frissítése public: Entity(const ComPtr &device); explicit Entity(const Entity& other); // másolókonstruktor @@ -41,6 +42,8 @@ namespace eg3d { SRTProps getEntitySRT() const; // SRT-tualjdonságok elkérése void draw(ComPtr commandList) const override; + + void setColor(float r, float g, float b); // szín beállítása }; } diff --git a/RUNTIME/shaders/basic_shader.hlsl b/RUNTIME/shaders/basic_shader.hlsl index e2171d0..88410b3 100644 --- a/RUNTIME/shaders/basic_shader.hlsl +++ b/RUNTIME/shaders/basic_shader.hlsl @@ -19,6 +19,7 @@ cbuffer CFrame : register(b0) cbuffer CEntity : register(b1) { float4x4 worldMatrix; + float4 color; } VSOutput vs_main(VSInput input) @@ -26,7 +27,7 @@ VSOutput vs_main(VSInput input) VSOutput output; // vertex shader kimenete output.position_H = mul(float4(input.position_D, 1.0), mul(worldMatrix, mul(viewMatrix, projMatrix))); - output.color = float3(1.0, 1.0, 1.0); + output.color = color; return output; } diff --git a/const_bufs.h b/const_bufs.h index ab5fe6b..376b2ed 100644 --- a/const_bufs.h +++ b/const_bufs.h @@ -18,6 +18,7 @@ struct CB_Frame struct CB_Entity { DirectX::XMFLOAT4X4 worldMatrix; // világ-mátrix (modell-mátrix) + DirectX::XMFLOAT4 color; // szín }; #endif //CONST_BUFS diff --git a/main.cpp b/main.cpp index 1b13491..265825d 100644 --- a/main.cpp +++ b/main.cpp @@ -83,6 +83,8 @@ void mouseCB(EventHandlerCBData * pCBData) pTeapot->loadBinarySTL("assets/utahteapot.stl", ImportAdapters::IAD_SwapYZ_RH); pTeapot->setEntitySRT(srtProps); + pTeapot->setColor(0.8f, 0.8f, 0.1f); + gDrawables.push_back(pTeapot); }