61 lines
1.9 KiB
Plaintext
61 lines
1.9 KiB
Plaintext
float4 g_fResolution : register(c0);
|
|
float3 g_vLightDir : register(c1);
|
|
|
|
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 float g_fMinLight= 0.15f;
|
|
static float3 g_fDif = float3(1.0f, 1.0f, 1.0f);
|
|
static float3 g_fSpec = float3(3.0f, 3.0f, 3.0f);
|
|
static float3 g_fShadowBack = float3(0.05f, 0.09f, 0.15f);
|
|
|
|
struct psIn
|
|
{
|
|
float4 c : COLOR0;
|
|
float2 t : TEXCOORD0;
|
|
float3 n : TEXCOORD1;
|
|
float3 v : TEXCOORD2;
|
|
float4 s : TEXCOORD3;
|
|
float3 w : TEXCOORD4;
|
|
};
|
|
|
|
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 normal= normalize( i.n );
|
|
|
|
float fShadow = lerp( g_fMinLight, 1.0f, tex2D(shadowSampler, sc) );
|
|
|
|
float3 fColor = i.c.xyz;
|
|
|
|
float3 fDifLight= lerp( g_fShadowBack, texCUBE(envIntSampler, i.n ), fShadow );
|
|
fColor*= fDifLight * g_fDif;
|
|
|
|
// Smoothstep sets threshold for specularity
|
|
// fColor += 2.0f * smoothstep( 0.3f, 1.0f, texCUBE(envSampler, reflect(-i.v, normal)).xyz ); <- warum?! Spec kommt aus der ueberhellen Sonne
|
|
fColor+= g_fSpec * i.c.aaa * texCUBE(envSampler, reflect(-i.v, normal)).xyz * lerp( 0.65f, 1.0f, fShadow );
|
|
|
|
// Interpret brightness > 1 as glow, ATTENTION: smaller glow value means MORE glow [0,1]
|
|
float fGlow = saturate( 2.0f - dot(fColor, 0.333f) );
|
|
|
|
// Linear fake "tone mapping", remap color back into range [0,1] (glow will overbright area anyways)
|
|
fColor.xyz /= max( 1.0f, dot(fColor, 0.333f) );
|
|
|
|
return float4( fColor, fGlow );
|
|
}
|