From 8c103bb3f949c141e73f3733ad067ce5899ad13c Mon Sep 17 00:00:00 2001 From: Lightling Date: Tue, 19 Apr 2022 22:40:39 -0400 Subject: [PATCH] add various shader supports - standard+toon w/o albedo - toon emission - emission as a color - standard+toon alpha+cutoff values (toon looks weird because of rim lighting at the moment) --- Assets/Textures/Ramps/toonRamp1.png | Bin 0 -> 17485 bytes Assets/Textures/Ramps/toonRamp2.png | Bin 0 -> 17473 bytes Assets/Textures/Ramps/toonRamp3.png | Bin 0 -> 17467 bytes Assets/Textures/Ramps/toonRampSpecular.png | Bin 0 -> 17466 bytes DX11Starter.vcxproj | 58 +++++++++++++++++++++ DX11Starter.vcxproj.filters | 15 ++++++ Game.cpp | 19 +++++-- Material.cpp | 37 +++++++++++-- Material.h | 13 +++-- SimplePixelShader.hlsl | 30 ++++++++--- ToonShader.hlsl | 39 ++++++++++---- 11 files changed, 181 insertions(+), 30 deletions(-) create mode 100644 Assets/Textures/Ramps/toonRamp1.png create mode 100644 Assets/Textures/Ramps/toonRamp2.png create mode 100644 Assets/Textures/Ramps/toonRamp3.png create mode 100644 Assets/Textures/Ramps/toonRampSpecular.png diff --git a/Assets/Textures/Ramps/toonRamp1.png b/Assets/Textures/Ramps/toonRamp1.png new file mode 100644 index 0000000000000000000000000000000000000000..421440aad5aa6215dc0aab61b5a53ab4efc286f1 GIT binary patch literal 17485 zcmeI4ZB!Fi8pj6}&?O_g&{KuBS|LB3=oi7 z(H<+hYulsHT3g&6ySlU<+`6t-M1l3Ct(mMXMgW))%_?RuFY>5=<@;9lNI= zZ_a@{-24AOck;W>eKKE$TJ!9gv7(7048vlL*@j#U8wSE**vKgGcFlXN54?@AXP7cD z>~ueAmezyGn@nb=*<8Z%ELXz1#m3A`vD?Gi7zd4EQ#-6hMGdF_bLQNUDQ#_LvnBW3 zq;v5Telg+CZA%+!{#dgiA|`I#n$f==KCC+ZQcHh}CCbwFY1kcI}?l~lCsQj!qE3!AMHlZ;w{qN>!>C28M zv>Mve+qzb z`!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Qh+qN21=A3W5iUVQumItLX$Zy$mmnfofN;Sy1Y?9t5D_duxL_KBF~TK?2o@k* zFb%;N;Sxjy3lJ`thG2|v2_k|82p3F4Fh;lp5y1k43#K6$KNOcJ^zxm_&vJPp!ll@rPH5PkiBuEj5VdJJ?m^d55(qG50W#R}7%K#4nFCPJ({2he^ why$tzbS_YTKz$N@9iXp8|LuXs+7dA)CA$Bgg)7>9|J}ftHQUfMqiFg60D3h7q5uE@ literal 0 HcmV?d00001 diff --git a/Assets/Textures/Ramps/toonRamp2.png b/Assets/Textures/Ramps/toonRamp2.png new file mode 100644 index 0000000000000000000000000000000000000000..3dc94e511f3fd4554b65910a4bd63b5729eb7ca8 GIT binary patch literal 17473 zcmeI4ZB!Fi8pj6}(1_OBTEX4cG|G0NBr^#lkue02u###tVx(YKWynmzNRml20|ZK~ z*gY!Rb=zZMYqhwZc6Di8-MU?0s0yqvZROMtU5njnsjD8lwkj^ZEr_~z5=<@;9lNI= zZ_a@{-24AOck;W>eKKE$I_s?Iqhu3g7>129=b7>`YzPR4V8dg;+g1OuUhp=|nQh6& zuv2}MRoMV0Z?HKzR%)UZ3#pg}LO5T0**lAjRD|+QW+Gog?o_eX6CxB%@>q=j8)@%GG#A}8(Dw# z&CcZQ^OCIEIk%cBtovq6vduMLd9@?zqM2-JE~s8sz5VL%;!}vN+EwbE+Bfu!?q#;3 zt!B%ivF#%Y$~*SxUffw*vF&=t=)-HsS&NT8r;=^!_Q)EYaD4vx z{Hjpaw*GJLUQX5W8Tt?k%y z^c}PD<_~@Et^WG=YZjXK_ICAdSg+f4sk5nNOU<2w2ljqaGW&XFd(G3`-KT!&+tuBr zswwTIdwae-9{ufsS7d$UwJp~+p1E@e8-+cRc3fB(501nLZ(b3PVWSUk!w{trJc~}<@$7$TC3Nm=~LtyLaoJ#R6LbXYEsEGf=tuM`(Fy93`7PW z?I80_zv^EO{FR|76$CGd)Oq=X2uf^z?L`(BK-45-5~>l}DibN)JCNnB;CA z6T{nmtXE(;k6g@4m2l-khC(4O6ngc4F1I(dkcaPQ2Poox%8RR21U{IFwue04a-S=3 zX|x?@T#TFX2t4qq2lWA@7E8!F=yGoNpiW-MtpJ~(pU9w2-d5#h@O*~n%6)bww*p+r zq`@xUd$)ZKo-QvmjI5h-GPu{{G~nSuNEs+P z((K^{%428DCLk=9=g_D@OJxE$EEd>) zPihlqFBj{+KQ;X$Q$zN9QqT6Wpl4AoNF!eTk6mJrH1{l($MT@ks-Ox4br|SMbD0+h zj^3Scv4QU5rF=Xi9=;64-P0FpN1<*bdIE=-r0il}GTOz`W@rOGU^IMLA!omh{eL$w zm>;s=e~rpg#`B<~5lj_O-9HJ>IfP2e$7DM}O+3u04Q3r^i%f68#Xjz02W~`gbm0En zt=N0_(-3NHWDe)zd=`#ojA{cu*l>7#$OUdUt--rZqlpvb(<#;iT2LaK0g^x|#J)&^ zA_PFFz~+Nh?-`5K7mCH?Di7%O8Unm->C5Z?YAY3pF$r$01L<9>EE|`X7jBrUJf&~Z{OhYn8xFiw50)z{uAsHiF zl89gd!UfZij1ewLM6dwif@w&`2$v)xSb%WBG$dn$OA-+*K)7HUk}<+1i3k=TTrdsE z7~zsc1Pc%@n1*DGa7iM91qc^RLo!CVBoV;^gbSu286#Yhh+qN21=Em>5iUtYumItL zX-LKhmn0%sfN;SyBx8h25)mvwxL_KRF~TK@2o@k*Fb&E0fw*Mhrw17icx12=JR7*| z)`3_I8}2rnvTgo_7dx^aT}og>+mIq2UHK}T%i7d`Xu@~ iKwpc&+XLroy)3#~F%l-%K#`{MA literal 0 HcmV?d00001 diff --git a/Assets/Textures/Ramps/toonRamp3.png b/Assets/Textures/Ramps/toonRamp3.png new file mode 100644 index 0000000000000000000000000000000000000000..c0b29b4918d337e131036485614597df35d18d93 GIT binary patch literal 17467 zcmeI4e^gWF8OJXwpb?eXx}sZc8f6=lR8!Q|J(Wv5iwKOubueQv14j8F76%NYmKsYeAw~rr5UTKlJ~YvRIRN~ z>3B8f-MHMxu+leQK6-|d-ilo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P8!U)Q4J|&d9o0pM|ApgHn$VHXL3ba)H}TYw&Kc$^!X=6b z79d$(OutDir)/Assets/Textures/PBR + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + + + false + true + false + true + false + true + false + true + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + $(OutDir)/Assets/Textures/Ramps + + diff --git a/DX11Starter.vcxproj.filters b/DX11Starter.vcxproj.filters index 089b7ba..65951b6 100644 --- a/DX11Starter.vcxproj.filters +++ b/DX11Starter.vcxproj.filters @@ -40,6 +40,9 @@ {5a00f65f-2015-451b-9c46-5131e9fd2555} + + {e1723348-5c0a-4f5f-8586-ccf0126a4509} + @@ -324,6 +327,18 @@ Assets\Textures\PBR + + Assets\Textures\Ramps + + + Assets\Textures\Ramps + + + Assets\Textures\Ramps + + + Assets\Textures\Ramps + diff --git a/Game.cpp b/Game.cpp index 76ea700..0927627 100644 --- a/Game.cpp +++ b/Game.cpp @@ -80,6 +80,7 @@ void Game::LoadShadersAndMaterials() pixelShaderToon = std::make_shared(device, context, GetFullPathTo_Wide(L"ToonShader.cso").c_str()); XMFLOAT3 white = XMFLOAT3(1.0f, 1.0f, 1.0f); + XMFLOAT3 deepPurple = XMFLOAT3(0.1f, 0.02f, 0.1f); materials = { std::make_shared(false, white, 0, vertexShader, pixelShader), @@ -92,6 +93,7 @@ void Game::LoadShadersAndMaterials() std::make_shared(true, white, 0, vertexShaderPBR, pixelShaderPBR), std::make_shared(false, white, 0, vertexShader, pixelShader), std::make_shared(false, white, 0, vertexShader, pixelShaderToon), + std::make_shared(false, deepPurple, 0, vertexShader, pixelShaderToon), }; } @@ -188,12 +190,21 @@ void Game::LoadTextures() materials[8]->PushSampler("BasicSampler", sampler); materials[8]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-floor_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); materials[8]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-floor_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); + // this texture has some weird noise artifacts in the holes of the floor that I probably just never noticed + // when I used it in the game I made it for because it was also had Cutoff in Unity. add high cutoff, but not too high for distant mipmaps + materials[8]->SetCutoff(0.9f); + // this is just to test alpha + materials[8]->SetAlpha(0.8f); materials[9]->PushSampler("BasicSampler", sampler); materials[9]->SetRoughness(1); 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[10]->PushSampler("BasicSampler", sampler); + materials[10]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_emissive.png", TEXTYPE_EMISSIVE, device.Get(), context.Get()); + materials[10]->SetEmitAmount(XMFLOAT3(0.05f, 0.1f, 0.01f)); } // -------------------------------------------------------- @@ -257,10 +268,10 @@ void Game::CreateBasicGeometry() std::make_shared(materials[9], shapes[3]), std::make_shared(materials[9], shapes[3]), std::make_shared(materials[9], shapes[3]), - std::make_shared(materials[9], shapes[3]), - std::make_shared(materials[9], shapes[3]), - std::make_shared(materials[9], shapes[3]), - std::make_shared(materials[9], shapes[3]), + std::make_shared(materials[10], shapes[3]), + std::make_shared(materials[10], shapes[3]), + std::make_shared(materials[10], shapes[3]), + std::make_shared(materials[10], shapes[3]), }; transpEntities = { diff --git a/Material.cpp b/Material.cpp index 1186d06..bf30dc5 100644 --- a/Material.cpp +++ b/Material.cpp @@ -10,11 +10,14 @@ Material::Material( pbr = _pbr; tint = _tint; roughness = _roughness; + alpha = 1; + cutoff = 0; vertexShader = _vertexShader; pixelShader = _pixelShader; uvOffset = DirectX::XMFLOAT2(0, 0); uvScale = DirectX::XMFLOAT2(1, 1); - emitAmount = 0; + emitAmount = DirectX::XMFLOAT3(0, 0, 0); + hasAlbedoMap = false; hasEmissiveMap = false; hasSpecularMap = false; hasNormalMap = false; @@ -51,7 +54,17 @@ float Material::GetRoughness() return roughness; } -float Material::GetEmitAmount() +float Material::GetAlpha() +{ + return alpha; +} + +float Material::GetCutoff() +{ + return cutoff; +} + +DirectX::XMFLOAT3 Material::GetEmitAmount() { return emitAmount; } @@ -97,7 +110,17 @@ void Material::SetRoughness(float _roughness) } } -void Material::SetEmitAmount(float _emit) +void Material::SetAlpha(float _alpha) +{ + alpha = _alpha; +} + +void Material::SetCutoff(float _cutoff) +{ + cutoff = _cutoff; +} + +void Material::SetEmitAmount(DirectX::XMFLOAT3 _emit) { emitAmount = _emit; } @@ -118,7 +141,8 @@ void Material::LoadTexture(const wchar_t* _path, const char* _type, ID3D11Device DirectX::CreateWICTextureFromFile(_device, _context, DXCore::GetFullPathTo_Wide(_path).c_str(), 0, shaderResourceView.GetAddressOf()); PushTexture(_type, shaderResourceView); - if (_type == TEXTYPE_EMISSIVE) hasEmissiveMap = true; + if (_type == TEXTYPE_ALBEDO) hasAlbedoMap = true; + else if (_type == TEXTYPE_EMISSIVE) hasEmissiveMap = true; else if (_type == TEXTYPE_SPECULAR) hasSpecularMap = true; else if (_type == TEXTYPE_NORMAL) hasNormalMap = true; else if (_type == TEXTYPE_REFLECTION) hasReflectionMap = true; @@ -145,12 +169,15 @@ void Material::ActivateStandard(Transform* _transform, std::shared_ptr _ pixelShader->SetFloat3("cameraPosition", _camera->GetTransform()->GetPosition()); pixelShader->SetFloat("roughness", GetRoughness()); + pixelShader->SetFloat("alpha", GetAlpha()); + pixelShader->SetFloat("cutoff", GetCutoff()); pixelShader->SetFloat2("scale", GetUVScale()); pixelShader->SetFloat2("offset", GetUVOffset()); pixelShader->SetFloat3("ambient", _ambient); - pixelShader->SetFloat("emitAmount", GetEmitAmount()); + pixelShader->SetFloat3("emitAmount", GetEmitAmount()); pixelShader->SetFloat3("tint", GetTint()); 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); diff --git a/Material.h b/Material.h index 9f1d5bd..4111c98 100644 --- a/Material.h +++ b/Material.h @@ -39,7 +39,9 @@ public: DirectX::XMFLOAT2 GetUVScale(); DirectX::XMFLOAT2 GetUVOffset(); float GetRoughness(); - float GetEmitAmount(); + float GetAlpha(); + float GetCutoff(); + DirectX::XMFLOAT3 GetEmitAmount(); std::shared_ptr GetVertexShader(); std::shared_ptr GetPixelShader(); @@ -47,7 +49,9 @@ public: void SetUVScale(DirectX::XMFLOAT2 _scale); void SetUVOffset(DirectX::XMFLOAT2 _offset); void SetRoughness(float _roughness); - void SetEmitAmount(float _emit); + void SetAlpha(float _alpha); + void SetCutoff(float _cutoff); + void SetEmitAmount(DirectX::XMFLOAT3 _emit); void SetVertexShader(std::shared_ptr _vertexShader); void SetPixelShader(std::shared_ptr _pixelShader); @@ -55,6 +59,7 @@ public: void PushSampler(std::string _name, Microsoft::WRL::ComPtr _sampler); void PushTexture(std::string _name, Microsoft::WRL::ComPtr _texture); + bool hasAlbedoMap; bool hasEmissiveMap; bool hasSpecularMap; bool hasNormalMap; @@ -74,7 +79,9 @@ private: bool pbr; DirectX::XMFLOAT3 tint; float roughness; - float emitAmount; + float alpha; + float cutoff; + DirectX::XMFLOAT3 emitAmount; DirectX::XMFLOAT2 uvScale; DirectX::XMFLOAT2 uvOffset; std::shared_ptr vertexShader; diff --git a/SimplePixelShader.hlsl b/SimplePixelShader.hlsl index 642b8e2..c46944b 100644 --- a/SimplePixelShader.hlsl +++ b/SimplePixelShader.hlsl @@ -7,20 +7,24 @@ cbuffer ExternalData : register(b0) { float3 cameraPosition; - float roughness; + int hasNormalMap; float2 offset; float2 scale; float3 ambient; - float emitAmount; - - float3 tint; float lightCount; + float3 tint; + int hasAlbedoMap; + + float3 emitAmount; int hasEmissiveMap; + + float alpha; + float cutoff; + float roughness; int hasSpecularMap; - int hasNormalMap; int hasReflectionMap; Light lights[MAX_LIGHTS]; @@ -39,6 +43,18 @@ float4 main(VertexToPixel input) : SV_TARGET // ensure input normals are normalized input.normal = normalize(input.normal); input.tangent = normalize(input.tangent); + + float3 surface = tint; + float alphaValue = alpha; + if (hasAlbedoMap) + { + float4 sampledAlbedo = Albedo.Sample(BasicSampler, input.uv); + if (sampledAlbedo.a < cutoff) discard; + float3 albedo = pow(sampledAlbedo.rgb, 2.2f); + surface *= albedo.rgb; + alphaValue *= sampledAlbedo.a; + } + if (hasNormalMap > 0) { float3 unpackedNormal = Normal.Sample(BasicSampler, input.uv).rgb * 2 - 1; @@ -52,12 +68,10 @@ float4 main(VertexToPixel input) : SV_TARGET // view only needs calculated once, so pre-calculate here and pass it to lights float3 view = getView(cameraPosition, input.worldPosition); - float4 albedo = pow(Albedo.Sample(BasicSampler, input.uv).rgba, 2.2f); float specular = 1; if (hasSpecularMap > 0) specular = Specular.Sample(BasicSampler, input.uv).r; float3 emit = float3(1, 1, 1); if (hasEmissiveMap > 0) emit = Emissive.Sample(BasicSampler, input.uv).rgb; - float3 surface = albedo.rgb * tint; float3 light = ambient * surface; // loop through lights @@ -83,5 +97,5 @@ float4 main(VertexToPixel input) : SV_TARGET final = lerp(final, reflCol, getFresnel(input.normal, view, F0_NON_METAL)); } - return float4(pow(final, 1.0f/2.2f), albedo.a); + return float4(pow(final, 1.0f/2.2f), alphaValue); } diff --git a/ToonShader.hlsl b/ToonShader.hlsl index 9202ab8..b66444f 100644 --- a/ToonShader.hlsl +++ b/ToonShader.hlsl @@ -16,7 +16,13 @@ cbuffer ExternalData : register(b0) float lightCount; float3 tint; + int hasAlbedoMap; + float3 emitAmount; + int hasEmissiveMap; + + float alpha; + float cutoff; float roughness; int hasSpecularMap; @@ -26,9 +32,12 @@ cbuffer ExternalData : register(b0) Texture2D Albedo : register(t0); Texture2D Specular : register(t1); Texture2D Normal : register(t2); +Texture2D Emissive : register(t3); +Texture2D RampDiffuse : register(t4); +Texture2D RampSpecular : register(t5); SamplerState BasicSampler : register(s0); -float RampDiffuse(float original) +float GetRampDiffuse(float original) { if (original < 0.25f) return 0.0f; //if (original < 0.5f) return 0.5f; @@ -37,7 +46,7 @@ float RampDiffuse(float original) return 1; } -float RampSpecular(float original) +float GetRampSpecular(float original) { if (original < 0.6f) return 0.0f; @@ -52,6 +61,17 @@ float4 main(VertexToPixel input) : SV_TARGET float3 view = getView(cameraPosition, input.worldPosition); float3 normal = input.normal; + float3 surface = tint; + float alphaValue = alpha; + if (hasAlbedoMap) + { + float4 sampledAlbedo = Albedo.Sample(BasicSampler, input.uv); + if (sampledAlbedo.a < cutoff) discard; + float3 albedo = pow(sampledAlbedo.rgb, 2.2f); + surface *= albedo.rgb; + alphaValue *= sampledAlbedo.a; + } + if (hasNormalMap > 0) { float3 unpackedNormal = Normal.Sample(BasicSampler, input.uv).rgb * 2 - 1; @@ -66,9 +86,6 @@ float4 main(VertexToPixel input) : SV_TARGET { specularValue = Specular.Sample(BasicSampler, input.uv).r; } - - float4 albedo = pow(Albedo.Sample(BasicSampler, input.uv).rgba, 2.2f); - float3 surface = albedo.rgb * tint; float3 light = ambient * surface; for (int i = 0; i < lightCount; i++) { @@ -85,14 +102,16 @@ float4 main(VertexToPixel input) : SV_TARGET break; } - float diffuse = RampDiffuse(getDiffuse(normal, toLight)); - float specular = RampSpecular(calculateSpecular(normal, toLight, view, specularValue, diffuse) * roughness); + float diffuse = GetRampDiffuse(getDiffuse(normal, toLight)); + float specular = GetRampSpecular(calculateSpecular(normal, toLight, view, specularValue, diffuse) * roughness); light += (diffuse * surface.rgb + specular) * attenuate * lights[i].Intensity * lights[i].Color; } - float4 rim = RampSpecular((1 - dot(view, input.normal)) * pow(light, 0.075f)); - float3 final = float3(light + rim/* + (emit * emitAmount)*/); + float3 emit = float3(1, 1, 1); + if (hasEmissiveMap > 0) emit = Emissive.Sample(BasicSampler, input.uv).rgb; + float4 rim = GetRampSpecular((1 - dot(view, input.normal)) * pow(light, 0.075f)); + float3 final = float3(light + rim + (emit * emitAmount)); - return float4(pow(final, 1.0f / 2.2f), albedo.a); + return float4(pow(final, 1.0f / 2.2f), alphaValue); } \ No newline at end of file