Squadron Z HD Post-Processing Pixel Shader

Post-Processing Pixel Shader Code:

  • This code was used for post-processing in order to achieve the progressively inverted colors around the laser(it gradually inverts the color, inverting it more towards the center and smoothly doing so less as it goes towards the edges)

PixelToFrame PostProcessPS(VertexToPixel PSIn)

{
PixelToFrame Output = (PixelToFrame)0;
Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
float4 temp, temp2 = mul(PSIn.Position3D, mul(xView, xProjection));
temp.x=laserpos.x;
temp.yw = 1;
temp.z = -laserpos.y;
temp = mul(temp, mul(xView, xProjection));
float relposx = abs(PSIn.Position3D.x – laserpos.x);
if(postprocess && laser && temp.y < temp2.y+10 && relposx < laserwidth*2*3.1415926535)
{
float3 color;
color.r = Output.Color.r – (1- Output.Color.r);
color.g = Output.Color.g – (1- Output.Color.g);
color.b = Output.Color.b – (1- Output.Color.b);
if(temp.y < temp2.y)
{
Output.Color.rgb -= color * (laserwidth*2*3.1415926535 – relposx)/(laserwidth*2*3.1415926535);
}
else
{
float rely = temp.y-temp2.y;
Output.Color.rgb -= color * ((10-rely)/10) * (laserwidth*2*3.1415926535 – relposx)/(laserwidth*2*3.1415926535);
}
}

return Output;
}

%d bloggers like this: