push work for return to cali

This commit is contained in:
buncccc 2025-04-21 22:25:11 +12:00
parent 1bf83a4eed
commit 8be33b903c
5 changed files with 118 additions and 60 deletions

View File

@ -23,8 +23,12 @@ Shader "Custom/DepthOnly"
o.pos = UnityObjectToClipPos(v.vertex); o.pos = UnityObjectToClipPos(v.vertex);
// o.depth = (o.pos.z + 1.) / 2. / o.pos.w; // o.depth = (o.pos.z + 1.) / 2. / o.pos.w;
// o.depth = (o.pos.z + 1.) / 2.; // o.depth = (o.pos.z + 1.) / 2.;
o.depth = o.pos.z; // o.depth = o.pos.z;
// o.depth = o.pos.z/ o.pos.w ;
// o.pos.x = o.pos.x / o.pos.w;
// o.pos.y = o.pos.y / o.pos.w;
// o.pos.z = o.pos.z / o.pos.w;
o.depth = o.pos.z / o.pos.w;
//o.depth = mul(UNITY_MATRIX_M, v.vertex).x; //o.depth = mul(UNITY_MATRIX_M, v.vertex).x;
// o.pos2 = o.pos; // o.pos2 = o.pos;
return o; return o;
@ -32,9 +36,38 @@ Shader "Custom/DepthOnly"
fixed4 frag(v2f i) : SV_Target fixed4 frag(v2f i) : SV_Target
{ {
// if (i.depth <= 0) {
// return fixed4(1.0, 0.5, 0.0, 1.0);
// }
// ****We had to change Unity's color space to Gamma such that it doesn't add its own gamma correction, // ****We had to change Unity's color space to Gamma such that it doesn't add its own gamma correction,
// for this to work ******* // for this to work *******
return fixed4(i.depth, i.depth, i.depth, 1.0); uint depth24b = (i.depth * ((1<<24)-1)); // maps depth to be from 0 --- 2^24
uint rEncode = 0;
uint gEncode = 0;
uint bEncode = 0;
// This loop encodes depth into a 24 bit value split across all three color channels.
// The least significant digit is the last blue value.
// The most significant digit is the first red value.
for (int i = 0; i < 8; i++){
bEncode |= ((depth24b) & 1) << i;
depth24b >>= 1;
gEncode |= ((depth24b) & 1) << i;
depth24b >>= 1;
rEncode |= ((depth24b) & 1) << i;
depth24b >>= 1;
}
return fixed4(
rEncode/255.,
gEncode/255.,
bEncode/255.,
1.0
);
// return fixed4(i.depth, i.depth, i.depth, 1.0);
// Output depth as grayscale // Output depth as grayscale
// return fixed4((i.depth), (i.depth), (i.depth), 1.0); // return fixed4((i.depth), (i.depth), (i.depth), 1.0);
// return fixed4( // return fixed4(

View File

@ -12904,26 +12904,62 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: Holostream starter kit value: Holostream starter kit
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1490280167841848408, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: m_ClearFlags
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1490280167841848408, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: orthographic
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1490280167841848408, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3} - target: {fileID: 1490280167841848408, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: far clip plane propertyPath: far clip plane
value: 10 value: 10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1490280167841848408, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: near clip plane
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 1490280167841848408, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3} - target: {fileID: 1490280167841848408, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: orthographic size propertyPath: orthographic size
value: 5 value: 5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1490280168423195780, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: m_ClearFlags
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1490280168423195780, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: orthographic
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1490280168423195780, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3} - target: {fileID: 1490280168423195780, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: far clip plane propertyPath: far clip plane
value: 10 value: 10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1490280168423195780, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: near clip plane
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 1490280168423195780, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3} - target: {fileID: 1490280168423195780, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: orthographic size propertyPath: orthographic size
value: 5 value: 5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1490280168970962316, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: m_ClearFlags
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1490280168970962316, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: orthographic
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1490280168970962316, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3} - target: {fileID: 1490280168970962316, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: far clip plane propertyPath: far clip plane
value: 10 value: 10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1490280168970962316, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: near clip plane
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 1490280168970962316, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3} - target: {fileID: 1490280168970962316, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: orthographic size propertyPath: orthographic size
value: 5 value: 5
@ -12950,7 +12986,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4883613104065510132, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3} - target: {fileID: 4883613104065510132, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 21.83 value: 21.18
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4883613104065510132, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3} - target: {fileID: 4883613104065510132, guid: a0090e2e14d4fa743aefa3c48d3707f3, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z

View File

@ -14,8 +14,6 @@ public class RT3script : MonoBehaviour
// public string outputRTMP = "rtmp://localhost/live/HoloPipeline"; // public string outputRTMP = "rtmp://localhost/live/HoloPipeline";
public string ingestRTMP = "rtmp://ingest.vrcdn.live/live"; public string ingestRTMP = "rtmp://ingest.vrcdn.live/live";
public string streamKey = ""; public string streamKey = "";
public string mp4name = "my_movie_depth_ffmpeg.mp4";
public Camera[] cameraList; public Camera[] cameraList;
private Camera[] depthCameraList; private Camera[] depthCameraList;

View File

@ -26,41 +26,6 @@ mat4 unity_to_opengl(mat4 U) {
0., 0., 0., 1. 0., 0., 0., 1.
) * U; ) * U;
} }
// mat4 swapHandedness(mat4 sM) {
// return mat4(
// sM[0][0], sM[0][1], sM[0][2], sM[3][0],
// sM[1][0], sM[1][1], sM[1][2], sM[3][1],
// sM[2][0], sM[2][1], sM[2][2], sM[3][2],
// sM[0][3], sM[1][3], sM[2][3], sM[3][3]);
// }
// mat4 fuckAroundAndFindOut(mat4 sM) {
// // return mat4(
// // sM[0][0], sM[1][0], sM[2][0], sM[0][3],
// // sM[0][1], sM[1][1], sM[2][1], sM[1][3],
// // sM[0][2], sM[1][2], sM[2][2], sM[2][3],
// // sM[3][0], sM[3][1], sM[3][2], sM[3][3]);
// return mat4(
// -sM[0][0], -sM[0][1], -sM[0][2], -sM[0][3],
// sM[1][0], sM[1][1], sM[1][2], sM[1][3],
// -sM[2][0], -sM[2][1], -sM[2][2], -sM[2][3],
// sM[3][0], sM[3][1], sM[3][2], sM[3][3]);
// // return mat4(
// // sM[0][0], sM[1][0], sM[0][2], sM[0][3],
// // sM[0][1], sM[1][1], sM[1][2], sM[1][3],
// // sM[2][0], sM[2][1], sM[2][2], sM[2][3],
// // sM[3][0], sM[3][1], sM[3][2], sM[3][3]);
// // return mat4(
// // sM[0][0], sM[0][1], sM[2][0], sM[0][3],
// // sM[1][0], sM[1][1], sM[2][1], sM[1][3],
// // sM[0][2], sM[1][2], sM[2][2], sM[2][3],
// // sM[3][0], sM[3][1], sM[3][2], sM[3][3]);
// // return mat4(
// // sM[0][0], sM[0][1], -sM[0][2], sM[0][3],
// // sM[1][0], sM[1][1], sM[1][2], sM[1][3],
// // -sM[2][0], sM[2][1], sM[2][2], sM[2][3],
// // sM[3][0], sM[3][1], sM[3][2], sM[3][3]);
// }
void main() { void main() {
@ -82,24 +47,36 @@ void main() {
} }
paintfordiscard = float(skipctr > skipthreshold); paintfordiscard = float(skipctr > skipthreshold);
//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))); 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;
int decodeDepth = 0;
int rEncode = int(color.r*255.);
int gEncode = int(color.g*255.);
int bEncode = int(color.b*255.);
// (original) Projection code by @kcmic // This loop decodes depth into a 24 bit value split across all three color channels.
// The least significant digit is the last blue value.
// The most significant digit is the first red value.
for (int i = 0; i < 8; i++){
decodeDepth <<= 1;
decodeDepth |= ((rEncode >> (7-i)) & 1);
decodeDepth <<= 1;
decodeDepth |= ((gEncode >> (7-i)) & 1);
decodeDepth <<= 1;
decodeDepth |= ((bEncode >> (7-i)) & 1);
}
// decodeDepth = int(10000024);
// decodeDepth = int(1<<23);
// decodeDepth = int(color.r * 255.*255.);
float depth = float(decodeDepth) / float((1<<24) - 1);
// float depth = .5;
// depth = color.r;
// if (decodeDepth > 6) depth = .5;
// 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;
// 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(
2.*(position.x / float(width)) - 1., 2.*(position.x / float(width)) - 1.,
@ -107,16 +84,11 @@ void main() {
mix(1., -1., depth), mix(1., -1., depth),
1.0 1.0
); );
//vec4 pos2 = pos;
// First undo projection, then undo view, then below model is undone; flip the Y and Z vectors since WebGL is right handed // First undo projection, then undo view, then below model is undone; flip the Y and Z vectors since WebGL is right handed
vec4 pos2 = unity_to_opengl(c2wm) * inverse(prjm) * pos; // order matters here! Parentheses do not vec4 pos2 = unity_to_opengl(c2wm) * inverse(prjm) * pos; // order matters here! Parentheses do not
pos2.xyz *= boxSize; 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;
// float(cameraIndex)
gl_PointSize = pointSize; gl_PointSize = pointSize;
gl_Position = projectionMatrix * modelViewMatrix * pos2; gl_Position = projectionMatrix * modelViewMatrix * pos2;
if (depth <.01 || (paintfordiscard != 0.0)) { // move this point out of the view box if the depth is nearly zero if (depth <.01 || (paintfordiscard != 0.0)) { // move this point out of the view box if the depth is nearly zero

19
Assets/Website~/thingy.js Normal file
View File

@ -0,0 +1,19 @@
var decodeDepth;
var rEncode = color.r;
var gEncode = color.g;
var bEncode = color.b;
// This loop decodes depth into a 24 bit value split across all three color channels.
// The least significant digit is the last blue value.
// The most significant digit is the first red value.
for (var i = 0; i < 8; i++){
decodeDepth |= ((bEncode) & 1) << i;
decodeDepth >>= 1;
decodeDepth |= ((gEncode) & 1) << i;
decodeDepth >>= 1;
decodeDepth |= ((rEncode) & 1) << i;
decodeDepth >>= 1;
}