MONKEYYYY
This commit is contained in:
parent
002edb6651
commit
1e6ea97fd0
@ -372,6 +372,9 @@ bool CelShadingShader::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
|||||||
dataPtr2->diffuseColor = diffuseColor;
|
dataPtr2->diffuseColor = diffuseColor;
|
||||||
dataPtr2->lightDirection = lightDirection;
|
dataPtr2->lightDirection = lightDirection;
|
||||||
dataPtr2->lightPosition = lightPosition;
|
dataPtr2->lightPosition = lightPosition;
|
||||||
|
dataPtr2->constantAttenuation = 0.5f; // Set your attenuation values here
|
||||||
|
dataPtr2->linearAttenuation = 0.1f;
|
||||||
|
dataPtr2->quadraticAttenuation = 0.01f;
|
||||||
|
|
||||||
// Unlock the constant buffer.
|
// Unlock the constant buffer.
|
||||||
deviceContext->Unmap(m_lightBuffer, 0);
|
deviceContext->Unmap(m_lightBuffer, 0);
|
||||||
@ -389,6 +392,7 @@ bool CelShadingShader::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CelShadingShader::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount)
|
void CelShadingShader::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount)
|
||||||
{
|
{
|
||||||
// Set the vertex input layout.
|
// Set the vertex input layout.
|
||||||
|
@ -32,8 +32,13 @@ private:
|
|||||||
float padding; // Padding to ensure the structure is a multiple of 16 bytes.
|
float padding; // Padding to ensure the structure is a multiple of 16 bytes.
|
||||||
XMFLOAT3 lightPosition; // Add light position
|
XMFLOAT3 lightPosition; // Add light position
|
||||||
float padding2; // Padding to ensure the structure is a multiple of 16 bytes.
|
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:
|
public:
|
||||||
CelShadingShader();
|
CelShadingShader();
|
||||||
CelShadingShader(const CelShadingShader&);
|
CelShadingShader(const CelShadingShader&);
|
||||||
|
@ -5,6 +5,10 @@ cbuffer LightBuffer
|
|||||||
float padding; // Padding to ensure the structure is a multiple of 16 bytes.
|
float padding; // Padding to ensure the structure is a multiple of 16 bytes.
|
||||||
float3 lightPosition; // Add light position
|
float3 lightPosition; // Add light position
|
||||||
float padding2; // Padding to ensure the structure is a multiple of 16 bytes.
|
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;
|
Texture2D shaderTexture;
|
||||||
@ -41,6 +45,15 @@ float4 CelShadingPixelShader(PixelInputType input) : SV_TARGET
|
|||||||
// Combine the directional and positional light intensities.
|
// Combine the directional and positional light intensities.
|
||||||
lightIntensity = max(directionalLightIntensity, positionalLightIntensity);
|
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.
|
// Apply a step function to create the cel shading effect.
|
||||||
if (lightIntensity > 0.75f)
|
if (lightIntensity > 0.75f)
|
||||||
{
|
{
|
||||||
@ -71,4 +84,4 @@ float4 CelShadingPixelShader(PixelInputType input) : SV_TARGET
|
|||||||
finalColor = textureColor * diffuseColor * lightIntensity;
|
finalColor = textureColor * diffuseColor * lightIntensity;
|
||||||
|
|
||||||
return finalColor;
|
return finalColor;
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@ Pos=60,60
|
|||||||
Size=342,82
|
Size=342,82
|
||||||
|
|
||||||
[Window][Light]
|
[Window][Light]
|
||||||
Pos=1223,64
|
Pos=1564,17
|
||||||
Size=345,519
|
Size=345,519
|
||||||
|
|
||||||
[Window][Shader Manager]
|
[Window][Shader Manager]
|
||||||
Pos=33,253
|
Pos=32,253
|
||||||
Size=172,284
|
Size=172,284
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user