putting pos in coordinate space from -1,-1,-1 to 1,1,1
This commit is contained in:
parent
bca0869987
commit
6196971871
@ -104,7 +104,8 @@ public class RT3script : MonoBehaviour
|
|||||||
//encode into pixels this camera's coordinates
|
//encode into pixels this camera's coordinates
|
||||||
// var tr = cameraList[i].transform.localToWorldMatrix;
|
// var tr = cameraList[i].transform.localToWorldMatrix;
|
||||||
int rowOffset = 2;
|
int rowOffset = 2;
|
||||||
// UnityEngine.Debug.Log("Encoding Camera "+i+":\n" +cameraList[i].cameraToWorldMatrix.ToString());
|
// UnityEngine.Debug.Log("Encoding cameraToWorldMatrix for camera "+i+":\n" +cameraList[i].cameraToWorldMatrix.ToString());
|
||||||
|
// UnityEngine.Debug.Log("Encoding projectionMatrix for camera "+i+":\n" +cameraList[i].projectionMatrix.ToString());
|
||||||
|
|
||||||
rowOffset = encodeMatrix(cameraList[i].cameraToWorldMatrix, i, rowOffset);
|
rowOffset = encodeMatrix(cameraList[i].cameraToWorldMatrix, i, rowOffset);
|
||||||
rowOffset = encodeMatrix(cameraList[i].projectionMatrix, i, rowOffset);
|
rowOffset = encodeMatrix(cameraList[i].projectionMatrix, i, rowOffset);
|
||||||
|
@ -173,7 +173,8 @@
|
|||||||
pointSize: { value: pointSize },
|
pointSize: { value: pointSize },
|
||||||
cameraIndex: { value: i },
|
cameraIndex: { value: i },
|
||||||
numCameras: { value: numCameras },
|
numCameras: { value: numCameras },
|
||||||
c2wm: { value: new THREE.Matrix4() }
|
c2wm: { value: new THREE.Matrix4() },
|
||||||
|
prjm: { value: new THREE.Matrix4() }
|
||||||
},
|
},
|
||||||
vertexShader: projection_vert_shader_source,
|
vertexShader: projection_vert_shader_source,
|
||||||
fragmentShader: projection_frag_shader_source,
|
fragmentShader: projection_frag_shader_source,
|
||||||
@ -221,14 +222,22 @@
|
|||||||
|
|
||||||
// this next line needs to obtain the region of the video texture with
|
// this next line needs to obtain the region of the video texture with
|
||||||
// the appropriate pixel encoded floats for the camera matrix.
|
// the appropriate pixel encoded floats for the camera matrix.
|
||||||
let d = context.getImageData((256*i),1,canvas.width,16); //should get data from the second line to the 17th, or 16 rows of pixels
|
let d = context.getImageData((256*i),1,canvas.width,32); //should get data from the second line to the 17th, or 16 rows of pixels
|
||||||
|
|
||||||
const c2wm_array = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0];
|
const c2wm_array = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0];
|
||||||
|
const prjm_array = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0];
|
||||||
for(let rowNr = 0; rowNr < 16; rowNr++) {
|
for(let rowNr = 0; rowNr < 16; rowNr++) {
|
||||||
// cameraFloats[i][rowNr] = decodeUint32ToFloat(pixelArrayToUint32(d.data, c.width, rowNr))
|
// cameraFloats[i][rowNr] = decodeUint32ToFloat(pixelArrayToUint32(d.data, c.width, rowNr))
|
||||||
c2wm_array[rowNr] = decodeUint32ToFloat(pixelArrayToUint32(d.data, canvas.width, rowNr))
|
c2wm_array[rowNr] = decodeUint32ToFloat(pixelArrayToUint32(d.data, canvas.width, rowNr))
|
||||||
|
prjm_array[rowNr] = decodeUint32ToFloat(pixelArrayToUint32(d.data, canvas.width, rowNr+16))
|
||||||
|
|
||||||
}
|
}
|
||||||
materialList[i].uniforms.c2wm.value.fromArray(c2wm_array);
|
materialList[i].uniforms.c2wm.value.fromArray(c2wm_array);
|
||||||
|
materialList[i].uniforms.prjm.value.fromArray(prjm_array);
|
||||||
|
|
||||||
|
if (i==0) document.prjm0 = prjm_array; //these two lines make the projection array visible in console, for debugging
|
||||||
|
if (i==1) document.prjm1 = prjm_array;
|
||||||
|
// columns = document.prjm1; a = []; for (let row=0; row < 4; ++row) a.push([columns[0+row], columns[4+row], columns[8+row], columns[12+row]]); a
|
||||||
}
|
}
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ uniform sampler2D map;
|
|||||||
uniform float cameraIndex;
|
uniform float cameraIndex;
|
||||||
uniform float numCameras;
|
uniform float numCameras;
|
||||||
uniform mat4 c2wm;
|
uniform mat4 c2wm;
|
||||||
|
uniform mat4 prjm;
|
||||||
|
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
varying float paintfordiscard;
|
varying float paintfordiscard;
|
||||||
|
@ -12,7 +12,7 @@ uniform float cameraIndex;
|
|||||||
uniform float numCameras;
|
uniform float numCameras;
|
||||||
|
|
||||||
uniform mat4 c2wm;
|
uniform mat4 c2wm;
|
||||||
|
uniform mat4 prjm;
|
||||||
|
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
varying vec2 vUv1pxOffset;
|
varying vec2 vUv1pxOffset;
|
||||||
@ -21,7 +21,7 @@ varying float paintfordiscard;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
vUv = vec2( position.x / width, position.y / height ); // -> vec2(0, 0)
|
vUv = vec2( position.x / width, position.y / height );
|
||||||
vUv1pxOffset = vec2( 1.0 / width, 1.0 / height ) * 2.0;
|
vUv1pxOffset = vec2( 1.0 / width, 1.0 / height ) * 2.0;
|
||||||
|
|
||||||
int skipctr = 0;
|
int skipctr = 0;
|
||||||
@ -50,15 +50,26 @@ void main() {
|
|||||||
// guess the projection.
|
// guess the projection.
|
||||||
// Undoes the perspective division
|
// Undoes the perspective division
|
||||||
//float z = depth * (farClipping-nearClipping) + nearClipping;
|
//float z = depth * (farClipping-nearClipping) + nearClipping;
|
||||||
float z = depth;
|
// float z = depth;
|
||||||
|
|
||||||
|
// vec4 pos = vec4(
|
||||||
|
// ( position.x / width - 0.5 )*boxSize,
|
||||||
|
// ( position.y / height - 0.5 )*boxSize,
|
||||||
|
// z*boxSize*0.5, // we had applied a (-1.0) multiplier to try to flip element [2,2]
|
||||||
|
// 1.0);
|
||||||
|
|
||||||
vec4 pos = vec4(
|
vec4 pos = vec4(
|
||||||
( position.x / width - 0.5 )*boxSize,
|
2.*(position.x / float(width)) - 1.,
|
||||||
( position.y / height - 0.5 )*boxSize,
|
2.*(position.y / float(height)) - 1.,
|
||||||
z*boxSize*0.5, // we had applied a (-1.0) multiplier to try to flip element [2,2]
|
2.*depth - 1.,
|
||||||
1.0);
|
1.0
|
||||||
|
);
|
||||||
//vec4 pos2 = pos;
|
//vec4 pos2 = pos;
|
||||||
vec4 pos2 = c2wm * pos;
|
// vec4 pos2 = c2wm * prjm * pos; // order matters here! First undo projection, then undo view, then below model is undone
|
||||||
|
vec4 pos2 = c2wm * inverse(prjm) * pos; // order matters here! First undo projection, then undo view, then below model is undone
|
||||||
|
pos2.xyz *= boxSize;
|
||||||
|
// pos2 = pos2 * vec4(20000., 20000., 20000., 20000.); // bad idea! the last point needs to be 1 for translation to work
|
||||||
|
// pos2 = pos2 * boxSize;
|
||||||
//vec4 pos2 = inverse(c2wm) * pos;
|
//vec4 pos2 = inverse(c2wm) * pos;
|
||||||
// float(cameraIndex)
|
// float(cameraIndex)
|
||||||
gl_PointSize = pointSize;
|
gl_PointSize = pointSize;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user