fixed major ordering in encoding

This commit is contained in:
buncccc 2025-04-14 10:45:07 +12:00
parent bafc67c982
commit 844db81ddc
3 changed files with 40 additions and 25 deletions

View File

@ -38,6 +38,10 @@ public class RT3script : MonoBehaviour
depthImages = new RenderTexture[cameraList.Length];
depthCameraList = new Camera[cameraList.Length];
Matrix4x4 testTranslate = Matrix4x4.Translate(new Vector3(0, 0, 2));
// UnityEngine.Debug.Log(testTranslate.ToString());
// colorImage = new RenderTexture(256,256,16,RenderTextureFormat.ARGB32);
// colorImage2 = new RenderTexture(256,256,16,RenderTextureFormat.ARGB32);
@ -100,6 +104,8 @@ public class RT3script : MonoBehaviour
//encode into pixels this camera's coordinates
// var tr = cameraList[i].transform.localToWorldMatrix;
int rowOffset = 2;
// UnityEngine.Debug.Log("Encoding Camera "+i+":\n" +cameraList[i].cameraToWorldMatrix.ToString());
rowOffset = encodeMatrix(cameraList[i].cameraToWorldMatrix, i, rowOffset);
rowOffset = encodeMatrix(cameraList[i].projectionMatrix, i, rowOffset);
@ -121,11 +127,14 @@ public class RT3script : MonoBehaviour
}
// this is encoding COLUMN MAJOR; the inner loop (j) goes along the COLUMN index
// this is encoding COLUMN MAJOR; the inner loop (rowNr) goes along a column. E.g. First row's item on the column, then second row's item, etc.
private int encodeMatrix(Matrix4x4 mat, int colOffset, int rowOffset) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
encodeData(mat[i,j], colOffset, rowOffset); // if I want to switch to ROW MAJOR encoding, switch i and j here so it's [j,i]
// UnityEngine.Debug.Log("m23: "+mat.m23+"; mat[2,3]: "+mat[2,3]);
for (int colNr = 0; colNr < 4; colNr++) {
for (int rowNr = 0; rowNr < 4; rowNr++) {
encodeData(mat[rowNr,colNr], colOffset, rowOffset); // if I want to switch to ROW MAJOR encoding, switch the two loop lines above (ALT+Up/Down)
// UnityEngine.Debug.Log("RO " + rowOffset + ": encode "+mat[i,j]);
rowOffset++;
}
}

View File

@ -213,13 +213,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 91574286}
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1.8927, y: 1.8927, z: 1.8927}
m_LocalRotation: {x: -0.028943438, y: -0.7065142, z: 0.7065142, w: -0.028943438}
m_LocalPosition: {x: -0.0031539078, y: 0, z: 0.076987565}
m_LocalScale: {x: 2.2267053, y: 2.2267056, z: 2.226706}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_Father: {fileID: 1871562477}
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!1 &103678967
GameObject:
@ -540,7 +540,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_LocalPosition.x
value: 0.0026808311
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_LocalPosition.y
@ -548,7 +548,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_LocalPosition.z
value: 0.065439425
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_LocalRotation.w
@ -787,14 +787,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0.12744485, y: -0, z: -0, w: 0.9918457}
m_LocalPosition: {x: 0, y: 1.148, z: -3}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.5, z: -1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 14.644, y: 0, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &963194229
MonoBehaviour:
m_ObjectHideFlags: 0
@ -897,13 +897,18 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1332006756}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -3.7489998, y: -0.42, z: 1.462}
m_LocalPosition: {x: 0.22, y: -0.42, z: 1.462}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &1871562477 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
m_PrefabInstance: {fileID: 570808960}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1983426807
GameObject:
m_ObjectHideFlags: 0
@ -1034,7 +1039,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2050897061}
m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068}
m_LocalPosition: {x: 4.5, y: 0, z: 1.5}
m_LocalPosition: {x: 1, y: 0.5, z: -0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []

View File

@ -63,13 +63,14 @@
float z = depth * (farClipping-nearClipping) + nearClipping;
vec4 pos = vec4(
(float(cameraIndex) + position.x / width - 0.5 )*boxSize,
( position.x / width - 0.5 )*boxSize,
( position.y / height - 0.5 )*boxSize,
z*boxSize*0.5,
1.0);
vec4 pos2 = inverse (c2wm) * pos;
// vec4 pos2 = c2wm * pos;
vec4 pos2 = inverse(c2wm) * pos;
// float(cameraIndex)
gl_PointSize = pointSize;
gl_Position = projectionMatrix * modelViewMatrix * pos2;
if (depth <.01) { // move this point out of the view box if the depth is nearly zero
@ -268,7 +269,7 @@
camera.lookAt(center);
let canvas = document.getElementById("debugCanvas");
let context = canvas.getContext("2d");
let context = canvas.getContext('2d', { willReadFrequently: true } );
context.drawImage(texture.image, 0,0); //the image must be drawn to a canvas in order to read numCameras
@ -285,13 +286,13 @@
// update all the properties of each camera matrix
for(let i = 0; i < numCameras; i++) {
//skip drawing if this is the first camera, since we already did it to get numCameras above
if (i != 0) {
context.drawImage(texture.image, 256*i,0);
}
// if (i != 0) {
// context.drawImage(texture.image, 256*i,0);
// }
// this next line needs to obtain the region of the video texture with
// the appropriate pixel encoded floats for the camera matrix.
let d = context.getImageData(0,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,16); //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];
for(let rowNr = 0; rowNr < 16; rowNr++) {
@ -330,6 +331,6 @@
</script>
<canvas id="debugCanvas" width="256" height="256" />
<canvas id="debugCanvas" width="512" height="256" />
</body>
</html>