2020-10-01 21:52:19 +00:00
|
|
|
#include "Macros.fxh"
|
|
|
|
|
|
|
|
DECLARE_TEXTURE(gPosition, 0);
|
|
|
|
DECLARE_TEXTURE(gAlbedo, 1);
|
|
|
|
DECLARE_TEXTURE(gNormal, 2);
|
|
|
|
|
|
|
|
BEGIN_CONSTANTS
|
|
|
|
|
|
|
|
float3 EyePosition _ps(c0) _cb(c0);
|
|
|
|
|
|
|
|
float3 DirectionalLightDirection _ps(c1) _cb(c1);
|
2020-10-02 05:26:40 +00:00
|
|
|
float3 DirectionalLightColor _ps(c2) _cb(c2);
|
|
|
|
|
|
|
|
float Softness _ps(c3) _cb(c3);
|
2020-10-01 21:52:19 +00:00
|
|
|
|
|
|
|
END_CONSTANTS
|
|
|
|
|
|
|
|
struct VertexInput
|
|
|
|
{
|
|
|
|
float4 Position : POSITION;
|
|
|
|
float2 TexCoord : TEXCOORD;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PixelInput
|
|
|
|
{
|
|
|
|
float4 Position : SV_POSITION;
|
|
|
|
float2 TexCoord : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
PixelInput main_vs(VertexInput input)
|
|
|
|
{
|
|
|
|
PixelInput output;
|
|
|
|
|
|
|
|
output.Position = input.Position;
|
|
|
|
output.TexCoord = input.TexCoord;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 main_ps(PixelInput input) : SV_TARGET0
|
|
|
|
{
|
|
|
|
float3 worldPosition = SAMPLE_TEXTURE(gPosition, input.TexCoord).rgb;
|
|
|
|
float3 normal = SAMPLE_TEXTURE(gNormal, input.TexCoord).xyz;
|
|
|
|
float3 albedo = SAMPLE_TEXTURE(gAlbedo, input.TexCoord).rgb;
|
|
|
|
|
|
|
|
float3 V = normalize(EyePosition - worldPosition);
|
|
|
|
float3 L = normalize(DirectionalLightDirection);
|
|
|
|
float3 N = normalize(normal);
|
2020-10-02 05:26:40 +00:00
|
|
|
float3 H = normalize(V + L);
|
|
|
|
|
2020-10-01 21:52:19 +00:00
|
|
|
float NdotL = dot(N, L);
|
2020-10-02 05:26:40 +00:00
|
|
|
float NdotH = max(dot(N, H), 0.0);
|
|
|
|
|
|
|
|
float lightIntensity;
|
|
|
|
if (Softness > 0.0)
|
|
|
|
{
|
|
|
|
lightIntensity = smoothstep(0, Softness, NdotL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lightIntensity = (NdotL > 0.0) ? 1.0 : 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
float3 light = lightIntensity * DirectionalLightColor;
|
|
|
|
|
|
|
|
float specularIntensity = pow(NdotH * lightIntensity, 32 * 32);
|
|
|
|
float specularSmooth = smoothstep(0.005, 0.01, specularIntensity);
|
|
|
|
|
|
|
|
float3 specular = specularSmooth * float3(1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
float rimColor = float3(1.0, 1.0, 1.0);
|
|
|
|
float rimThreshold = 0.1;
|
|
|
|
float rimAmount = 0.76;
|
|
|
|
float rimDot = 1 - dot(V, N);
|
|
|
|
float rimIntensity = rimDot * pow(max(NdotL, 0.0), rimThreshold);
|
|
|
|
rimIntensity = smoothstep(rimAmount - 0.01, rimAmount + 0.01, rimIntensity);
|
|
|
|
float3 rim = rimIntensity * rimColor;
|
|
|
|
|
|
|
|
float3 color = albedo * (light + specular + rim);
|
2020-10-01 21:52:19 +00:00
|
|
|
|
2020-10-02 05:26:40 +00:00
|
|
|
return float4(color, 1.0);
|
2020-10-01 21:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Technique Deferred_Toon
|
|
|
|
{
|
|
|
|
Pass
|
|
|
|
{
|
|
|
|
VertexShader = compile vs_3_0 main_vs();
|
|
|
|
PixelShader = compile ps_3_0 main_ps();
|
|
|
|
}
|
|
|
|
}
|