Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 120
- /*
- * Simple outline postprocessing effect
- * Author: nyuuzero
- */
- #define LINE_THICKNESS 1
- uniform sampler2D composite;
- uniform sampler2D gdepth;
- uniform float viewWidth;
- uniform float viewHeight;
- uniform float near;
- uniform float far;
- varying vec4 texcoord;
- float getLinearDepth(vec2 coords)
- {
- return (2 * near) / (far + near - texture2D( gdepth, coords ).x * (far - near));
- }
- float generateOutline(vec2 coords)
- {
- // pixelsize
- float horizontalPixelSize = 1.0 / viewWidth * LINE_THICKNESS;
- float verticalPixelSize = 1.0 / viewHeight * LINE_THICKNESS;
- // generate outline
- float tempDepth =
- getLinearDepth(coords + vec2(horizontalPixelSize,verticalPixelSize)) +
- getLinearDepth(coords + vec2(-horizontalPixelSize,verticalPixelSize)) +
- getLinearDepth(coords + vec2(0.0,-verticalPixelSize));
- tempDepth /= 3;
- return getLinearDepth(coords)-tempDepth;
- }
- void main()
- {
- vec4 color;
- color = mix(texture2D( composite, texcoord.st ),vec4(0.0,0.0,0.0,1.0),clamp(generateOutline(texcoord.st)*100,0.0,0.999));
- //color *= 1.0 - clamp(generateOutline(texcoord.st)*100,0.0,1.0);
- gl_FragColor = color;
- }
Advertisement
Add Comment
Please, Sign In to add comment