Debian Codegraph @

src/scene/glsl/generated-pascal/ssao.glsl.inc

raw
1 { -*- buffer-read-only: t -*- }
2 { DON'T EDIT -- this file was automatically generated from "source/ssao.glsl" }
3 'ivec2 screen_position();' + LineEnding +
4 'float screen_get_depth_fast(ivec2 position);' + LineEnding +
5 'vec4 screen_get_color(ivec2 position);' + LineEnding +
6 '' + LineEnding +
7 '// shader from http://www.pasteall.org/12282, http://www.youtube.com/watch?v=R_L-_oGTbqw' + LineEnding +
8 '' + LineEnding +
9 'uniform float near; //Z-near' + LineEnding +
10 'uniform float far; //Z-far' + LineEnding +
11 '' + LineEnding +
12 '#define PI 3.14159265' + LineEnding +
13 '' + LineEnding +
14 '//samples on the first ring (was 8)' + LineEnding +
15 '#define SSAO_SAMPLES 6' + LineEnding +
16 '' + LineEnding +
17 '//ring count (was 6)' + LineEnding +
18 '#define SSAO_RINGS 3' + LineEnding +
19 '' + LineEnding +
20 'vec2 rand(in vec2 coord) //generating random noise' + LineEnding +
21 '{' + LineEnding +
22 ' float noiseX = (fract(sin(dot(coord ,vec2(12.9898,78.233))) * 43758.5453));' + LineEnding +
23 ' float noiseY = (fract(sin(dot(coord ,vec2(12.9898,78.233)*2.0)) * 43758.5453));' + LineEnding +
24 ' return vec2(noiseX,noiseY)*0.004;' + LineEnding +
25 '}' + LineEnding +
26 '' + LineEnding +
27 'float readDepth(const in ivec2 coord)' + LineEnding +
28 '{' + LineEnding +
29 ' return (2.0 * near) / (far + near - screen_get_depth_fast(coord) * (far-near));' + LineEnding +
30 '}' + LineEnding +
31 '' + LineEnding +
32 'float compareDepths( in float depth1, in float depth2 )' + LineEnding +
33 '{' + LineEnding +
34 ' const float aoCap = 0.8;//1.0;' + LineEnding +
35 ' const float aoMultiplier = 100.0;' + LineEnding +
36 ' const float depthTolerance = 0.0001;' + LineEnding +
37 ' const float aorange = 60.0;// units in space the AO effect extends to (this gets divided by the camera far range' + LineEnding +
38 ' float diff = sqrt(clamp(1.0-(depth1-depth2) / (aorange/(far-near)),0.0,1.0));' + LineEnding +
39 ' float ao = min(aoCap,max(0.0,depth1-depth2-depthTolerance) * aoMultiplier) * diff;' + LineEnding +
40 ' return ao;' + LineEnding +
41 '}' + LineEnding +
42 '' + LineEnding +
43 'void main(void)' + LineEnding +
44 '{' + LineEnding +
45 ' ivec2 current_pos = screen_position();' + LineEnding +
46 ' float depth = readDepth(current_pos);' + LineEnding +
47 ' float d;' + LineEnding +
48 '' + LineEnding +
49 ' float width = float(screen_width);' + LineEnding +
50 ' float height = float(screen_height);' + LineEnding +
51 '' + LineEnding +
52 ' float aspect = width/height;' + LineEnding +
53 ' vec2 noise = rand(vec2(current_pos));' + LineEnding +
54 '' + LineEnding +
55 ' float w = (1.0 / width)/clamp(depth,0.05,1.0)+(noise.x*(1.0-noise.x));' + LineEnding +
56 ' float h = (1.0 / height)/clamp(depth,0.05,1.0)+(noise.y*(1.0-noise.y));' + LineEnding +
57 '' + LineEnding +
58 ' w *= width/2.0; h *= height/2.0; // JA added this line !!' + LineEnding +
59 '' + LineEnding +
60 ' float pw;' + LineEnding +
61 ' float ph;' + LineEnding +
62 '' + LineEnding +
63 ' float ao = 0.0;' + LineEnding +
64 ' float s = 0.0;' + LineEnding +
65 ' float fade = 1.0;' + LineEnding +
66 '' + LineEnding +
67 ' for (int i = 0 ; i < SSAO_RINGS; i += 1)' + LineEnding +
68 ' {' + LineEnding +
69 ' fade *= 0.5;' + LineEnding +
70 ' for (int j = 0 ; j < SSAO_SAMPLES*i; j += 1)' + LineEnding +
71 ' {' + LineEnding +
72 ' float step = PI*2.0 / float(SSAO_SAMPLES*i);' + LineEnding +
73 ' pw = (cos(float(j)*step)*float(i));' + LineEnding +
74 ' ph = (sin(float(j)*step)*float(i));' + LineEnding +
75 ' d = readDepth(current_pos + ivec2(int(pw * w), int(ph * h)));' + LineEnding +
76 ' ao += compareDepths(depth,d)*fade;' + LineEnding +
77 ' s += 1.0*fade;' + LineEnding +
78 ' }' + LineEnding +
79 ' }' + LineEnding +
80 '' + LineEnding +
81 ' ao /= s;' + LineEnding +
82 ' ao = 1.0-ao;' + LineEnding +
83 '' + LineEnding +
84 ' vec3 color = screen_get_color(current_pos).rgb;' + LineEnding +
85 ' //vec3 luminance = texture2D(bgl_LuminanceTexture,vec2(current_pos)).rgb;' + LineEnding +
86 ' //luminance = clamp(max(0.0,luminance-0.2)+max(0.0,luminance-0.2)+max(0.0,luminance-0.2),0.0,1.0);' + LineEnding +
87 ' //gl_FragColor = vec4(color*mix(vec3(ao),vec3(1.0),luminance),1.0);' + LineEnding +
88 '' + LineEnding +
89 ' ao = ao * 0.8 + 0.2;' + LineEnding +
90 ' gl_FragColor = vec4(color*vec3(ao),1.0);' + LineEnding +
91 ' //gl_FragColor = vec4(vec3(ao), 1.0); // ssao only' + LineEnding +
92 '}' + LineEnding +
93 ''