From bafc67c98232bf9622f150e9f4e4478141efbd8c Mon Sep 17 00:00:00 2001 From: buncccc Date: Thu, 10 Apr 2025 20:06:30 +1200 Subject: [PATCH] about to blind test encodeMatrix --- Assets/RT3script.cs | 4 +++- Assets/Scenes/SampleScene.unity | 4 ++-- Assets/Website/index.html | 42 +++++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Assets/RT3script.cs b/Assets/RT3script.cs index 2c83a8f..3ac541f 100644 --- a/Assets/RT3script.cs +++ b/Assets/RT3script.cs @@ -121,10 +121,11 @@ public class RT3script : MonoBehaviour } + // this is encoding COLUMN MAJOR; the inner loop (j) goes along the COLUMN index 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); + 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] rowOffset++; } } @@ -146,6 +147,7 @@ public class RT3script : MonoBehaviour encodedTransform[j] = Color.black; } } + outputImage.SetPixels((256*colNumber), outputImage.height-rowNumber,32,1, encodedTransform); } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 84fad09..c7c14a6 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -763,7 +763,7 @@ Camera: near clip plane: 0.01 far clip plane: 7 field of view: 60 - orthographic: 0 + orthographic: 1 orthographic size: 2 m_Depth: -1 m_CullingMask: @@ -802,7 +802,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 963194225} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: a42175a861c72054982b102c884dd2a6, type: 3} m_Name: diff --git a/Assets/Website/index.html b/Assets/Website/index.html index 40ad0c3..85e054f 100644 --- a/Assets/Website/index.html +++ b/Assets/Website/index.html @@ -37,7 +37,11 @@ uniform float pointSize; uniform float boxSize; - uniform int cameraIndex; + uniform float cameraIndex; + + uniform float numCameras; + + uniform mat4 c2wm; varying vec2 vUv; @@ -46,11 +50,16 @@ vUv = vec2( position.x / width, position.y / height ); - vec4 color = texture2D( map, vUv*vec2(0.5,0.333)+vec2(0,0.333)); + //vec4 color = texture2D( map, vUv*vec2(0.5,(1.0/3.0))+vec2(0,(1.0/3.0))); + vec4 color = texture2D( map, vUv*vec2(1.0/numCameras,(1.0/3.0))+vec2(cameraIndex/numCameras,(1.0/3.0))); + float depth = ( color.r + color.g + color.b ) / 3.0; // Projection code by @kcmic + // instead of building a matrix and multiplying by the matrix, math is being done to + // guess the projection. + // Undoes the perspective division float z = depth * (farClipping-nearClipping) + nearClipping; vec4 pos = vec4( @@ -59,8 +68,10 @@ z*boxSize*0.5, 1.0); + vec4 pos2 = inverse (c2wm) * pos; + gl_PointSize = pointSize; - gl_Position = projectionMatrix * modelViewMatrix * pos; + gl_Position = projectionMatrix * modelViewMatrix * pos2; if (depth <.01) { // move this point out of the view box if the depth is nearly zero gl_Position = vec4(-1., -1., -1., -1.); } @@ -70,14 +81,24 @@ @@ -221,8 +242,8 @@ boxSize: { value: boxSize }, pointSize: { value: pointSize }, cameraIndex: { value: i }, - captureCameraToWorldMatrix: {value: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, - captureCameraProjectionMatrix: {value: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, + numCameras: { value: numCameras }, + c2wm: { value: new THREE.Matrix4() } }, vertexShader: document.getElementById("vs").textContent, fragmentShader: document.getElementById("fs").textContent, @@ -272,11 +293,12 @@ // 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 - + 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++) { // cameraFloats[i][rowNr] = decodeUint32ToFloat(pixelArrayToUint32(d.data, c.width, rowNr)) - materialList[i].uniforms.captureCameraToWorldMatrix.value[rowNr] = decodeUint32ToFloat(pixelArrayToUint32(d.data, canvas.width, rowNr)) + c2wm_array[rowNr] = decodeUint32ToFloat(pixelArrayToUint32(d.data, canvas.width, rowNr)) } + materialList[i].uniforms.c2wm.value.fromArray(c2wm_array); } renderer.render(scene, camera); }