57 lines
1.5 KiB
Plaintext
57 lines
1.5 KiB
Plaintext
float3 lightDir : register(c1);
|
|
float3 viewDir : register(c4);
|
|
float3 passID2expIsLast : register(c23);
|
|
|
|
sampler2D colorSampler : register(s0);
|
|
sampler2D depthSampler : register(s1);
|
|
|
|
// Tweakables
|
|
static float4 g_fRayColor = float4(0.9f, 0.8f, 0.7f, 1.0f);
|
|
static float g_fRayNearPlane = 10.0f;
|
|
static float g_fRayFarPlane = 500.0f;
|
|
static float g_fRayDensity = 0.25f;
|
|
static float g_fRayDecay = 0.9125f;
|
|
static float g_fRayAnglePersistence = 4.f;
|
|
|
|
float4 ps_ray_mask(float2 TexCoord : TEXCOORD0, float2 LightPos : TEXCOORD2) : COLOR0
|
|
{
|
|
float2 d = LightPos - TexCoord;
|
|
float r = saturate( 1.f - dot(d, d) );
|
|
r *= saturate( g_fRayAnglePersistence * dot(-lightDir, viewDir) );
|
|
|
|
float m = tex2D(depthSampler, TexCoord).x;
|
|
m = saturate( (m - g_fRayNearPlane) / (g_fRayFarPlane - g_fRayNearPlane) );
|
|
// m = saturate(1.f - m);
|
|
|
|
// float2 p = TexCoord * 2.0f - 1.0f;
|
|
// float b = saturate( 1.0f - 0.7071f * dot(p, p) );
|
|
|
|
return /* b */ m * r * g_fRayColor;
|
|
}
|
|
|
|
// Pixel shader
|
|
float4 ps_ray_extrude(float2 TexCoord : TEXCOORD0, float2 LightPos : TEXCOORD2) : COLOR0
|
|
{
|
|
float2 s = g_fRayDensity / (passID2expIsLast.y) * (LightPos - TexCoord) / 8.f;
|
|
|
|
float4 r = 0.f, ro = 0.f, rm = 0.f, rd = .125f;
|
|
float2 c = TexCoord;
|
|
|
|
for(int i = 0; i < 8; i++)
|
|
{
|
|
float4 rs = tex2D(colorSampler, c);
|
|
ro = (i == 0) ? rs : ro;
|
|
|
|
rm = max(rs, rm);
|
|
rs.xyz = rm.xyz;
|
|
r += rs * rd;
|
|
|
|
rd.xyz *= (float3)g_fRayDecay;
|
|
c += s;
|
|
}
|
|
|
|
r.a = min(ro.a, r.a);
|
|
|
|
return r * saturate(1.f - passID2expIsLast.z * r.a);
|
|
}
|