//source
//https://www.shadertoy.com/view/ttj3zd
float4x4 matViewProj;
const float4 vecTime;
const float4 vecViewPort;
float lightRangeFactor = 1.0;
float smoothObjectPadding = 0.33;
float lightSaturationFactor = 0.2;
float flickerSpeedFactor = 2;
float iLights;
float4 vecLightPos[8];
float4 vecLightDir[8];
float4 vecLightColor[8];
texture TargetMap;
sampler postTex = sampler_state
{
texture = <TargetMap>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
float4 FP(float2 fragCoord: VPOS) : COLOR
{
float2 uv = fragCoord.xy / vecViewPort.xy;
float3 color = tex2D(postTex, uv).rgb;
float3 blurColor = float3(0.0, 0.0, 0.0);
float aspectRatio = vecViewPort.x / vecViewPort.y;
float i = 0;
for(i = 0; i < iLights; i += 1.0)
{
// pointlights only
if(vecLightDir[i].x <= 0 && vecLightDir[i].y <= 0 && vecLightDir[i].z <= 0)
{
float4 clipSpacePos = mul(float4(vecLightPos[i].xyz, 1.0f), matViewProj);
float3 ndcSpacePos = clipSpacePos.xyz / clipSpacePos.w;
float2 windowSpacePos = float2(((ndcSpacePos.x + 1.0) / 2.0) * vecViewPort.x, ((1.0 - ndcSpacePos.y) / 2.0) * vecViewPort.y);
float2 objectCenter = windowSpacePos.xy / vecViewPort.xy;
float2 v = uv - objectCenter;
v.x = v.x * aspectRatio;
float flickerTime = sin(vecTime.w * flickerSpeedFactor);
float min_size = (vecLightPos[i].w * lightRangeFactor / 2.0) / 100;
float max_size = (vecLightPos[i].w * lightRangeFactor / 2.1) / 100;
float size = lerp(min_size, max_size, flickerTime);
float smoothSize = size * smoothObjectPadding;
float circleMix = smoothstep(size, size - smoothSize, length(v));
blurColor.rgb = lerp(blurColor.rgb, color.rgb + (vecLightColor[i].xyz * lightSaturationFactor), circleMix);
}
}
float4 fragColor = float4(blurColor, 1.0);
return fragColor;
}
technique
{
pass one
{
PixelShader = compile ps_3_0 FP();
}
}