110 lines
2.6 KiB
Plaintext
110 lines
2.6 KiB
Plaintext
|
#include "Macros.fxh" //from FNA
|
||
|
#include "Lighting.fxh"
|
||
|
#include "Shadow.fxh"
|
||
|
|
||
|
DECLARE_TEXTURE(gPosition, 0);
|
||
|
DECLARE_TEXTURE(gAlbedo, 1);
|
||
|
DECLARE_TEXTURE(gNormal, 2);
|
||
|
DECLARE_TEXTURE(gMetallicRoughness, 3);
|
||
|
DECLARE_CUBEMAP(shadowMap, 4);
|
||
|
|
||
|
BEGIN_CONSTANTS
|
||
|
|
||
|
float3 EyePosition _ps(c0) _cb(c0);
|
||
|
|
||
|
float3 LightPosition _ps(c1) _cb(c1);
|
||
|
float3 LightDirection _ps(c2) _cb(c2);
|
||
|
float3 LightColor _ps(c3) _cb(c3);
|
||
|
float LightCutoff _ps(c4) _cb(c4);
|
||
|
|
||
|
float FarPlane _ps(c5) _cb(c5);
|
||
|
|
||
|
MATRIX_CONSTANTS
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
// Pixel Shader
|
||
|
|
||
|
float4 ComputeColor(
|
||
|
float3 worldPosition,
|
||
|
float3 worldNormal,
|
||
|
float3 albedo,
|
||
|
float metallic,
|
||
|
float roughness
|
||
|
) {
|
||
|
float3 V = normalize(EyePosition - worldPosition);
|
||
|
float3 N = normalize(worldNormal);
|
||
|
|
||
|
float3 F0 = float3(0.04, 0.04, 0.04);
|
||
|
F0 = lerp(F0, albedo, metallic);
|
||
|
|
||
|
float3 lightDir = LightPosition - worldPosition;
|
||
|
float3 L = normalize(lightDir);
|
||
|
float distance = length(lightDir);
|
||
|
float attenuation = 1.0 / (distance * distance);
|
||
|
float3 radiance = LightColor * attenuation;
|
||
|
|
||
|
//float shadow = HardPointShadow(worldPosition, N, L, PointLightPosition, SAMPLER(shadowMap), FarPlane);
|
||
|
float3 color = ComputeLight(L, radiance, F0, V, N, albedo, metallic, roughness, 1.0);
|
||
|
|
||
|
return float4(color, 1.0);
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
float2 metallicRoughness = SAMPLE_TEXTURE(gMetallicRoughness, input.TexCoord).rg;
|
||
|
|
||
|
float3 lightDir = normalize(LightPosition - worldPosition);
|
||
|
|
||
|
float theta = dot(lightDir, normalize(-LightDirection));
|
||
|
|
||
|
if (theta > LightCutoff)
|
||
|
{
|
||
|
return ComputeColor(
|
||
|
worldPosition,
|
||
|
normal,
|
||
|
albedo,
|
||
|
metallicRoughness.r,
|
||
|
metallicRoughness.g
|
||
|
);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return float4(0.0, 0.0, 0.0, 1.0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Technique DeferredPBR_Point
|
||
|
{
|
||
|
Pass
|
||
|
{
|
||
|
VertexShader = compile vs_3_0 main_vs();
|
||
|
PixelShader = compile ps_3_0 main_ps();
|
||
|
}
|
||
|
}
|