diff --git a/Game.cpp b/Game.cpp index 04b19dd..98257ac 100644 --- a/Game.cpp +++ b/Game.cpp @@ -74,14 +74,20 @@ void Game::LoadShadersAndMaterials() { vertexShader = std::make_shared(device, context, GetFullPathTo_Wide(L"VertexShader.cso").c_str()); pixelShader = std::make_shared(device, context, GetFullPathTo_Wide(L"SimplePixelShader.cso").c_str()); + vertexShaderPBR = std::make_shared(device, context, GetFullPathTo_Wide(L"SimpleVertexPBR.cso").c_str()); + pixelShaderPBR = std::make_shared(device, context, GetFullPathTo_Wide(L"SimplePixelPBR.cso").c_str()); XMFLOAT3 white = XMFLOAT3(1.0f, 1.0f, 1.0f); materials = { - std::make_shared(white, 0, vertexShader, pixelShader), - std::make_shared(white, 0, vertexShader, pixelShader), - std::make_shared(white, 0, vertexShader, pixelShader), - std::make_shared(white, 0, vertexShader, pixelShader), + std::make_shared(false, white, 0, vertexShader, pixelShader), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), + std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), }; } @@ -118,25 +124,46 @@ void Game::LoadTextures() materials[0]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_emissive.png", TEXTYPE_EMISSIVE, device.Get(), context.Get()); materials[1]->PushSampler("BasicSampler", sampler); - materials[1]->PushTexture(TEXTYPE_REFLECTION, demoCubemap); - materials[1]->hasReflectionMap = true; - materials[1]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); - materials[1]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); - materials[1]->LoadTexture(L"Assets/Textures/WithNormals/cobblestone_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/PBR/bronze_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/PBR/bronze_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/PBR/bronze_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/PBR/bronze_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); materials[2]->PushSampler("BasicSampler", sampler); - materials[2]->PushTexture(TEXTYPE_REFLECTION, demoCubemap); - materials[2]->hasReflectionMap = true; - materials[2]->LoadTexture(L"Assets/Textures/WithNormals/rock.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); - materials[2]->LoadTexture(L"Assets/Textures/WithNormals/rock_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); - materials[2]->LoadTexture(L"Assets/Textures/WithNormals/rock_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + materials[2]->LoadTexture(L"Assets/Textures/PBR/cobblestone_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[2]->LoadTexture(L"Assets/Textures/PBR/cobblestone_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[2]->LoadTexture(L"Assets/Textures/PBR/cobblestone_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[2]->LoadTexture(L"Assets/Textures/PBR/cobblestone_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); materials[3]->PushSampler("BasicSampler", sampler); - materials[3]->PushTexture(TEXTYPE_REFLECTION, demoCubemap); - materials[3]->hasReflectionMap = true; - materials[3]->LoadTexture(L"Assets/Textures/WithNormals/cushion.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); - materials[3]->LoadTexture(L"Assets/Textures/WithNormals/cushion_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); - materials[3]->LoadTexture(L"Assets/Textures/WithNormals/cushion_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + materials[3]->LoadTexture(L"Assets/Textures/PBR/floor_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[3]->LoadTexture(L"Assets/Textures/PBR/floor_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[3]->LoadTexture(L"Assets/Textures/PBR/floor_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[3]->LoadTexture(L"Assets/Textures/PBR/floor_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + + materials[4]->PushSampler("BasicSampler", sampler); + materials[4]->LoadTexture(L"Assets/Textures/PBR/paint_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[4]->LoadTexture(L"Assets/Textures/PBR/paint_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[4]->LoadTexture(L"Assets/Textures/PBR/paint_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[4]->LoadTexture(L"Assets/Textures/PBR/paint_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + + materials[5]->PushSampler("BasicSampler", sampler); + materials[5]->LoadTexture(L"Assets/Textures/PBR/rough_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[5]->LoadTexture(L"Assets/Textures/PBR/rough_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[5]->LoadTexture(L"Assets/Textures/PBR/rough_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[5]->LoadTexture(L"Assets/Textures/PBR/rough_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + + materials[6]->PushSampler("BasicSampler", sampler); + materials[6]->LoadTexture(L"Assets/Textures/PBR/scratched_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[6]->LoadTexture(L"Assets/Textures/PBR/scratched_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[6]->LoadTexture(L"Assets/Textures/PBR/scratched_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[6]->LoadTexture(L"Assets/Textures/PBR/scratched_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); + + materials[7]->PushSampler("BasicSampler", sampler); + materials[7]->LoadTexture(L"Assets/Textures/PBR/wood_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[7]->LoadTexture(L"Assets/Textures/PBR/wood_metal.png", TEXTYPE_METALNESS, device.Get(), context.Get()); + materials[7]->LoadTexture(L"Assets/Textures/PBR/wood_roughness.png", TEXTYPE_ROUGHNESS, device.Get(), context.Get()); + materials[7]->LoadTexture(L"Assets/Textures/PBR/wood_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); } // -------------------------------------------------------- @@ -147,13 +174,13 @@ void Game::LoadLighting() ambient = XMFLOAT3(0.1f, 0.1f, 0.15f); lights = { - Light::Directional(XMFLOAT3(1, 0.5f, 0.5f), XMFLOAT3(1, 1, 1), 0.75f), - Light::Directional(XMFLOAT3(-0.25f, -1, 0.75f), XMFLOAT3(1, 1, 1), 0.75f), - Light::Directional(XMFLOAT3(-1, 1, -0.5f), XMFLOAT3(1, 1, 1), 0.75f), - Light::Point(XMFLOAT3(-1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.5f, 10), + Light::Directional(XMFLOAT3(1, 0.5f, 0.5f), XMFLOAT3(1, 1, 1), 2.00f), + Light::Directional(XMFLOAT3(-0.25f, -1, 0.75f), XMFLOAT3(1, 1, 1), 0.25f), + Light::Directional(XMFLOAT3(-1, 1, -0.5f), XMFLOAT3(1, 1, 1), 0.25f), + Light::Point(XMFLOAT3(-1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.25f, 10), Light::Point(XMFLOAT3(1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.25f, 10), Light::Point(XMFLOAT3(0, 2, 0), XMFLOAT3(1, 0, 0), 0.25f, 10), - Light::Point(XMFLOAT3(-27.5f, 0, 0), XMFLOAT3(1, 1, 0.5f), 5, 20), + Light::Point(XMFLOAT3(-27.5f, 0, 0), XMFLOAT3(1, 1, 0.5f), 0.25f, 20), }; } @@ -187,31 +214,29 @@ void Game::CreateBasicGeometry() }; entities = { - std::make_shared(materials[1], shapes[0]), - std::make_shared(materials[2], shapes[1]), - std::make_shared(materials[3], shapes[2]), + std::make_shared(materials[1], shapes[3]), std::make_shared(materials[2], shapes[3]), - std::make_shared(materials[1], shapes[4]), - std::make_shared(materials[0], shapes[5]), - std::make_shared(materials[0], shapes[6]), + std::make_shared(materials[3], shapes[3]), + std::make_shared(materials[4], shapes[3]), + std::make_shared(materials[5], shapes[3]), + std::make_shared(materials[6], shapes[3]), + std::make_shared(materials[7], shapes[3]), + std::make_shared(materials[0], shapes[3]), }; - entities[6]->GetMaterial()->SetEmitAmount(0.75f); - for (int i = 0; i < entities.size(); ++i) { entities[i]->GetTransform()->SetPosition((-(int)(entities.size() / 2) + i) * 5, 0, 0); - entities[i]->GetMaterial()->SetRoughness(0.60f); } skybox = std::make_shared( - shapes[0], - std::make_shared(device, context, GetFullPathTo_Wide(L"SkyboxVertexShader.cso").c_str()), - std::make_shared(device, context, GetFullPathTo_Wide(L"SkyboxPixelShader.cso").c_str()), - demoCubemap, - sampler, - device - ); + shapes[0], + std::make_shared(device, context, GetFullPathTo_Wide(L"SkyboxVertexShader.cso").c_str()), + std::make_shared(device, context, GetFullPathTo_Wide(L"SkyboxPixelShader.cso").c_str()), + demoCubemap, + sampler, + device + ); } diff --git a/Game.h b/Game.h index ceed40c..acac3b8 100644 --- a/Game.h +++ b/Game.h @@ -47,6 +47,8 @@ private: // Shaders and shader-related constructs std::shared_ptr pixelShader; std::shared_ptr vertexShader; + std::shared_ptr pixelShaderPBR; + std::shared_ptr vertexShaderPBR; // A2 shapes std::vector> shapes; diff --git a/Material.cpp b/Material.cpp index 9ca9fbd..1186d06 100644 --- a/Material.cpp +++ b/Material.cpp @@ -1,11 +1,13 @@ #include "Material.h" Material::Material( + bool _pbr, DirectX::XMFLOAT3 _tint, float _roughness, std::shared_ptr _vertexShader, std::shared_ptr _pixelShader) { + pbr = _pbr; tint = _tint; roughness = _roughness; vertexShader = _vertexShader; @@ -25,37 +27,8 @@ Material::~Material() void Material::Activate(Transform* _transform, std::shared_ptr _camera, DirectX::XMFLOAT3 _ambient, std::vector _lights) { - vertexShader->SetMatrix4x4("world", _transform->GetWorldMatrix()); - vertexShader->SetMatrix4x4("worldInvTranspose", _transform->GetWorldMatrixInverseTranspose()); - vertexShader->SetMatrix4x4("view", _camera->GetViewMatrix()); - vertexShader->SetMatrix4x4("projection", _camera->GetProjectionMatrix()); - vertexShader->CopyAllBufferData(); - vertexShader->SetShader(); - - pixelShader->SetFloat3("cameraPosition", _camera->GetTransform()->GetPosition()); - pixelShader->SetFloat("roughness", GetRoughness()); - pixelShader->SetFloat2("scale", GetUVScale()); - pixelShader->SetFloat2("offset", GetUVOffset()); - pixelShader->SetFloat3("ambient", _ambient); - pixelShader->SetFloat("emitAmount", GetEmitAmount()); - pixelShader->SetFloat3("tint", GetTint()); - pixelShader->SetFloat("lightCount", (int)_lights.size()); - pixelShader->SetInt("hasEmissiveMap", (int)hasEmissiveMap); - pixelShader->SetInt("hasSpecularMap", (int)hasSpecularMap); - pixelShader->SetInt("hasNormalMap", (int)hasNormalMap); - pixelShader->SetInt("hasReflectionMap", (int)hasReflectionMap); - pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size()); - pixelShader->CopyAllBufferData(); - pixelShader->SetShader(); - - for (auto& t : textures) - { - pixelShader->SetShaderResourceView(t.first.c_str(), t.second.Get()); - } - for (auto& s : samplers) - { - pixelShader->SetSamplerState(s.first.c_str(), s.second.Get()); - } + if (pbr) ActivatePBR(_transform, _camera, _ambient, _lights); + else ActivateStandard(_transform, _camera, _ambient, _lights); } DirectX::XMFLOAT3 Material::GetTint() @@ -160,3 +133,65 @@ void Material::PushTexture(std::string _name, Microsoft::WRL::ComPtr _camera, DirectX::XMFLOAT3 _ambient, std::vector _lights) +{ + vertexShader->SetMatrix4x4("world", _transform->GetWorldMatrix()); + vertexShader->SetMatrix4x4("worldInvTranspose", _transform->GetWorldMatrixInverseTranspose()); + vertexShader->SetMatrix4x4("view", _camera->GetViewMatrix()); + vertexShader->SetMatrix4x4("projection", _camera->GetProjectionMatrix()); + vertexShader->CopyAllBufferData(); + vertexShader->SetShader(); + + pixelShader->SetFloat3("cameraPosition", _camera->GetTransform()->GetPosition()); + pixelShader->SetFloat("roughness", GetRoughness()); + pixelShader->SetFloat2("scale", GetUVScale()); + pixelShader->SetFloat2("offset", GetUVOffset()); + pixelShader->SetFloat3("ambient", _ambient); + pixelShader->SetFloat("emitAmount", GetEmitAmount()); + pixelShader->SetFloat3("tint", GetTint()); + pixelShader->SetFloat("lightCount", (int)_lights.size()); + pixelShader->SetInt("hasEmissiveMap", (int)hasEmissiveMap); + pixelShader->SetInt("hasSpecularMap", (int)hasSpecularMap); + pixelShader->SetInt("hasNormalMap", (int)hasNormalMap); + pixelShader->SetInt("hasReflectionMap", (int)hasReflectionMap); + pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size()); + pixelShader->CopyAllBufferData(); + pixelShader->SetShader(); + + for (auto& t : textures) + { + pixelShader->SetShaderResourceView(t.first.c_str(), t.second.Get()); + } + for (auto& s : samplers) + { + pixelShader->SetSamplerState(s.first.c_str(), s.second.Get()); + } +} + +void Material::ActivatePBR(Transform* _transform, std::shared_ptr _camera, DirectX::XMFLOAT3 _ambient, std::vector _lights) +{ + vertexShader->SetMatrix4x4("world", _transform->GetWorldMatrix()); + vertexShader->SetMatrix4x4("worldInvTranspose", _transform->GetWorldMatrixInverseTranspose()); + vertexShader->SetMatrix4x4("view", _camera->GetViewMatrix()); + vertexShader->SetMatrix4x4("projection", _camera->GetProjectionMatrix()); + vertexShader->CopyAllBufferData(); + vertexShader->SetShader(); + + pixelShader->SetFloat2("scale", GetUVScale()); + pixelShader->SetFloat2("offset", GetUVOffset()); + pixelShader->SetFloat3("cameraPosition", _camera->GetTransform()->GetPosition()); + pixelShader->SetFloat("lightCount", (int)_lights.size()); + pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size()); + pixelShader->CopyAllBufferData(); + pixelShader->SetShader(); + + for (auto& t : textures) + { + pixelShader->SetShaderResourceView(t.first.c_str(), t.second.Get()); + } + for (auto& s : samplers) + { + pixelShader->SetSamplerState(s.first.c_str(), s.second.Get()); + } +} diff --git a/Material.h b/Material.h index 3375880..9f1d5bd 100644 --- a/Material.h +++ b/Material.h @@ -2,6 +2,7 @@ #include #include +#include #include "DXCore.h" #include "SimpleShader.h" #include "Transform.h" @@ -14,11 +15,14 @@ constexpr auto TEXTYPE_NORMAL = "Normal"; constexpr auto TEXTYPE_EMISSIVE = "Emissive"; constexpr auto TEXTYPE_SPECULAR = "Specular"; constexpr auto TEXTYPE_REFLECTION = "Reflection"; +constexpr auto TEXTYPE_ROUGHNESS = "Roughness"; +constexpr auto TEXTYPE_METALNESS = "Metalness"; class Material { public: Material( + bool _pbr, DirectX::XMFLOAT3 _tint, float _roughness, std::shared_ptr _vertexShader, @@ -56,6 +60,18 @@ public: bool hasNormalMap; bool hasReflectionMap; private: + void ActivateStandard( + Transform* _transform, + std::shared_ptr _camera, + DirectX::XMFLOAT3 _ambient, + std::vector _lights); + void ActivatePBR( + Transform* _transform, + std::shared_ptr _camera, + DirectX::XMFLOAT3 _ambient, + std::vector _lights); + + bool pbr; DirectX::XMFLOAT3 tint; float roughness; float emitAmount;