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 50 51 52 53 54 55 56
| uniform sampler2D normalAndDepthTexture;
uniform mat4 projScene;
uniform mat4 invProjScene;
uniform vec4 viewport;
vec2 screensize = vec2(viewport[2]-viewport[0],viewport[3]-viewport[1]);
vec3 project(vec3 point)
{
vec4 res = vec4(point,1.0);
res = projScene * res;
res.xyz = (res.xyz/res.w)*0.5 + 0.5;
res.x = res.x * viewport[2] + viewport[0];
res.y = res.y * viewport[3] + viewport[1];
return res.xyz;
}
vec4 unproject(vec3 pixel)
{
vec4 point = vec4(0.0);
point=vec4(pixel,1.0);
point.x = (point.x - viewport[0]) / viewport[2];
point.y = (point.y - viewport[1]) / viewport[3];
point.xyz = point.xyz * 2.0 - 1.0;
point = invProjScene * point;
point.xyz = point.xyz / point.w;
point.w = 1.0;
return point;
}
void main(void)
{
float x = gl_FragCoord.x;
float y = gl_FragCoord.y;
vec4 color = vec4(0.0,0.0,0.0,1.0);
vec4 texel = texture2D( normalAndDepthTexture, vec2(x/screensize.x,y/screensize.y));
float z = texel.w;
//AFFICHER PIXELS EN ENTREE : color = vec4(x/screensize.x,y/screensize.y,0.0,1.0);
vec4 p = unproject(vec3(x,y,z));
//AFFICHER POINTS DANS L'ESPACE : color = vec4(-p.x*screensize.x*0.5+0.5,-p.y*screensize.y*0.5+0.5,0.0,1.0);
p = vec4(project(p.xyz),1.0);
//AFFICHER PIXELS EN SORTIE : color = vec4(p.x/screensize.x,p.y/screensize.y,0.0,1.0);
gl_FragColor = color;
} |
Partager