implement toon shading basics

This commit is contained in:
lightling 2022-04-19 21:32:18 -04:00
parent 8a33809c73
commit d04a1afb66
Signed by: lightling
GPG key ID: 016F11E0AA296B67
3 changed files with 35 additions and 7 deletions

View file

@ -190,8 +190,10 @@ void Game::LoadTextures()
materials[8]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-floor_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get());
materials[9]->PushSampler("BasicSampler", sampler);
materials[9]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get());
materials[9]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get());
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());
}
// --------------------------------------------------------

View file

@ -66,7 +66,7 @@ float4 main(VertexToPixel input) : SV_TARGET
switch (lights[i].Type)
{
case LIGHT_TYPE_DIRECTIONAL:
light += calculateDirectionalLight(lights[i], input.normal, view, roughness, surface, specular);
light += calculateDirectionalLight(lights[i], -input.normal, view, roughness, surface, specular);
break;
case LIGHT_TYPE_POINT:
light += calculatePointLight(lights[i], input.normal, view, input.worldPosition, roughness, surface, specular);

View file

@ -16,6 +16,8 @@ cbuffer ExternalData : register(b0)
float lightCount;
float3 tint;
float roughness;
int hasSpecularMap;
Light lights[MAX_LIGHTS];
@ -26,6 +28,22 @@ Texture2D Specular : register(t1);
Texture2D Normal : register(t2);
SamplerState BasicSampler : register(s0);
float RampDiffuse(float original)
{
if (original < 0.25f) return 0.0f;
//if (original < 0.5f) return 0.5f;
if (original < 0.75f) return 0.75f;
return 1;
}
float RampSpecular(float original)
{
if (original < 0.95f) return 0.0f;
return 1.0f;
}
float4 main(VertexToPixel input) : SV_TARGET
{
input.normal = normalize(input.normal);
@ -42,10 +60,10 @@ float4 main(VertexToPixel input) : SV_TARGET
input.normal = mul(unpackedNormal, TBN);
}
float specular = 1;
float specularValue = 1;
if (hasSpecularMap > 0)
{
specular = Specular.Sample(BasicSampler, input.uv).r;
specularValue = Specular.Sample(BasicSampler, input.uv).r;
}
float4 albedo = pow(Albedo.Sample(BasicSampler, input.uv).rgba, 2.2f);
@ -53,15 +71,23 @@ float4 main(VertexToPixel input) : SV_TARGET
float3 light = ambient * surface;
for (int i = 0; i < lightCount; i++)
{
float3 toLight = float3(0, 0, 0);
float attenuate = 1;
switch (lights[i].Type)
{
case LIGHT_TYPE_DIRECTIONAL:
light += calculateDirectionalLight(lights[i], -input.normal, view, 1 /*roughness*/, surface, specular);
toLight = normalize(lights[i].Direction);
break;
case LIGHT_TYPE_POINT:
light += calculatePointLight(lights[i], input.normal, view, input.worldPosition, 1 /*roughness*/, surface, specular);
toLight = normalize(lights[i].Position - input.worldPosition);
attenuate = getAttenuation(lights[i].Position, input.worldPosition, lights[i].Range);
break;
}
float diffuse = RampDiffuse(getDiffuse(input.normal, toLight));
float specular = RampSpecular(calculateSpecular(input.normal, toLight, view, specularValue, diffuse) * roughness);
light += (diffuse * surface.rgb + specular) * attenuate * lights[i].Intensity * lights[i].Color;
}
float3 final = float3(light/* + (emit * emitAmount)*/);