about to blind test encodeMatrix
This commit is contained in:
parent
1f31073017
commit
bafc67c982
@ -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) {
|
private int encodeMatrix(Matrix4x4 mat, int colOffset, int rowOffset) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
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++;
|
rowOffset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,6 +147,7 @@ public class RT3script : MonoBehaviour
|
|||||||
encodedTransform[j] = Color.black;
|
encodedTransform[j] = Color.black;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outputImage.SetPixels((256*colNumber), outputImage.height-rowNumber,32,1, encodedTransform);
|
outputImage.SetPixels((256*colNumber), outputImage.height-rowNumber,32,1, encodedTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,7 +763,7 @@ Camera:
|
|||||||
near clip plane: 0.01
|
near clip plane: 0.01
|
||||||
far clip plane: 7
|
far clip plane: 7
|
||||||
field of view: 60
|
field of view: 60
|
||||||
orthographic: 0
|
orthographic: 1
|
||||||
orthographic size: 2
|
orthographic size: 2
|
||||||
m_Depth: -1
|
m_Depth: -1
|
||||||
m_CullingMask:
|
m_CullingMask:
|
||||||
@ -802,7 +802,7 @@ MonoBehaviour:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 963194225}
|
m_GameObject: {fileID: 963194225}
|
||||||
m_Enabled: 1
|
m_Enabled: 0
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: a42175a861c72054982b102c884dd2a6, type: 3}
|
m_Script: {fileID: 11500000, guid: a42175a861c72054982b102c884dd2a6, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
|
@ -37,7 +37,11 @@
|
|||||||
|
|
||||||
uniform float pointSize;
|
uniform float pointSize;
|
||||||
uniform float boxSize;
|
uniform float boxSize;
|
||||||
uniform int cameraIndex;
|
uniform float cameraIndex;
|
||||||
|
|
||||||
|
uniform float numCameras;
|
||||||
|
|
||||||
|
uniform mat4 c2wm;
|
||||||
|
|
||||||
|
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
@ -46,11 +50,16 @@
|
|||||||
|
|
||||||
vUv = vec2( position.x / width, position.y / height );
|
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;
|
float depth = ( color.r + color.g + color.b ) / 3.0;
|
||||||
|
|
||||||
// Projection code by @kcmic
|
// 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;
|
float z = depth * (farClipping-nearClipping) + nearClipping;
|
||||||
|
|
||||||
vec4 pos = vec4(
|
vec4 pos = vec4(
|
||||||
@ -59,8 +68,10 @@
|
|||||||
z*boxSize*0.5,
|
z*boxSize*0.5,
|
||||||
1.0);
|
1.0);
|
||||||
|
|
||||||
|
vec4 pos2 = inverse (c2wm) * pos;
|
||||||
|
|
||||||
gl_PointSize = pointSize;
|
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
|
if (depth <.01) { // move this point out of the view box if the depth is nearly zero
|
||||||
gl_Position = vec4(-1., -1., -1., -1.);
|
gl_Position = vec4(-1., -1., -1., -1.);
|
||||||
}
|
}
|
||||||
@ -70,14 +81,24 @@
|
|||||||
|
|
||||||
<script id="fs" type="x-shader/x-fragment">
|
<script id="fs" type="x-shader/x-fragment">
|
||||||
uniform sampler2D map;
|
uniform sampler2D map;
|
||||||
uniform int cameraIndex;
|
uniform float cameraIndex;
|
||||||
|
|
||||||
|
uniform float numCameras;
|
||||||
|
|
||||||
|
uniform mat4 c2wm;
|
||||||
|
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 color = texture2D( map, vUv*vec2(0.5,0.333) + vec2(0.0, 0.0) );
|
vec4 color = texture2D( map, vUv*vec2(1.0/numCameras,(1.0/3.0))+vec2(cameraIndex/numCameras,0.0));
|
||||||
// if (color.r < .2) { discard;}
|
// if (color.r < .2) { discard;}
|
||||||
|
|
||||||
|
if (c2wm[1][2] > .26) {
|
||||||
|
gl_FragColor = vec4(1.0, 0.5, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
gl_FragColor = vec4( color.r, color.g, color.b, 1.0);
|
gl_FragColor = vec4( color.r, color.g, color.b, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -221,8 +242,8 @@
|
|||||||
boxSize: { value: boxSize },
|
boxSize: { value: boxSize },
|
||||||
pointSize: { value: pointSize },
|
pointSize: { value: pointSize },
|
||||||
cameraIndex: { value: i },
|
cameraIndex: { value: i },
|
||||||
captureCameraToWorldMatrix: {value: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
|
numCameras: { value: numCameras },
|
||||||
captureCameraProjectionMatrix: {value: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
|
c2wm: { value: new THREE.Matrix4() }
|
||||||
},
|
},
|
||||||
vertexShader: document.getElementById("vs").textContent,
|
vertexShader: document.getElementById("vs").textContent,
|
||||||
fragmentShader: document.getElementById("fs").textContent,
|
fragmentShader: document.getElementById("fs").textContent,
|
||||||
@ -272,11 +293,12 @@
|
|||||||
// the appropriate pixel encoded floats for the camera matrix.
|
// 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(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++) {
|
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))
|
||||||
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);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user