diff --git a/DX11Starter.vcxproj b/DX11Starter.vcxproj index a2e915d..9287f20 100644 --- a/DX11Starter.vcxproj +++ b/DX11Starter.vcxproj @@ -140,6 +140,7 @@ + diff --git a/DX11Starter.vcxproj.filters b/DX11Starter.vcxproj.filters index da4fb1a..7b1f5b3 100644 --- a/DX11Starter.vcxproj.filters +++ b/DX11Starter.vcxproj.filters @@ -86,6 +86,9 @@ Header Files + + Header Files + diff --git a/Game.cpp b/Game.cpp index 9ecca3a..e569536 100644 --- a/Game.cpp +++ b/Game.cpp @@ -60,6 +60,7 @@ void Game::Init() // geometry to draw and some simple camera matrices. // - You'll be expanding and/or replacing these later LoadShaders(); + LoadLighting(); CreateBasicGeometry(); // Tell the input assembler stage of the pipeline what kind of @@ -95,6 +96,15 @@ void Game::LoadShaders() }; } +void Game::LoadLighting() +{ + directionalLight1 = {}; + directionalLight1.Type = LIGHT_TYPE_DIRECTIONAL; + directionalLight1.Direction = XMFLOAT3(1, -1, 0); + directionalLight1.Color = XMFLOAT3(0.2f, 0.2f, 1.0f); + directionalLight1.Intensity = 1.0f; +} + // -------------------------------------------------------- // Creates the geometry we're going to draw - a single triangle for now // -------------------------------------------------------- @@ -205,6 +215,7 @@ void Game::Draw(float deltaTime, float totalTime) ps->SetFloat3("cameraPosition", camera->GetTransform()->GetPosition()); ps->SetFloat("roughness", entity->GetMaterial()->GetRoughness()); ps->SetFloat3("ambient", ambient); + ps->SetData("directionalLight1", &directionalLight1, sizeof(Light)); ps->CopyAllBufferData(); entity->GetMaterial()->GetVertexShader()->SetShader(); diff --git a/Game.h b/Game.h index 1ca6c20..5c5b510 100644 --- a/Game.h +++ b/Game.h @@ -6,6 +6,7 @@ #include "Entity.h" #include "SimpleShader.h" #include "Material.h" +#include "Lights.h" #include #include // Used for ComPtr - a smart pointer for COM objects #include @@ -33,6 +34,7 @@ private: // Initialization helper methods - feel free to customize, combine, etc. void LoadShaders(); + void LoadLighting(); void CreateBasicGeometry(); // Note the usage of ComPtr below @@ -52,6 +54,8 @@ private: std::shared_ptr camera; // A6 Materials std::vector> materials; + // A7 Lights + Light directionalLight1; Microsoft::WRL::ComPtr constantBufferVS; }; diff --git a/Lights.h b/Lights.h new file mode 100644 index 0000000..b3085ed --- /dev/null +++ b/Lights.h @@ -0,0 +1,17 @@ +#pragma once +#define LIGHT_TYPE_DIRECTIONAL 0 +#define LIGHT_TYPE_POINT 1 +#define LIGHT_TYPE_SPOT 2 +#include + +struct Light +{ + int Type; + DirectX::XMFLOAT3 Direction; + float Range; + DirectX::XMFLOAT3 Position; + float Intensity; + DirectX::XMFLOAT3 Color; + float SpotFalloff; + DirectX::XMFLOAT3 Padding; +};