Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 120
- //FXAA shader by kool_Kat
- uniform sampler2D gcolor;
- uniform sampler2D gdepth;
- uniform float viewHeight;
- uniform float viewWidth;
- varying vec4 texcoord;
- vec4 fxaa() {
- float pw = 1.0 / viewWidth;
- float ph = 1.0 / viewHeight;
- vec3 rgbNW = texture2D(gcolor, texcoord.xy + vec2(-pw,-ph)).xyz;
- vec3 rgbNE = texture2D(gcolor, texcoord.xy + vec2(pw,-ph)).xyz;
- vec3 rgbSW = texture2D(gcolor, texcoord.xy + vec2(-pw,ph)).xyz;
- vec3 rgbSE = texture2D(gcolor, texcoord.xy + vec2(pw,ph)).xyz;
- vec3 rgbM = texture2D(gcolor, texcoord.xy).xyz;
- vec3 luma = vec3(0.299, 0.587, 0.114);
- float lumaNW = dot(rgbNW, luma);
- float lumaNE = dot(rgbNE, luma);
- float lumaSW = dot(rgbSW, luma);
- float lumaSE = dot(rgbSE, luma);
- float lumaM = dot(rgbM, luma);
- float lumaMin = min(lumaM, min(min(lumaNW,lumaNE),min(lumaSW,lumaSE)));
- float lumaMax = max(lumaM, max(max(lumaNW,lumaNE),max(lumaSW,lumaSE)));
- vec2 dir;
- dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
- dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
- float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * 1.0/8.0), 1.0/128.0);
- float rcpDirMin = 1.0 /(min(abs(dir.x), abs(dir.y)) + dirReduce);
- dir = min(vec2(4.0,4.0),max(vec2(-4.0,-4.0),dir * rcpDirMin)) * vec2(pw,ph);
- vec3 rgbA = (1.0/2.0) * (texture2D(gcolor, texcoord.xy + dir * (1.0/3,0 - 0.5)).xyz +
- texture2D(gcolor, texcoord.xy + dir * (2.0/3.0 - 0.5)).xyz);
- vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (texture2D(gcolor, texcoord.xy + dir * (0.0/3.0 - 0.5)).xyz +
- texture2D(gcolor, texcoord.xy + dir * (3.0/3.0 - 0.5)).xyz);
- float lumaB = dot(rgbB, luma);
- if((lumaB < lumaMin) || (lumaB > lumaMax)) {
- return vec4(rgbA , 1.0);
- }
- return vec4(rgbB, 1.0);
- }
- void main() {
- gl_FragData[0] = texture2D(gcolor, texcoord.st);
- gl_FragData[1] = texture2D(gdepth, texcoord.st);
- gl_FragData[3] = fxaa();
- }
Advertisement
Add Comment
Please, Sign In to add comment