cleanup Game and Material .cpp
- regions and comments - convert "pbr" to "mode" and have separate Activate for Toon shader
This commit is contained in:
parent
22c946ec1a
commit
520c33b017
3 changed files with 118 additions and 31 deletions
59
Game.cpp
59
Game.cpp
|
@ -83,17 +83,17 @@ void Game::LoadShadersAndMaterials()
|
||||||
XMFLOAT3 deepPurple = XMFLOAT3(0.1f, 0.02f, 0.1f);
|
XMFLOAT3 deepPurple = XMFLOAT3(0.1f, 0.02f, 0.1f);
|
||||||
|
|
||||||
materials = {
|
materials = {
|
||||||
std::make_shared<Material>(false, white, 0, vertexShader, pixelShader),
|
std::make_shared<Material>(MATTYPE_STANDARD, white, 0, vertexShader, pixelShader),
|
||||||
std::make_shared<Material>(true, white, 0, vertexShaderPBR, pixelShaderPBR),
|
std::make_shared<Material>(MATTYPE_PBR, white, 0, vertexShaderPBR, pixelShaderPBR),
|
||||||
std::make_shared<Material>(true, white, 0, vertexShaderPBR, pixelShaderPBR),
|
std::make_shared<Material>(MATTYPE_PBR, white, 0, vertexShaderPBR, pixelShaderPBR),
|
||||||
std::make_shared<Material>(true, white, 0, vertexShaderPBR, pixelShaderPBR),
|
std::make_shared<Material>(MATTYPE_PBR, white, 0, vertexShaderPBR, pixelShaderPBR),
|
||||||
std::make_shared<Material>(true, white, 0, vertexShaderPBR, pixelShaderPBR),
|
std::make_shared<Material>(MATTYPE_PBR, white, 0, vertexShaderPBR, pixelShaderPBR),
|
||||||
std::make_shared<Material>(true, white, 0, vertexShaderPBR, pixelShaderPBR),
|
std::make_shared<Material>(MATTYPE_PBR, white, 0, vertexShaderPBR, pixelShaderPBR),
|
||||||
std::make_shared<Material>(true, white, 0, vertexShaderPBR, pixelShaderPBR),
|
std::make_shared<Material>(MATTYPE_PBR, white, 0, vertexShaderPBR, pixelShaderPBR),
|
||||||
std::make_shared<Material>(true, white, 0, vertexShaderPBR, pixelShaderPBR),
|
std::make_shared<Material>(MATTYPE_PBR, white, 0, vertexShaderPBR, pixelShaderPBR),
|
||||||
std::make_shared<Material>(false, white, 0, vertexShader, pixelShader),
|
std::make_shared<Material>(MATTYPE_STANDARD, white, 0, vertexShader, pixelShader),
|
||||||
std::make_shared<Material>(false, white, 0, vertexShader, pixelShaderToon),
|
std::make_shared<Material>(MATTYPE_TOON, white, 0, vertexShader, pixelShaderToon),
|
||||||
std::make_shared<Material>(false, deepPurple, 0, vertexShader, pixelShaderToon),
|
std::make_shared<Material>(MATTYPE_TOON, deepPurple, 0, vertexShader, pixelShaderToon),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +102,8 @@ void Game::LoadShadersAndMaterials()
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
void Game::LoadTextures()
|
void Game::LoadTextures()
|
||||||
{
|
{
|
||||||
|
#pragma region Sampler Initialization
|
||||||
|
// Sampler description for wrapped texture sampling
|
||||||
D3D11_SAMPLER_DESC sampDesc = {};
|
D3D11_SAMPLER_DESC sampDesc = {};
|
||||||
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
@ -111,6 +113,7 @@ void Game::LoadTextures()
|
||||||
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||||
device->CreateSamplerState(&sampDesc, sampler.GetAddressOf());
|
device->CreateSamplerState(&sampDesc, sampler.GetAddressOf());
|
||||||
|
|
||||||
|
// Blend description for alpha support
|
||||||
D3D11_BLEND_DESC blendDesc = {};
|
D3D11_BLEND_DESC blendDesc = {};
|
||||||
blendDesc.RenderTarget[0].BlendEnable = true;
|
blendDesc.RenderTarget[0].BlendEnable = true;
|
||||||
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||||
|
@ -121,17 +124,22 @@ void Game::LoadTextures()
|
||||||
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||||
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||||
device->CreateBlendState(&blendDesc, alphaBlendState.GetAddressOf());
|
device->CreateBlendState(&blendDesc, alphaBlendState.GetAddressOf());
|
||||||
|
|
||||||
|
// Rasterizer description for alpha support/rendering backfaces only
|
||||||
D3D11_RASTERIZER_DESC rastDesc = {};
|
D3D11_RASTERIZER_DESC rastDesc = {};
|
||||||
rastDesc.DepthClipEnable = true;
|
rastDesc.DepthClipEnable = true;
|
||||||
rastDesc.CullMode = D3D11_CULL_FRONT;
|
rastDesc.CullMode = D3D11_CULL_FRONT;
|
||||||
rastDesc.FillMode = D3D11_FILL_SOLID;
|
rastDesc.FillMode = D3D11_FILL_SOLID;
|
||||||
device->CreateRasterizerState(&rastDesc, backfaceRasterState.GetAddressOf());
|
device->CreateRasterizerState(&rastDesc, backfaceRasterState.GetAddressOf());
|
||||||
|
|
||||||
|
// Sampler description for clamping
|
||||||
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
device->CreateSamplerState(&sampDesc, clampSampler.GetAddressOf());
|
device->CreateSamplerState(&sampDesc, clampSampler.GetAddressOf());
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
// Initialize skybox
|
||||||
demoCubemap = CreateCubemap(
|
demoCubemap = CreateCubemap(
|
||||||
device,
|
device,
|
||||||
context,
|
context,
|
||||||
|
@ -143,6 +151,7 @@ void Game::LoadTextures()
|
||||||
L"Assets/Textures/Skies/planets/back.png"
|
L"Assets/Textures/Skies/planets/back.png"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#pragma region Material Setup
|
||||||
materials[0]->PushSampler("BasicSampler", sampler);
|
materials[0]->PushSampler("BasicSampler", sampler);
|
||||||
materials[0]->PushTexture(TEXTYPE_REFLECTION, demoCubemap);
|
materials[0]->PushTexture(TEXTYPE_REFLECTION, demoCubemap);
|
||||||
materials[0]->hasReflectionMap = true;
|
materials[0]->hasReflectionMap = true;
|
||||||
|
@ -221,6 +230,7 @@ void Game::LoadTextures()
|
||||||
materials[10]->LoadTexture(L"Assets/Textures/Ramps/toonRampSpecular.png", TEXTYPE_RAMPSPECULAR, device.Get(), context.Get());
|
materials[10]->LoadTexture(L"Assets/Textures/Ramps/toonRampSpecular.png", TEXTYPE_RAMPSPECULAR, device.Get(), context.Get());
|
||||||
materials[10]->SetRimCutoff(0.15f);
|
materials[10]->SetRimCutoff(0.15f);
|
||||||
materials[10]->SetEmitAmount(XMFLOAT3(0.05f, 0.1f, 0.01f));
|
materials[10]->SetEmitAmount(XMFLOAT3(0.05f, 0.1f, 0.01f));
|
||||||
|
#pragma endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
@ -232,6 +242,8 @@ void Game::LoadLighting()
|
||||||
|
|
||||||
lights = {
|
lights = {
|
||||||
Light::Directional(XMFLOAT3(1, 0.5f, -0.5f), XMFLOAT3(1, 1, 1), 1.0f),
|
Light::Directional(XMFLOAT3(1, 0.5f, -0.5f), XMFLOAT3(1, 1, 1), 1.0f),
|
||||||
|
|
||||||
|
// extra lights for testing
|
||||||
//Light::Directional(XMFLOAT3(-0.25f, -1, 0.75f), XMFLOAT3(1, 1, 1), 0.25f),
|
//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::Directional(XMFLOAT3(-1, 1, -0.5f), XMFLOAT3(1, 1, 1), 0.25f),
|
||||||
//Light::Point(XMFLOAT3(-1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.35f, 10),
|
//Light::Point(XMFLOAT3(-1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.35f, 10),
|
||||||
|
@ -246,6 +258,7 @@ void Game::LoadLighting()
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
void Game::CreateBasicGeometry()
|
void Game::CreateBasicGeometry()
|
||||||
{
|
{
|
||||||
|
#pragma region Mesh Loading
|
||||||
shapes = {
|
shapes = {
|
||||||
std::make_shared<Mesh>(
|
std::make_shared<Mesh>(
|
||||||
GetFullPathTo("Assets/Models/cube.obj").c_str(),
|
GetFullPathTo("Assets/Models/cube.obj").c_str(),
|
||||||
|
@ -269,7 +282,9 @@ void Game::CreateBasicGeometry()
|
||||||
GetFullPathTo("Assets/Models/quad_double_sided.obj").c_str(),
|
GetFullPathTo("Assets/Models/quad_double_sided.obj").c_str(),
|
||||||
device, context),
|
device, context),
|
||||||
};
|
};
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region Entity Definition
|
||||||
entities = {
|
entities = {
|
||||||
std::make_shared<Entity>(materials[1], shapes[3]),
|
std::make_shared<Entity>(materials[1], shapes[3]),
|
||||||
std::make_shared<Entity>(materials[2], shapes[3]),
|
std::make_shared<Entity>(materials[2], shapes[3]),
|
||||||
|
@ -295,7 +310,9 @@ void Game::CreateBasicGeometry()
|
||||||
std::make_shared<Entity>(materials[8], shapes[3]),
|
std::make_shared<Entity>(materials[8], shapes[3]),
|
||||||
std::make_shared<Entity>(materials[8], shapes[3]),
|
std::make_shared<Entity>(materials[8], shapes[3]),
|
||||||
};
|
};
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region Transform Setup
|
||||||
for (int i = 0; i < entities.size() / 2; ++i)
|
for (int i = 0; i < entities.size() / 2; ++i)
|
||||||
{
|
{
|
||||||
entities[i]->GetTransform()->SetPosition((-(int)(entities.size() / 4) + i + 0.5f) * 2.5f, -1.5f, 0);
|
entities[i]->GetTransform()->SetPosition((-(int)(entities.size() / 4) + i + 0.5f) * 2.5f, -1.5f, 0);
|
||||||
|
@ -310,6 +327,7 @@ void Game::CreateBasicGeometry()
|
||||||
{
|
{
|
||||||
transpEntities[i]->GetTransform()->SetPosition(0, -3.5f, (-(int)(transpEntities.size() / 2) + i) * 2.5f);
|
transpEntities[i]->GetTransform()->SetPosition(0, -3.5f, (-(int)(transpEntities.size() / 2) + i) * 2.5f);
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
skybox = std::make_shared<Sky>(
|
skybox = std::make_shared<Sky>(
|
||||||
shapes[0],
|
shapes[0],
|
||||||
|
@ -345,6 +363,7 @@ void Game::Update(float deltaTime, float totalTime)
|
||||||
|
|
||||||
camera->Update(deltaTime);
|
camera->Update(deltaTime);
|
||||||
|
|
||||||
|
// rotate entities over time
|
||||||
for (int i = 0; i < entities.size(); ++i)
|
for (int i = 0; i < entities.size(); ++i)
|
||||||
{
|
{
|
||||||
entities[i]->GetTransform()->SetRotation(sin(totalTime / 720) * 360, 0, 0);
|
entities[i]->GetTransform()->SetRotation(sin(totalTime / 720) * 360, 0, 0);
|
||||||
|
@ -359,9 +378,7 @@ void Game::Draw(float deltaTime, float totalTime)
|
||||||
// Background color for clearing
|
// Background color for clearing
|
||||||
static const float color[4] = { 0.1f, 0.1f, 0.1f, 0.0f };
|
static const float color[4] = { 0.1f, 0.1f, 0.1f, 0.0f };
|
||||||
|
|
||||||
// Clear the render target and depth buffer (erases what's on the screen)
|
// Clear the render target and depth buffer (erases what's on the screen) before doign anything else
|
||||||
// - Do this ONCE PER FRAME
|
|
||||||
// - At the beginning of Draw (before drawing *anything*)
|
|
||||||
context->ClearRenderTargetView(backBufferRTV.Get(), color);
|
context->ClearRenderTargetView(backBufferRTV.Get(), color);
|
||||||
context->ClearDepthStencilView(
|
context->ClearDepthStencilView(
|
||||||
depthStencilView.Get(),
|
depthStencilView.Get(),
|
||||||
|
@ -369,11 +386,16 @@ void Game::Draw(float deltaTime, float totalTime)
|
||||||
1.0f,
|
1.0f,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
// Render solid entities first
|
||||||
for (auto entity : entities)
|
for (auto entity : entities)
|
||||||
{
|
{
|
||||||
entity->Draw(camera, ambient, lights);
|
entity->Draw(camera, ambient, lights);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the skybox after solid entities to avoid overdraw
|
||||||
|
skybox->Draw(context, camera);
|
||||||
|
|
||||||
|
// Sort transparent entities
|
||||||
std::sort(transpEntities.begin(), transpEntities.end(), [&](std::shared_ptr<Entity> a, std::shared_ptr<Entity> b) -> bool
|
std::sort(transpEntities.begin(), transpEntities.end(), [&](std::shared_ptr<Entity> a, std::shared_ptr<Entity> b) -> bool
|
||||||
{
|
{
|
||||||
XMFLOAT3 positionA = a->GetTransform()->GetPosition();
|
XMFLOAT3 positionA = a->GetTransform()->GetPosition();
|
||||||
|
@ -386,8 +408,7 @@ void Game::Draw(float deltaTime, float totalTime)
|
||||||
return aDist > bDist;
|
return aDist > bDist;
|
||||||
});
|
});
|
||||||
|
|
||||||
skybox->Draw(context, camera);
|
// Draw transparent entities with proper blendstate
|
||||||
|
|
||||||
context->OMSetBlendState(alphaBlendState.Get(), 0, 0xFFFFFFFF);
|
context->OMSetBlendState(alphaBlendState.Get(), 0, 0xFFFFFFFF);
|
||||||
for (auto entity : transpEntities)
|
for (auto entity : transpEntities)
|
||||||
{
|
{
|
||||||
|
@ -396,11 +417,11 @@ void Game::Draw(float deltaTime, float totalTime)
|
||||||
context->RSSetState(0);
|
context->RSSetState(0);
|
||||||
entity->Draw(camera, ambient, lights);
|
entity->Draw(camera, ambient, lights);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset blendstate after drawing transparent entities
|
||||||
context->OMSetBlendState(0, 0, 0xFFFFFFFF);
|
context->OMSetBlendState(0, 0, 0xFFFFFFFF);
|
||||||
|
|
||||||
// Present the back buffer to the user
|
// Present the back buffer (i.e. the final frame) to the user at the end of drawing
|
||||||
// - Puts the final frame we're drawing into the window so the user can see it
|
|
||||||
// - Do this exactly ONCE PER FRAME (always at the very end of the frame)
|
|
||||||
swapChain->Present(vsync ? 1 : 0, 0);
|
swapChain->Present(vsync ? 1 : 0, 0);
|
||||||
|
|
||||||
// Due to the usage of a more sophisticated swap chain,
|
// Due to the usage of a more sophisticated swap chain,
|
||||||
|
|
77
Material.cpp
77
Material.cpp
|
@ -1,13 +1,13 @@
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
|
|
||||||
Material::Material(
|
Material::Material(
|
||||||
bool _pbr,
|
int _mode,
|
||||||
DirectX::XMFLOAT3 _tint,
|
DirectX::XMFLOAT3 _tint,
|
||||||
float _roughness,
|
float _roughness,
|
||||||
std::shared_ptr<SimpleVertexShader> _vertexShader,
|
std::shared_ptr<SimpleVertexShader> _vertexShader,
|
||||||
std::shared_ptr<SimplePixelShader> _pixelShader)
|
std::shared_ptr<SimplePixelShader> _pixelShader)
|
||||||
{
|
{
|
||||||
pbr = _pbr;
|
mode = _mode;
|
||||||
tint = _tint;
|
tint = _tint;
|
||||||
roughness = _roughness;
|
roughness = _roughness;
|
||||||
normalIntensity = 1.f;
|
normalIntensity = 1.f;
|
||||||
|
@ -36,10 +36,22 @@ Material::~Material()
|
||||||
|
|
||||||
void Material::Activate(Transform* _transform, std::shared_ptr<Camera> _camera, DirectX::XMFLOAT3 _ambient, std::vector<Light> _lights)
|
void Material::Activate(Transform* _transform, std::shared_ptr<Camera> _camera, DirectX::XMFLOAT3 _ambient, std::vector<Light> _lights)
|
||||||
{
|
{
|
||||||
if (pbr) ActivatePBR(_transform, _camera, _ambient, _lights);
|
switch (mode)
|
||||||
else ActivateStandard(_transform, _camera, _ambient, _lights);
|
{
|
||||||
|
case MATTYPE_PBR:
|
||||||
|
ActivatePBR(_transform, _camera, _ambient, _lights);
|
||||||
|
break;
|
||||||
|
case MATTYPE_TOON:
|
||||||
|
ActivateToon(_transform, _camera, _ambient, _lights);
|
||||||
|
break;
|
||||||
|
case MATTYPE_STANDARD:
|
||||||
|
default:
|
||||||
|
ActivateStandard(_transform, _camera, _ambient, _lights);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma region Getters
|
||||||
DirectX::XMFLOAT3 Material::GetTint()
|
DirectX::XMFLOAT3 Material::GetTint()
|
||||||
{
|
{
|
||||||
return tint;
|
return tint;
|
||||||
|
@ -109,7 +121,9 @@ std::shared_ptr<SimplePixelShader> Material::GetPixelShader()
|
||||||
{
|
{
|
||||||
return pixelShader;
|
return pixelShader;
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region Setters
|
||||||
void Material::SetTint(DirectX::XMFLOAT3 _tint)
|
void Material::SetTint(DirectX::XMFLOAT3 _tint)
|
||||||
{
|
{
|
||||||
tint = _tint;
|
tint = _tint;
|
||||||
|
@ -190,7 +204,9 @@ void Material::SetPixelShader(std::shared_ptr<SimplePixelShader> _pixelShader)
|
||||||
{
|
{
|
||||||
pixelShader = _pixelShader;
|
pixelShader = _pixelShader;
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region Utility
|
||||||
void Material::LoadTexture(const wchar_t* _path, const char* _type, ID3D11Device* _device, ID3D11DeviceContext* _context)
|
void Material::LoadTexture(const wchar_t* _path, const char* _type, ID3D11Device* _device, ID3D11DeviceContext* _context)
|
||||||
{
|
{
|
||||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> shaderResourceView;
|
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> shaderResourceView;
|
||||||
|
@ -215,7 +231,9 @@ void Material::PushTexture(std::string _name, Microsoft::WRL::ComPtr<ID3D11Shade
|
||||||
{
|
{
|
||||||
textures.insert({ _name, _texture });
|
textures.insert({ _name, _texture });
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region Internal Material Activation
|
||||||
void Material::ActivateStandard(Transform* _transform, std::shared_ptr<Camera> _camera, DirectX::XMFLOAT3 _ambient, std::vector<Light> _lights)
|
void Material::ActivateStandard(Transform* _transform, std::shared_ptr<Camera> _camera, DirectX::XMFLOAT3 _ambient, std::vector<Light> _lights)
|
||||||
{
|
{
|
||||||
vertexShader->SetMatrix4x4("world", _transform->GetWorldMatrix());
|
vertexShader->SetMatrix4x4("world", _transform->GetWorldMatrix());
|
||||||
|
@ -235,18 +253,12 @@ void Material::ActivateStandard(Transform* _transform, std::shared_ptr<Camera> _
|
||||||
pixelShader->SetFloat3("ambient", _ambient);
|
pixelShader->SetFloat3("ambient", _ambient);
|
||||||
pixelShader->SetFloat3("emitAmount", GetEmitAmount());
|
pixelShader->SetFloat3("emitAmount", GetEmitAmount());
|
||||||
pixelShader->SetFloat3("tint", GetTint());
|
pixelShader->SetFloat3("tint", GetTint());
|
||||||
pixelShader->SetFloat3("rimTint", GetRimTint());
|
|
||||||
pixelShader->SetFloat3("outlineTint", GetOutlineTint());
|
|
||||||
pixelShader->SetFloat("outlineThickness", GetOutlineThickness());
|
|
||||||
pixelShader->SetFloat("rimCutoff", GetRimCutoff());
|
|
||||||
pixelShader->SetFloat("lightCount", (int)_lights.size());
|
pixelShader->SetFloat("lightCount", (int)_lights.size());
|
||||||
pixelShader->SetInt("hasAlbedoMap", (int)hasAlbedoMap);
|
pixelShader->SetInt("hasAlbedoMap", (int)hasAlbedoMap);
|
||||||
pixelShader->SetInt("hasEmissiveMap", (int)hasEmissiveMap);
|
pixelShader->SetInt("hasEmissiveMap", (int)hasEmissiveMap);
|
||||||
pixelShader->SetInt("hasSpecularMap", (int)hasSpecularMap);
|
pixelShader->SetInt("hasSpecularMap", (int)hasSpecularMap);
|
||||||
pixelShader->SetInt("hasNormalMap", (int)hasNormalMap);
|
pixelShader->SetInt("hasNormalMap", (int)hasNormalMap);
|
||||||
pixelShader->SetInt("hasReflectionMap", (int)hasReflectionMap);
|
pixelShader->SetInt("hasReflectionMap", (int)hasReflectionMap);
|
||||||
pixelShader->SetInt("hasRampDiffuse", (int)hasRampDiffuse);
|
|
||||||
pixelShader->SetInt("hasRampSpecular", (int)hasRampSpecular);
|
|
||||||
pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size());
|
pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size());
|
||||||
pixelShader->CopyAllBufferData();
|
pixelShader->CopyAllBufferData();
|
||||||
pixelShader->SetShader();
|
pixelShader->SetShader();
|
||||||
|
@ -288,3 +300,48 @@ void Material::ActivatePBR(Transform* _transform, std::shared_ptr<Camera> _camer
|
||||||
pixelShader->SetSamplerState(s.first.c_str(), s.second.Get());
|
pixelShader->SetSamplerState(s.first.c_str(), s.second.Get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Material::ActivateToon(Transform* _transform, std::shared_ptr<Camera> _camera, DirectX::XMFLOAT3 _ambient, std::vector<Light> _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->SetFloat("normalIntensity", GetNormalIntensity());
|
||||||
|
pixelShader->SetFloat("alpha", GetAlpha());
|
||||||
|
pixelShader->SetFloat("cutoff", GetCutoff());
|
||||||
|
pixelShader->SetFloat2("scale", GetUVScale());
|
||||||
|
pixelShader->SetFloat2("offset", GetUVOffset());
|
||||||
|
pixelShader->SetFloat3("ambient", _ambient);
|
||||||
|
pixelShader->SetFloat3("emitAmount", GetEmitAmount());
|
||||||
|
pixelShader->SetFloat3("tint", GetTint());
|
||||||
|
pixelShader->SetFloat3("rimTint", GetRimTint());
|
||||||
|
pixelShader->SetFloat3("outlineTint", GetOutlineTint());
|
||||||
|
pixelShader->SetFloat("outlineThickness", GetOutlineThickness());
|
||||||
|
pixelShader->SetFloat("rimCutoff", GetRimCutoff());
|
||||||
|
pixelShader->SetFloat("lightCount", (int)_lights.size());
|
||||||
|
pixelShader->SetInt("hasAlbedoMap", (int)hasAlbedoMap);
|
||||||
|
pixelShader->SetInt("hasEmissiveMap", (int)hasEmissiveMap);
|
||||||
|
pixelShader->SetInt("hasSpecularMap", (int)hasSpecularMap);
|
||||||
|
pixelShader->SetInt("hasNormalMap", (int)hasNormalMap);
|
||||||
|
pixelShader->SetInt("hasRampDiffuse", (int)hasRampDiffuse);
|
||||||
|
pixelShader->SetInt("hasRampSpecular", (int)hasRampSpecular);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
13
Material.h
13
Material.h
|
@ -20,11 +20,15 @@ constexpr auto TEXTYPE_METALNESS = "Metalness";
|
||||||
constexpr auto TEXTYPE_RAMPDIFFUSE = "RampDiffuse";
|
constexpr auto TEXTYPE_RAMPDIFFUSE = "RampDiffuse";
|
||||||
constexpr auto TEXTYPE_RAMPSPECULAR = "RampSpecular";
|
constexpr auto TEXTYPE_RAMPSPECULAR = "RampSpecular";
|
||||||
|
|
||||||
|
constexpr auto MATTYPE_STANDARD = 0;
|
||||||
|
constexpr auto MATTYPE_PBR = 1;
|
||||||
|
constexpr auto MATTYPE_TOON = 2;
|
||||||
|
|
||||||
class Material
|
class Material
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Material(
|
Material(
|
||||||
bool _pbr,
|
int _mode,
|
||||||
DirectX::XMFLOAT3 _tint,
|
DirectX::XMFLOAT3 _tint,
|
||||||
float _roughness,
|
float _roughness,
|
||||||
std::shared_ptr<SimpleVertexShader> _vertexShader,
|
std::shared_ptr<SimpleVertexShader> _vertexShader,
|
||||||
|
@ -89,8 +93,13 @@ private:
|
||||||
std::shared_ptr<Camera> _camera,
|
std::shared_ptr<Camera> _camera,
|
||||||
DirectX::XMFLOAT3 _ambient,
|
DirectX::XMFLOAT3 _ambient,
|
||||||
std::vector<Light> _lights);
|
std::vector<Light> _lights);
|
||||||
|
void ActivateToon(
|
||||||
|
Transform* _transform,
|
||||||
|
std::shared_ptr<Camera> _camera,
|
||||||
|
DirectX::XMFLOAT3 _ambient,
|
||||||
|
std::vector<Light> _lights);
|
||||||
|
|
||||||
bool pbr;
|
int mode;
|
||||||
DirectX::XMFLOAT3 tint;
|
DirectX::XMFLOAT3 tint;
|
||||||
float roughness;
|
float roughness;
|
||||||
float alpha;
|
float alpha;
|
||||||
|
|
Reference in a new issue