Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shader that adds outlines
- const float EDGE_THRESHOLD = 0.1;
- const float EDGE_THICKNESS = 1.0;
- const float INFINITY = 1000.0;
- uniform sampler2D sampler0;
- uniform sampler2D sampler1;
- uniform sampler2D sampler2;
- uniform float near;
- uniform float far;
- uniform float aspectRatio;
- uniform float displayHeight;
- uniform float displayWidth;
- float getDepth(vec2 coord);
- void main() {
- gl_FragColor = texture2D(sampler0, gl_TexCoord[0].st);
- vec2 o11 = vec2(1.0, aspectRatio)*EDGE_THICKNESS/displayWidth;
- vec2 base = gl_TexCoord[0].st - 2*o11;
- float depth = getDepth(gl_TexCoord[0].st);
- float avg = depth;
- float laplace = 24*depth;
- float sample;
- int n = 1;
- for (int i = 0; i < 5; ++i) {
- for (int j = 0; j < 5; ++j) {
- if (i != 2 || j != 2) {
- sample = getDepth(base + vec2(float(i) * o11.s, float(j) * o11.t));
- laplace -= sample;
- if (sample < 1.0) {
- ++n;
- avg += sample*sample;
- }
- }
- }
- }
- avg /= n;
- if (laplace > EDGE_THRESHOLD) {
- avg = clamp(avg, 0.0, 1.0);
- gl_FragColor.rgb = mix(vec3(0.0), gl_Fog.color.rgb, 0.5*avg*clamp(depth, 0.0, 1.0));
- }
- }
- float getDepth(vec2 coord) {
- // Return linearized depth in [0.0, 1.0]
- float depth = texture2D(sampler1, coord).x;
- float depth2 = texture2D(sampler2, coord).x;
- if (depth2 < 1.0) {
- depth = depth2;
- }
- if (depth == 1.0) {
- // Attempt to detect sky
- return INFINITY;
- }
- return (near - depth*far)/(near + depth*(far - near));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement