Texture TargetMap;
sampler2D g_samSrcColor = sampler_state { texture = <TargetMap>; MipFilter = Linear; };
texture mtlSkin1;
sampler2D randSrc = sampler_state{texture = (mtlSkin1); };
float4 vecSkill1;
float4 vecViewPort;
#define PI2 6.28318530717959
#define MAGIC_GRAD_THRESH 0.01
#define MAGIC_SENSITIVITY 10.0
#define MAGIC_COLOR 0.5
float4 getCol(float2 pos)
{
float2 uv = pos / vecViewPort.xy;
return tex2D(g_samSrcColor, uv);
}
float getVal(float2 pos)
{
float4 c = getCol(pos);
return dot(c.xyz, float3(0.2126, 0.7152, 0.0722));
}
float2 getGrad(float2 pos, float eps)
{
float2 d= float2(eps,0);
return float2(
getVal(pos+d.xy)-getVal(pos-d.xy),
getVal(pos+d.yx)-getVal(pos-d.yx)
)/eps/2.0;
}
void pR(inout float2 p, float a) {
p = cos(a)*p + sin(a)* float2(p.y, -p.x);
}
float absCircular(float t)
{
float a = floor(t + 0.5);
return fmod(abs(a - t), 1.0);
}
float4 postprocessing_gameboy( float2 Tex : TEXCOORD0 ) : COLOR0
{
float2 pos = Tex;
float weight = 1.0;
for (int j = 0; j < 4; j += 1)
{
float2 dir = float2(1, 0);
pR(dir, float(j) * PI2 / (2.0 * 4.0));
float2 grad = float2(-dir.y, dir.x);
for (int i = -16; i <= 16; i += 2)
{
float2 pos2 = pos + normalize(dir)*float(i);
// video texture wrap can't be set to anything other than clamp (-_-)
if (pos2.y < 0.0 || pos2.x < 0.0 || pos2.x > vecViewPort.x || pos2.y > vecViewPort.y)
continue;
float2 g = getGrad(pos2, 1.);
if (length(g) < MAGIC_GRAD_THRESH)
continue;
weight -= pow(abs(dot(normalize(grad), normalize(g))), MAGIC_SENSITIVITY) / floor((2.0 * 16.0 + 1.0) / 2.0) / 4.0;
}
}
#ifndef GRAYSCALE
float4 col = getCol(pos);
#else
float4 col = float4(getVal(pos), getVal(pos), getVal(pos), 1.0);
#endif
float4 background = lerp(col, float4(1.0,1.0,1.0,1.0), MAGIC_COLOR);
// I couldn't get this to look good, but I guess it's almost obligatory at this point...
/*float distToLine = absCircular(fragCoord.y / (iResolution.y/8.));
background = lerp(vec4(0.6,0.6,1,1), background, smoothstep(0., 0.03, distToLine));*/
// because apparently all shaders need one of these. It's like a law or something.
float r = length(pos - vecViewPort.xy*.5) / vecViewPort.x;
float vign = 1. - r*r*r;
float4 a = tex2D(randSrc, pos/vecViewPort.xy);
float4 fragColor = vign * lerp(float4(0.0,0.0,0.0,0.0), background, weight) + a.xxxx/25.;
//fragColor = getCol(pos);
return fragColor;
}
technique PostProcess
{
pass p1
{
AlphaBlendEnable = false;
VertexShader = null;
PixelShader = compile ps_3_0 postprocessing_gameboy();
}
}