73 lines
2.0 KiB
Plaintext
73 lines
2.0 KiB
Plaintext
float4 g_fResolution : register(c0);
|
|
float3 g_vLightDir : register(c1);
|
|
float3 g_vViewDir : register(c4);
|
|
|
|
float4 g_fGlow : register(c61);
|
|
|
|
sampler1D dif : register(s2);
|
|
sampler1D spec : register(s3);
|
|
sampler2D shadowSampler : register(s4);
|
|
sampler2D depthSampler : register(s5);
|
|
samplerCUBE envSampler : register(s6);
|
|
samplerCUBE envIntSampler : register(s7);
|
|
|
|
static float4 g_fSpecularPower = {1.15f, 1.05f, 1.0f, 1.25f};
|
|
|
|
struct psIn
|
|
{
|
|
float4 c : COLOR0;
|
|
float2 t : TEXCOORD0;
|
|
float3 n : TEXCOORD1;
|
|
float3 v : TEXCOORD2;
|
|
float4 s : TEXCOORD3;
|
|
float3 w : TEXCOORD4;
|
|
float3 o : TEXCOORD5;
|
|
};
|
|
|
|
float4 ps_main(psIn i):color
|
|
{
|
|
// Environment lighting
|
|
// return texCUBE(envIntSampler, i.n);
|
|
// Environment reflection
|
|
// return texCUBE(envSampler, reflect(-i.v, i.n));
|
|
|
|
// Shadow AA
|
|
float2 sc = i.s.xy / i.s.w;
|
|
float aa = abs( tex2D(depthSampler, sc).x - i.s.z );
|
|
float2 ddaa = float2(ddx(aa), ddy(aa));
|
|
float2 aaetc = sign(-ddaa) * g_fResolution.zw;
|
|
sc += aaetc * saturate(4.f * aa);
|
|
|
|
float3 n = normalize(i.n);
|
|
float3 v = normalize(i.v);
|
|
float3 no = normalize(i.o);
|
|
|
|
float3 fColor = i.c.xyz;
|
|
float fShadow = 0.6f + 0.4f * tex2D(shadowSampler, sc);
|
|
|
|
// return texCUBE(envSampler, reflect(g_vViewDir, i.n));
|
|
// g_vViewDir
|
|
|
|
// fColor *= texCUBE(envSampler, i.n).xyz; // * fShadow // envIntSampler
|
|
// fColor += 0.1f * texCUBE(envSampler, reflect(-i.v, i.n)).xyz;
|
|
|
|
// Lighting
|
|
float fLight = saturate( dot( n, -g_vLightDir) );
|
|
fLight = min(fShadow * fLight, fLight);
|
|
fColor.xyz *= lerp(
|
|
float3(0.7f, 0.6f, 1.0f) * tex1D( dif, fLight ),
|
|
float3(0.8f, 0.6f, 0.9f) * tex1D( dif, abs( sin(5 * fLight) ) ),
|
|
saturate( 5 * dot(no, n) ) );
|
|
|
|
// return abs( 3 * dot(no, n) );
|
|
|
|
// Specular highlights
|
|
float3 h = normalize( v + -g_vLightDir );
|
|
float hdn = saturate( dot(n, h) );
|
|
float fSpecularity = smoothstep( 0.5f, 0.9f,
|
|
abs( sin(16 * hdn) ) * ( dot( n, -g_vLightDir) > 0 ) + abs( sin(8 * dot(n, v)) ) * 0.85f );
|
|
fColor += 0.3f * fShadow * tex1D( spec, fSpecularity );
|
|
|
|
return float4( (1.0f + 1.5f * g_fGlow.w) * fColor, 0.3f );
|
|
}
|