1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
const std::string depthGenFragShader =
"#version 130 \n"
"uniform sampler2D depthBuffer;"
"uniform sampler2D texture;"
"uniform vec3 resolution;"
"uniform float haveTexture;"
"in mat4 projMat;"
"void main () {"
"vec2 position = ( gl_FragCoord.xy / resolution.xy );"
"vec4 previous_depth_alpha = texture2D(depthBuffer, position);"
"vec4 texel = texture2D(texture, gl_TexCoord[0].xy);"
"vec4 colors[2];"
"colors[1] = texel * gl_Color;"
"colors[0] = gl_Color;"
"bool b = (haveTexture == 1);"
"float current_alpha = colors[int(b)].a;"
"float current_depth = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
"colors[1] = vec4(current_depth, current_alpha, current_depth, current_alpha);"
"colors[0] = vec4(current_depth, current_alpha, previous_depth_alpha.z, previous_depth_alpha.a);"
"b = (current_depth >= previous_depth_alpha.z && current_alpha != 0);"
"gl_FragColor = colors[int(b)];"
"}";
const std::string frameBufferGenFragShader =
"#version 130 \n"
"uniform sampler2D depthBuffer;"
"uniform sampler2D frameBuffer;"
"uniform sampler2D texture;"
"uniform vec3 resolution;"
"uniform float haveTexture;"
"in mat4 projMat;"
"void main () {"
"vec2 position = ( gl_FragCoord.xy / resolution.xy );"
"vec4 previous_depth_alpha = texture2D(depthBuffer, position);"
"vec4 previous_color = texture2D(frameBuffer, position);"
"vec4 texel = texture2D(texture, gl_TexCoord[0].xy);"
"vec4 colors[2];"
"colors[1] = texel * gl_Color;"
"colors[0] = gl_Color;"
"bool b = (haveTexture == 1);"
"vec4 current_color = colors[int(b)];"
"float current_depth = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
"colors[1] = current_color * current_color.a + previous_color * (1 - current_color.a);"
"colors[1].a = current_color.a + previous_color.a * (1 - current_color.a);"
"colors[0] = previous_color * previous_depth_alpha.a + current_color * (1 - previous_depth_alpha.a);"
"colors[0].a = previous_color.a + current_color.a * (1 - previous_color.a);"
"b = (current_depth >= previous_depth_alpha.z);"
"gl_FragColor = colors[int(b)];"
"}"; |
Partager