general copy of standard shader to toon shader
This commit is contained in:
parent
b07b4fbda0
commit
8a33809c73
2 changed files with 53 additions and 16 deletions
18
Game.cpp
18
Game.cpp
|
@ -188,6 +188,10 @@ void Game::LoadTextures()
|
||||||
materials[8]->PushSampler("BasicSampler", sampler);
|
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_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());
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
@ -195,16 +199,16 @@ void Game::LoadTextures()
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
void Game::LoadLighting()
|
void Game::LoadLighting()
|
||||||
{
|
{
|
||||||
ambient = XMFLOAT3(0.1f, 0.1f, 0.15f);
|
ambient = XMFLOAT3(0.01f, 0.01f, 0.015f);
|
||||||
|
|
||||||
lights = {
|
lights = {
|
||||||
Light::Directional(XMFLOAT3(1, 0.5f, -0.5f), XMFLOAT3(1, 1, 1), 1.0f),
|
Light::Directional(XMFLOAT3(1, 0.5f, -0.5f), XMFLOAT3(1, 1, 1), 1.0f),
|
||||||
Light::Directional(XMFLOAT3(-0.25f, -1, 0.75f), XMFLOAT3(1, 1, 1), 0.25f),
|
//Light::Directional(XMFLOAT3(-0.25f, -1, 0.75f), XMFLOAT3(1, 1, 1), 0.25f),
|
||||||
Light::Directional(XMFLOAT3(-1, 1, -0.5f), XMFLOAT3(1, 1, 1), 0.25f),
|
//Light::Directional(XMFLOAT3(-1, 1, -0.5f), XMFLOAT3(1, 1, 1), 0.25f),
|
||||||
Light::Point(XMFLOAT3(-1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.35f, 10),
|
//Light::Point(XMFLOAT3(-1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.35f, 10),
|
||||||
Light::Point(XMFLOAT3(1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.35f, 10),
|
//Light::Point(XMFLOAT3(1.5f, 0, 0), XMFLOAT3(1, 1, 1), 0.35f, 10),
|
||||||
Light::Point(XMFLOAT3(0, 2, 0), XMFLOAT3(1, 0, 0), 0.35f, 10),
|
//Light::Point(XMFLOAT3(0, 2, 0), XMFLOAT3(1, 0, 0), 0.35f, 10),
|
||||||
Light::Point(XMFLOAT3(-27.5f, 0, 0), XMFLOAT3(1, 1, 0.5f), 0.35f, 20),
|
//Light::Point(XMFLOAT3(-27.5f, 0, 0), XMFLOAT3(1, 1, 0.5f), 0.35f, 20),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,31 +7,64 @@
|
||||||
cbuffer ExternalData : register(b0)
|
cbuffer ExternalData : register(b0)
|
||||||
{
|
{
|
||||||
float3 cameraPosition;
|
float3 cameraPosition;
|
||||||
float roughness;
|
int hasNormalMap;
|
||||||
|
|
||||||
float2 offset;
|
float2 offset;
|
||||||
float2 scale;
|
float2 scale;
|
||||||
|
|
||||||
float3 ambient;
|
float3 ambient;
|
||||||
float emitAmount;
|
|
||||||
|
|
||||||
float3 tint;
|
|
||||||
float lightCount;
|
float lightCount;
|
||||||
|
|
||||||
int hasEmissiveMap;
|
float3 tint;
|
||||||
int hasSpecularMap;
|
int hasSpecularMap;
|
||||||
int hasNormalMap;
|
|
||||||
|
|
||||||
Light lights[MAX_LIGHTS];
|
Light lights[MAX_LIGHTS];
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D Albedo : register(t0);
|
Texture2D Albedo : register(t0);
|
||||||
Texture2D Specular : register(t1);
|
Texture2D Specular : register(t1);
|
||||||
Texture2D Emissive : register(t2);
|
Texture2D Normal : register(t2);
|
||||||
Texture2D Normal : register(t3);
|
|
||||||
SamplerState BasicSampler : register(s0);
|
SamplerState BasicSampler : register(s0);
|
||||||
|
|
||||||
float4 main(VertexToPixel input) : SV_TARGET
|
float4 main(VertexToPixel input) : SV_TARGET
|
||||||
{
|
{
|
||||||
return float4(1.0f, 1.0f, 1.0f, 1.0f);
|
input.normal = normalize(input.normal);
|
||||||
|
input.tangent = normalize(input.tangent);
|
||||||
|
input.uv = input.uv * scale + offset;
|
||||||
|
float3 view = getView(cameraPosition, input.worldPosition);
|
||||||
|
|
||||||
|
if (hasNormalMap > 0)
|
||||||
|
{
|
||||||
|
float3 unpackedNormal = Normal.Sample(BasicSampler, input.uv).rgb * 2 - 1;
|
||||||
|
float3 T = normalize(input.tangent - input.normal * dot(input.tangent, input.normal));
|
||||||
|
float3 B = cross(T, input.normal);
|
||||||
|
float3x3 TBN = float3x3(T, B, input.normal);
|
||||||
|
input.normal = mul(unpackedNormal, TBN);
|
||||||
|
}
|
||||||
|
|
||||||
|
float specular = 1;
|
||||||
|
if (hasSpecularMap > 0)
|
||||||
|
{
|
||||||
|
specular = 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++)
|
||||||
|
{
|
||||||
|
switch (lights[i].Type)
|
||||||
|
{
|
||||||
|
case LIGHT_TYPE_DIRECTIONAL:
|
||||||
|
light += calculateDirectionalLight(lights[i], -input.normal, view, 1 /*roughness*/, surface, specular);
|
||||||
|
break;
|
||||||
|
case LIGHT_TYPE_POINT:
|
||||||
|
light += calculatePointLight(lights[i], input.normal, view, input.worldPosition, 1 /*roughness*/, surface, specular);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 final = float3(light/* + (emit * emitAmount)*/);
|
||||||
|
|
||||||
|
return float4(pow(final, 1.0f / 2.2f), albedo.a);
|
||||||
}
|
}
|
Reference in a new issue