From 22d0253364c596e7a7841dc7a09f37c9fc42c53e Mon Sep 17 00:00:00 2001 From: Lightling Date: Tue, 19 Apr 2022 23:43:43 -0400 Subject: [PATCH] expose outline/rim values --- Game.cpp | 1 + Material.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ Material.h | 12 ++++++++++++ ToonShader.hlsl | 12 ++++++------ 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/Game.cpp b/Game.cpp index 4159e4f..afb43fe 100644 --- a/Game.cpp +++ b/Game.cpp @@ -206,6 +206,7 @@ void Game::LoadTextures() materials[9]->LoadTexture(L"Assets/Textures/WithNormals/cushion.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); materials[9]->LoadTexture(L"Assets/Textures/WithNormals/cushion_normals.png", TEXTYPE_NORMAL, device.Get(), context.Get()); materials[9]->LoadTexture(L"Assets/Textures/WithNormals/cushion_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); + materials[9]->SetOutlineThickness(0); materials[10]->PushSampler("BasicSampler", sampler); materials[10]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_emissive.png", TEXTYPE_EMISSIVE, device.Get(), context.Get()); diff --git a/Material.cpp b/Material.cpp index e4fa831..8420525 100644 --- a/Material.cpp +++ b/Material.cpp @@ -23,6 +23,9 @@ Material::Material( hasSpecularMap = false; hasNormalMap = false; hasReflectionMap = false; + outlineThickness = 1; + rimCutoff = 0.075f; + rimTint = DirectX::XMFLOAT3(0.5f, 0.5f, 0.5f); } Material::~Material() @@ -70,11 +73,31 @@ float Material::GetNormalIntensity() return normalIntensity; } +float Material::GetRimCutoff() +{ + return rimCutoff; +} + +float Material::GetOutlineThickness() +{ + return outlineThickness; +} + DirectX::XMFLOAT3 Material::GetEmitAmount() { return emitAmount; } +DirectX::XMFLOAT3 Material::GetOutlineTint() +{ + return outlineTint; +} + +DirectX::XMFLOAT3 Material::GetRimTint() +{ + return rimTint; +} + std::shared_ptr Material::GetVertexShader() { return vertexShader; @@ -131,11 +154,31 @@ void Material::SetNormalIntensity(float _intensity) normalIntensity = _intensity; } +void Material::SetRimCutoff(float _cutoff) +{ + rimCutoff = _cutoff; +} + +void Material::SetOutlineThickness(float _thickness) +{ + outlineThickness = _thickness; +} + void Material::SetEmitAmount(DirectX::XMFLOAT3 _emit) { emitAmount = _emit; } +void Material::SetOutlineTint(DirectX::XMFLOAT3 _tint) +{ + outlineTint = _tint; +} + +void Material::SetRimTint(DirectX::XMFLOAT3 _tint) +{ + rimTint = _tint; +} + void Material::SetVertexShader(std::shared_ptr _vertexShader) { vertexShader = _vertexShader; @@ -188,6 +231,10 @@ void Material::ActivateStandard(Transform* _transform, std::shared_ptr _ 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); diff --git a/Material.h b/Material.h index 7c175d3..2be3f9a 100644 --- a/Material.h +++ b/Material.h @@ -42,7 +42,11 @@ public: float GetAlpha(); float GetCutoff(); float GetNormalIntensity(); + float GetRimCutoff(); + float GetOutlineThickness(); DirectX::XMFLOAT3 GetEmitAmount(); + DirectX::XMFLOAT3 GetOutlineTint(); + DirectX::XMFLOAT3 GetRimTint(); std::shared_ptr GetVertexShader(); std::shared_ptr GetPixelShader(); @@ -53,7 +57,11 @@ public: void SetAlpha(float _alpha); void SetCutoff(float _cutoff); void SetNormalIntensity(float _intensity); + void SetRimCutoff(float _cutoff); + void SetOutlineThickness(float _thickness); void SetEmitAmount(DirectX::XMFLOAT3 _emit); + void SetOutlineTint(DirectX::XMFLOAT3 _tint); + void SetRimTint(DirectX::XMFLOAT3 _tint); void SetVertexShader(std::shared_ptr _vertexShader); void SetPixelShader(std::shared_ptr _pixelShader); @@ -84,7 +92,11 @@ private: float alpha; float cutoff; float normalIntensity; + float outlineThickness; + float rimCutoff; DirectX::XMFLOAT3 emitAmount; + DirectX::XMFLOAT3 outlineTint; + DirectX::XMFLOAT3 rimTint; DirectX::XMFLOAT2 uvScale; DirectX::XMFLOAT2 uvOffset; std::shared_ptr vertexShader; diff --git a/ToonShader.hlsl b/ToonShader.hlsl index 662764b..0df85fa 100644 --- a/ToonShader.hlsl +++ b/ToonShader.hlsl @@ -26,8 +26,8 @@ cbuffer ExternalData : register(b0) float roughness; float normalIntensity; - float3 outline; - float outlineIntensity; + float3 outlineTint; + float outlineThickness; float3 rimTint; float rimCutoff; @@ -120,17 +120,17 @@ float4 main(VertexToPixel input) : SV_TARGET if (hasEmissiveMap > 0) emit = Emissive.Sample(BasicSampler, input.uv).rgb; float vDotN = (1 - dot(view, input.normal)); - float rimValue = GetRampSpecular(vDotN * pow(light, 0.075f)); - float outlineValue = GetRampSpecular(vDotN * 2); + float rimValue = GetRampSpecular(vDotN * pow(light, rimCutoff)); + float outlineValue = GetRampSpecular(vDotN * outlineThickness); if (rimValue > 0) { - return float4(light + (emit * emitAmount) + float3(1,1,1), alphaValue); + return float4(light + (emit * emitAmount) + rimTint, alphaValue); } if (outlineValue > 0) { - return float4(outlineValue * float3(0,0,0), alphaValue); + return float4(outlineValue * outlineTint, alphaValue); } float3 final = float3(light + (emit * emitAmount));