I'm trying to apply OpenCV's fisheye projection model to this demo (source code is here) showing 3D cube using three.js developed by Giliam de Carpentier.
the above demo is already applied fisheye-like effect, but I need a real fisheye projection with a real camera calibration.
I started implementing a new fragment shader on it, but I noticed 3rd value (z) of position of vertex is always 0. So, it's not possible to compute a=x/z, b=y/z in the formula of the projection model.
Since I'm very new to three.js and webGL, I could not figure out what's wrong with that. Could you tell me how can I get z-axis value of a vertex position?
Thank you in advance.
update: to reproduce the problem, please replace vertex shader by the following code in the lensdistortion-webgl.html.
vertexShader: [
"void main() {",
"vec3 vposition = position;",
"if (position[2] == 0.0) { ", // check if z value is zero.
" vposition[1] = 0.5 * vposition[1];", // if z value is zero, then shorten shaps along y-axis.
"}",
"gl_Position = projectionMatrix * (modelViewMatrix * vec4(vposition, 1.0));",
"}"
].join("\n"),
you will see the shorten boxes that is shown only when z coordinate is zero.