Wire OBS Spout capture and brush lowering
This commit is contained in:
parent
f6b32c6356
commit
03330f9476
7 changed files with 115 additions and 22 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -6,3 +6,6 @@ logs/
|
|||
__pycache__/
|
||||
.venv/
|
||||
calibration/runs/
|
||||
tools/drivers/
|
||||
tools/obs-spout2-plugin/
|
||||
tools/src/
|
||||
|
|
|
|||
|
|
@ -12,13 +12,16 @@ This is the deadline stream surface. It is not a preview window and it is not a
|
|||
flowchart TD
|
||||
A["TrackCache / demo source"] --> B["RenderFramePacket JSON"]
|
||||
B --> C["scripts/stream_spout.py"]
|
||||
C --> D["OpenGL FBO"]
|
||||
D --> E["Spout sender texture"]
|
||||
E --> F["OBS Spout2 Capture"]
|
||||
C --> D["ScreenBrushPacket lowering"]
|
||||
D --> E["OpenGL texture/FBO"]
|
||||
E --> F["Spout sender texture"]
|
||||
F --> G["OBS Spout2 Capture"]
|
||||
```
|
||||
|
||||
Aquarium Engine remains the intended authority for dense brush/splat rendering. The useful boundary is `RenderFramePacket`: Aquarium can replace the OpenGL renderer behind the same packet contract without changing capture, fusion, timing, or OBS ingestion.
|
||||
|
||||
The deadline sink borrows the Zyphos brush rule rather than pretending points are enough: each render point lowers into a compact anisotropic screen brush with center, radii, rotation, and color. That shape mirrors Aquarium's bounded brush/splat direction while keeping the stream path simple enough to verify under pressure.
|
||||
|
||||
## Run
|
||||
|
||||
Install calibration/runtime dependencies once:
|
||||
|
|
@ -40,7 +43,7 @@ Start the Spout sender:
|
|||
--status .\calibration\runs\stream-spout-status.json
|
||||
```
|
||||
|
||||
For OBS, add a Spout2 Capture source and select `LocalCastBridge Point Cloud`.
|
||||
For OBS, add a Spout2 Capture source and select `LocalCastBridge Point Cloud`. On this workstation, OBS websocket was enabled locally and the Off World Live `win-spout` plugin was installed under `C:\ProgramData\obs-studio\plugins\win-spout`.
|
||||
|
||||
## Status
|
||||
|
||||
|
|
@ -72,7 +75,7 @@ The next renderer cut is to move the `RenderFramePacket` consumer into Aquarium
|
|||
```text
|
||||
RenderFramePacket
|
||||
-> Aquarium typed runtime state
|
||||
-> GPU splat/brush buffers
|
||||
-> compact anisotropic brush/splat buffers
|
||||
-> D3D render target
|
||||
-> Spout2 sender texture
|
||||
-> OBS Spout2 Capture
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from .core import (
|
|||
load_fusion_config,
|
||||
)
|
||||
from .render_bridge import RenderBridgeConfig, RenderFramePacket, RenderPointPacket, lower_points_to_render_frame
|
||||
from .spout_output import SpoutOutputConfig, frame_to_vertex_array
|
||||
from .spout_output import ScreenBrushPacket, SpoutOutputConfig, frame_to_vertex_array, lower_frame_to_screen_brushes
|
||||
|
||||
__all__ = [
|
||||
"CameraModel",
|
||||
|
|
@ -27,7 +27,9 @@ __all__ = [
|
|||
"RenderBridgeConfig",
|
||||
"RenderFramePacket",
|
||||
"RenderPointPacket",
|
||||
"ScreenBrushPacket",
|
||||
"SpoutOutputConfig",
|
||||
"frame_to_vertex_array",
|
||||
"lower_frame_to_screen_brushes",
|
||||
"lower_points_to_render_frame",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
from dataclasses import dataclass
|
||||
import ctypes
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
|
@ -22,6 +23,14 @@ class SpoutOutputConfig:
|
|||
demo_point_count: int = 4096
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ScreenBrushPacket:
|
||||
center_px: tuple[int, int]
|
||||
radii_px: tuple[int, int]
|
||||
rotation_deg: float
|
||||
color_rgba: tuple[int, int, int, int]
|
||||
|
||||
|
||||
class RenderFrameFileSource:
|
||||
def __init__(self, path: Path, demo_if_missing: bool = False, demo_point_count: int = 4096) -> None:
|
||||
self.path = path
|
||||
|
|
@ -95,6 +104,54 @@ def frame_to_vertex_array(frame: RenderFramePacket, point_scale: float = 1.0) ->
|
|||
return vertices
|
||||
|
||||
|
||||
def lower_frame_to_screen_brushes(
|
||||
frame: RenderFramePacket,
|
||||
width: int,
|
||||
height: int,
|
||||
point_scale: float = 1.0,
|
||||
) -> tuple[ScreenBrushPacket, ...]:
|
||||
brushes: list[ScreenBrushPacket] = []
|
||||
for point in frame.points:
|
||||
x, y, z = point.xyz
|
||||
px = int(round((0.5 + float(x) * 0.29) * width))
|
||||
py = int(round((0.5 - ((float(z) - 1.18) * 0.575 + float(y) * 0.08)) * height))
|
||||
radius = max(2, int(round(float(point.radius_m) * point_scale * height * 0.75)))
|
||||
if px < -radius * 3 or px >= width + radius * 3 or py < -radius * 3 or py >= height + radius * 3:
|
||||
continue
|
||||
stable = hashlib.blake2s(point.stable_key.encode("utf-8"), digest_size=4).digest()
|
||||
angle = int.from_bytes(stable[:2], "little") / 65535.0 * 180.0
|
||||
stretch = 1.0 + (stable[2] / 255.0) * 1.8
|
||||
radii = (max(2, int(round(radius * stretch))), radius)
|
||||
rgba = np.clip(np.asarray(point.color_rgba, dtype=np.float32), 0.0, 1.0)
|
||||
rgba[3] *= max(0.0, min(1.0, float(point.confidence)))
|
||||
color = tuple(int(v) for v in (rgba * 255.0)[:4])
|
||||
brushes.append(ScreenBrushPacket((px, py), radii, angle, color))
|
||||
return tuple(brushes)
|
||||
|
||||
|
||||
def rasterize_frame_rgba(frame: RenderFramePacket, width: int, height: int, point_scale: float = 1.0) -> np.ndarray:
|
||||
import cv2
|
||||
|
||||
image = np.zeros((height, width, 4), dtype=np.uint8)
|
||||
image[:, :, 0] = 10
|
||||
image[:, :, 1] = 14
|
||||
image[:, :, 2] = 20
|
||||
image[:, :, 3] = 255
|
||||
for brush in lower_frame_to_screen_brushes(frame, width, height, point_scale):
|
||||
cv2.ellipse(
|
||||
image,
|
||||
brush.center_px,
|
||||
brush.radii_px,
|
||||
brush.rotation_deg,
|
||||
0.0,
|
||||
360.0,
|
||||
brush.color_rgba,
|
||||
thickness=-1,
|
||||
lineType=cv2.LINE_AA,
|
||||
)
|
||||
return image
|
||||
|
||||
|
||||
def write_status(
|
||||
path: Path,
|
||||
*,
|
||||
|
|
@ -164,6 +221,7 @@ class OpenGLSpoutPointRenderer:
|
|||
GL_FLOAT,
|
||||
GL_ONE,
|
||||
GL_ONE_MINUS_SRC_ALPHA,
|
||||
GL_PROGRAM_POINT_SIZE,
|
||||
)
|
||||
|
||||
from OpenGL.GL.shaders import compileProgram, compileShader
|
||||
|
|
@ -208,6 +266,7 @@ class OpenGLSpoutPointRenderer:
|
|||
glEnableVertexAttribArray(2)
|
||||
glVertexAttribPointer(2, 1, GL_FLOAT, False, stride, ctypes.c_void_p(28))
|
||||
glEnable(GL_BLEND)
|
||||
glEnable(GL_PROGRAM_POINT_SIZE)
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
def render(self, frame: RenderFramePacket) -> bool:
|
||||
|
|
@ -216,12 +275,15 @@ class OpenGLSpoutPointRenderer:
|
|||
GL_COLOR_BUFFER_BIT,
|
||||
GL_DEPTH_BUFFER_BIT,
|
||||
GL_DYNAMIC_DRAW,
|
||||
GL_FALSE,
|
||||
GL_FRAMEBUFFER,
|
||||
GL_POINTS,
|
||||
GL_RGBA,
|
||||
GL_TEXTURE_2D,
|
||||
GL_TRUE,
|
||||
GL_UNSIGNED_BYTE,
|
||||
glBindBuffer,
|
||||
glBindFramebuffer,
|
||||
glBindTexture,
|
||||
glBindVertexArray,
|
||||
glBufferData,
|
||||
glClear,
|
||||
|
|
@ -231,6 +293,7 @@ class OpenGLSpoutPointRenderer:
|
|||
glGetUniformLocation,
|
||||
glUniform2f,
|
||||
glUniformMatrix4fv,
|
||||
glTexSubImage2D,
|
||||
glUseProgram,
|
||||
glViewport,
|
||||
)
|
||||
|
|
@ -245,16 +308,29 @@ class OpenGLSpoutPointRenderer:
|
|||
vertices = frame_to_vertex_array(frame, self.config.point_scale)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)
|
||||
glViewport(0, 0, self.config.width, self.config.height)
|
||||
glClearColor(0.015, 0.018, 0.022, 1.0)
|
||||
glClearColor(0.025, 0.035, 0.048, 1.0)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
glUseProgram(self.program)
|
||||
view_proj = camera_matrix(time.monotonic(), self.config.width / max(1, self.config.height))
|
||||
glUniformMatrix4fv(glGetUniformLocation(self.program, "u_view_proj"), 1, GL_FALSE, view_proj.astype(np.float32))
|
||||
glUniformMatrix4fv(glGetUniformLocation(self.program, "u_view_proj"), 1, GL_TRUE, view_proj.astype(np.float32))
|
||||
glUniform2f(glGetUniformLocation(self.program, "u_viewport"), float(self.config.width), float(self.config.height))
|
||||
glBindVertexArray(self.vao)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.nbytes, vertices, GL_DYNAMIC_DRAW)
|
||||
glDrawArrays(GL_POINTS, 0, len(vertices))
|
||||
image = rasterize_frame_rgba(frame, self.config.width, self.config.height, self.config.point_scale)
|
||||
glBindTexture(GL_TEXTURE_2D, self.texture)
|
||||
glTexSubImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
self.config.width,
|
||||
self.config.height,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
image,
|
||||
)
|
||||
glFlush()
|
||||
ok = bool(self.sender.sendTexture(self.texture, GL_TEXTURE_2D, self.config.width, self.config.height, False, self.fbo))
|
||||
if ok:
|
||||
|
|
@ -311,9 +387,9 @@ uniform vec2 u_viewport;
|
|||
out vec4 v_color;
|
||||
|
||||
void main() {
|
||||
vec4 clip = u_view_proj * vec4(in_pos, 1.0);
|
||||
gl_Position = clip;
|
||||
float radius_px = max(2.0, in_radius * u_viewport.y / max(0.05, abs(clip.w)) * 2.1);
|
||||
vec2 projected = vec2(in_pos.x * 0.58, (in_pos.z - 1.18) * 1.15 + in_pos.y * 0.16);
|
||||
gl_Position = vec4(projected, 0.0, 1.0);
|
||||
float radius_px = max(5.0, in_radius * u_viewport.y * 2.8);
|
||||
gl_PointSize = radius_px;
|
||||
v_color = in_color;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,3 +37,4 @@
|
|||
{"ts": "2026-05-18T15:22:33+00:00", "type": "decision", "status": "ok", "note": "Runtime mic sync must treat known speaker output as chirplet telemetry every block/frame, updating delay, SRO/rate-scale, phase, and confidence fields dynamically. Static sweep offsets are only initial state; low-confidence runtime chirplet observations should freeze updates rather than corrupt alignment."}
|
||||
{"ts": "2026-05-18T15:23:38+00:00", "type": "decision", "status": "ok", "note": "Active sync probes are now an explicit optimizer responsibility: when passive chirplet telemetry leaves any source below confidence threshold, the system may emit bounded extra chirplets in masked windows, maximizing confidence gain per audible intrusion while respecting spacing and level limits."}
|
||||
{"ts": "2026-05-18T15:35:24+00:00", "type": "verification", "status": "partial", "note": "Passive sync test using Scarlett output loopback as ground-truth content: 20s music run with normalized 4s/1s window correlation produced local Focusrite median delay 20115.5 samples/419.07 ms with 17 sample/0.35 ms MAD; PS Eye left 23848 samples/496.83 ms with 17 sample/0.35 ms MAD; Kiyo-left and PS Eye-right were noisier at about 3.9-4.2 ms MAD. Soundcard WASAPI loopback reported discontinuities, so loopback clock quality remains suspect."}
|
||||
{"ts": "2026-05-18T15:38:07+00:00", "type": "verification", "status": "ok", "note": "OBS puppet pass installed win-spout, enabled local obs-websocket without auth, created Spout2 Capture source LocalCastBridge Point Cloud, and verified a nonblack OBS screenshot from the live Spout sender. Zyphos sample/research shifted the deadline sink from point sprites toward compact anisotropic screen brush packets."}
|
||||
|
|
|
|||
|
|
@ -120,10 +120,11 @@ research:
|
|||
key_decision: >
|
||||
The deadline OBS surface is a real Spout sender named LocalCastBridge
|
||||
Point Cloud. `scripts/stream_spout.py` consumes render-frame packets,
|
||||
renders points into an OpenGL FBO, publishes the texture through SpoutGL,
|
||||
and writes a heartbeat status file. This is a sink boundary, not a new
|
||||
scene authority; Aquarium should replace the renderer body behind the
|
||||
same RenderFramePacket contract for dense brush/splat rendering.
|
||||
lowers them into compact anisotropic screen brush packets inspired by the
|
||||
Zyphos/Aquarium brush model, uploads the texture through SpoutGL, and
|
||||
writes a heartbeat status file. This is a sink boundary, not a new scene
|
||||
authority; Aquarium should replace the renderer body behind the same
|
||||
RenderFramePacket contract for dense brush/splat rendering.
|
||||
sensor_fusion_architecture:
|
||||
summary: docs/sensor-fusion-architecture.md
|
||||
key_decision: >
|
||||
|
|
@ -187,12 +188,15 @@ current_status:
|
|||
source time ranges, intended visual presentation time, audio-alignment
|
||||
time, target render size, Spout sender name, and point draw metadata for
|
||||
Aquarium/Spout. A deadline OBS Spout sender is now live-shaped:
|
||||
`scripts/stream_spout.py` reads render-frame JSON, renders points into an
|
||||
OpenGL FBO, publishes Spout sender `LocalCastBridge Point Cloud`, and writes
|
||||
`calibration/runs/stream-spout-status.json`; a smoke run sent real Spout
|
||||
frames, and the detached sender can run demo packets until live fusion writes
|
||||
`calibration/runs/live-render-frame.json`. Unit tests inject synthetic
|
||||
cameras and frames so the core does not depend on live camera drivers.
|
||||
`scripts/stream_spout.py` reads render-frame JSON, lowers points into
|
||||
compact anisotropic screen brush packets, uploads an OpenGL texture,
|
||||
publishes Spout sender `LocalCastBridge Point Cloud`, and writes
|
||||
`calibration/runs/stream-spout-status.json`; OBS now has a Spout2 Capture
|
||||
source pointed at that sender, and an OBS websocket screenshot verified
|
||||
nonblack brush output. The detached sender can run demo packets until live
|
||||
fusion writes `calibration/runs/live-render-frame.json`. Unit tests inject
|
||||
synthetic cameras and frames so the core does not depend on live camera
|
||||
drivers.
|
||||
next_action: >
|
||||
Capture real ChArUco intrinsics/extrinsics for the PS3 Eyes and Kiyos,
|
||||
replace `config/sensor-fusion.example.json` placeholder transforms with a
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from localcast.sensor_fusion import (
|
|||
SpoutOutputConfig,
|
||||
TrackCache,
|
||||
frame_to_vertex_array,
|
||||
lower_frame_to_screen_brushes,
|
||||
lower_points_to_render_frame,
|
||||
)
|
||||
from localcast.sensor_fusion.adapters import read_raw_bgr_frames
|
||||
|
|
@ -154,6 +155,9 @@ class SensorFusionTests(unittest.TestCase):
|
|||
self.assertEqual((1, 8), vertices.shape)
|
||||
self.assertAlmostEqual(0.10, float(vertices[0, 7]), places=6)
|
||||
self.assertGreater(float(vertices[0, 6]), 0.0)
|
||||
brushes = lower_frame_to_screen_brushes(loaded, width=1920, height=1080, point_scale=2.0)
|
||||
self.assertEqual(1, len(brushes))
|
||||
self.assertGreaterEqual(brushes[0].radii_px[0], brushes[0].radii_px[1])
|
||||
|
||||
def test_spout_output_config_is_importable_without_gpu_context(self):
|
||||
config = SpoutOutputConfig(sender_name="unit-test", width=128, height=72, fps=30)
|
||||
|
|
|
|||
Loading…
Reference in a new issue