From 1e6ea97fd067921db935f7381dbd1375cb859909 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Thu, 26 Sep 2024 21:55:33 +0200 Subject: [PATCH] MONKEYYYY --- enginecustom/CelShadingShader.cpp | 4 ++++ enginecustom/CelShadingShader.h | 5 +++++ enginecustom/celshading.ps | 15 ++++++++++++++- enginecustom/imgui.ini | 4 ++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/enginecustom/CelShadingShader.cpp b/enginecustom/CelShadingShader.cpp index 478551d..ddc15e0 100644 --- a/enginecustom/CelShadingShader.cpp +++ b/enginecustom/CelShadingShader.cpp @@ -372,6 +372,9 @@ bool CelShadingShader::SetShaderParameters(ID3D11DeviceContext* deviceContext, X dataPtr2->diffuseColor = diffuseColor; dataPtr2->lightDirection = lightDirection; dataPtr2->lightPosition = lightPosition; + dataPtr2->constantAttenuation = 0.5f; // Set your attenuation values here + dataPtr2->linearAttenuation = 0.1f; + dataPtr2->quadraticAttenuation = 0.01f; // Unlock the constant buffer. deviceContext->Unmap(m_lightBuffer, 0); @@ -389,6 +392,7 @@ bool CelShadingShader::SetShaderParameters(ID3D11DeviceContext* deviceContext, X } + void CelShadingShader::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount) { // Set the vertex input layout. diff --git a/enginecustom/CelShadingShader.h b/enginecustom/CelShadingShader.h index d152943..141c6a3 100644 --- a/enginecustom/CelShadingShader.h +++ b/enginecustom/CelShadingShader.h @@ -32,8 +32,13 @@ private: float padding; // Padding to ensure the structure is a multiple of 16 bytes. XMFLOAT3 lightPosition; // Add light position float padding2; // Padding to ensure the structure is a multiple of 16 bytes. + float constantAttenuation; + float linearAttenuation; + float quadraticAttenuation; + float padding3; // Padding to ensure the structure is a multiple of 16 bytes. }; + public: CelShadingShader(); CelShadingShader(const CelShadingShader&); diff --git a/enginecustom/celshading.ps b/enginecustom/celshading.ps index c613dcf..32fd479 100644 --- a/enginecustom/celshading.ps +++ b/enginecustom/celshading.ps @@ -5,6 +5,10 @@ cbuffer LightBuffer float padding; // Padding to ensure the structure is a multiple of 16 bytes. float3 lightPosition; // Add light position float padding2; // Padding to ensure the structure is a multiple of 16 bytes. + float constantAttenuation; + float linearAttenuation; + float quadraticAttenuation; + float padding3; // Padding to ensure the structure is a multiple of 16 bytes. }; Texture2D shaderTexture; @@ -41,6 +45,15 @@ float4 CelShadingPixelShader(PixelInputType input) : SV_TARGET // Combine the directional and positional light intensities. lightIntensity = max(directionalLightIntensity, positionalLightIntensity); + // Calculate the distance from the light to the fragment. + float distance = length(lightPosition - input.worldPos); + + // Apply an attenuation factor based on the distance. + float attenuation = 1.0f / (constantAttenuation + linearAttenuation * distance + quadraticAttenuation * distance * distance); + + // Combine the light intensity with the attenuation factor. + lightIntensity *= attenuation; + // Apply a step function to create the cel shading effect. if (lightIntensity > 0.75f) { @@ -71,4 +84,4 @@ float4 CelShadingPixelShader(PixelInputType input) : SV_TARGET finalColor = textureColor * diffuseColor * lightIntensity; return finalColor; -} \ No newline at end of file +} diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index 7130f2b..45d976f 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -15,10 +15,10 @@ Pos=60,60 Size=342,82 [Window][Light] -Pos=1223,64 +Pos=1564,17 Size=345,519 [Window][Shader Manager] -Pos=33,253 +Pos=32,253 Size=172,284