Jump to content

Modifying the Shader Filters in FXAA Injector


MShoap13

Recommended Posts

I'd like to invert the Vignette Effect and then apply it to the presharpening pass without adding any color. Essentially leaving a blurred radius around the outer edges of the screen. Any tips on how I'd go about modifying the shaders to accomplish this?

 

I was figuring just adding the proper code to the start of the presharpening pass would be the simplest solution, however I'm a very novice scripter and I don't exactly know how I'd accomplish the inversion. Obviously I'd want to create my own variables regarding vignette sharpening, which I should be capable of.

 

In my setup I'm not even using the post sharpening as I find it's too strong and adds aliasing back into the final picture (I even toned it all the way down to 0.008). The presharpen is much more tunable and gives a much nicer final picture.

 

Here's the code for how the Vignette shader works:

 

float4 VignettePass( float4 colorInput, float2 tex )
{
float4 vignette = colorInput;
float2 tc = tex - VignetteCenter;
float v = length(tc) / VignetteRadius;
vignette += pow(v, 4) * VignetteAmount;

return vignette;
}

 

 

And the code for the Presharpen shader:

 

float4 SharpenPass( float2 tex ) 
{
// Recover the original pixels
float4 ori = tex2D(s0, tex);
// Gaussian filter
//   [ 1, 2 , 1 ]
//   [ 2, 4 , 2 ]
//   [ 1, 2 , 1 ]
float4 c1 = tex2D(s0, tex + float2(-dx,-dy));
float4 c2 = tex2D(s0, tex + float2(0,-dy));
float4 c3 = tex2D(s0, tex + float2(dx,-dy));
float4 c4 = tex2D(s0, tex + float2(-dx,0));
float4 c5 = tex2D(s0, tex + float2(dx,0));
float4 c6 = tex2D(s0, tex + float2(-dx,dy));
float4 c7 = tex2D(s0, tex + float2(0,dy));
float4 c8 = tex2D(s0, tex + float2(dx,dy));
//Normalize the values. Formula: 1 / (1+2+1+2+4+2+1+2+1) = 1 / 16 = .0625
float4 blur = (c1+c3+c6+c8 + 2*(c2+c4+c5+c7)+ 4*ori)*0.0625;
//Subtracting the blurred image from the original image
float4 cori = CoefOri*ori - CoefBlur*blur;
//For higher precision in the calculation of contour, requires slightly more processing power
//   [ c1, c2 , c3 ]
//   [ c4, ori , c5 ]
//   [ c6, c7 , c8 ]
if (highQualitySharpen == true)
{
	c1 = tex2D(s0, tex + float2(-px,-py));
	c2 = tex2D(s0, tex + float2(0,-py));
	c3 = tex2D(s0, tex + float2(px,-py));
	c4 = tex2D(s0, tex + float2(-px,0));
	c5 = tex2D(s0, tex + float2(px,0));
	c6 = tex2D(s0, tex + float2(-px,py));
	c7 = tex2D(s0, tex + float2(0,py));
	c8 = tex2D(s0, tex + float2(px,py));
}
else {}
// Horizontal gradient
//   [ -1, 0 ,1 ]
//   [ -2, 0, 2 ]
//   [ -1, 0 ,1 ]
float delta1 = (c3 + 2*c5 + c8)-(c1 + 2*c4 + c6);
// Vertical gradient
//   [ -1,- 2,-1 ]
//   [  0,  0, 0 ]
//   [  1,  2, 1 ]
float delta2 = (c6 + 2*c7 + c8)-(c1 + 2*c2 + c3);
// Calculate and sharpen the blurry edges
if (sqrt( mul(delta1,delta1) + mul(delta2,delta2)) > SharpenEdge) 
	{
		// Contour sharpening
		return ori*Sharpen_val0 - (c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 ) * Sharpen_val1;
	}
else 
	{
		// Return corrected image
		return cori;
	}
}

 

Link to comment
Share on other sites

I played around with trying to accomplish this for a little bit last night, and I can say that this mod is very, very particular. However, I didn't even come close to achieving the effect I want. :wallbash:
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...