Constant PROJECTOR_WGSL
Source pub const PROJECTOR_WGSL: &str = "// \u{3c3} \u{2192} CIE 1931 XYZ \u{2192} linear sRGB (shared by projector + ambient).\n// HDR scene path: no sRGB gamma encode \u{2014} bloom composite applies Reinhard.\n\nfn sigma_to_cie_xyz(sigma: f32) -> vec3<f32> {\n let s = fract(sigma);\n let lambda = 400.0 + (s * 300.0);\n\n let x1 = 1.056 * exp(-0.5 * pow((lambda - 599.8) / 43.2, 2.0));\n let x2 = 0.362 * exp(-0.5 * pow((lambda - 442.0) / 32.0, 2.0));\n let x3 = -0.065 * exp(-0.5 * pow((lambda - 501.1) / 20.4, 2.0));\n let X = x1 + x2 + x3;\n\n let y1 = 0.821 * exp(-0.5 * pow((lambda - 568.8) / 46.9, 2.0));\n let y2 = 0.286 * exp(-0.5 * pow((lambda - 530.9) / 16.3, 2.0));\n let Y = y1 + y2;\n\n let z1 = 1.217 * exp(-0.5 * pow((lambda - 437.0) / 11.8, 2.0));\n let z2 = 0.681 * exp(-0.5 * pow((lambda - 459.0) / 26.0, 2.0));\n let Z = z1 + z2;\n\n return vec3<f32>(X, Y, Z);\n}\n\nfn xyz_to_linear_srgb(xyz: vec3<f32>) -> vec3<f32> {\n let R = 3.2404542 * xyz.x - 1.5371385 * xyz.y - 0.4985314 * xyz.z;\n let G = -0.9692660 * xyz.x + 1.8760108 * xyz.y + 0.0415560 * xyz.z;\n let B = 0.0556434 * xyz.x - 0.2040259 * xyz.y + 1.0572252 * xyz.z;\n return max(vec3<f32>(R, G, B), vec3<f32>(0.0));\n}\n\nfn sigma_to_linear_rgb(sigma: f32) -> vec3<f32> {\n return xyz_to_linear_srgb(sigma_to_cie_xyz(sigma));\n}// Tensor SOA projector \u{2014} 10D structural nodes with depth (Track C phenomenal viewport).\n//\n// Object space: P\' = \u{3a9} P \u{3a9}\u{303} (3D PGA sandwich) \u{b7} clip = camera.view_projection \u{b7} P\'\n// Phase 2b: dual-quaternion motor \u{2014} d=0 regresses to Phase 1 quaternion path\n// Phase 2c: bilateral T_pull via motor d channel (tensor.mu = deontic lane)\n// Phase 3: v-band topology (cyclic / hyperbolic / boundary clique anchor)\n//\n// @group(0) camera + observer \u{b7} @group(1) tensor SOA (offset past 32 B header)\n\nstruct Camera {\n view_projection: mat4x4<f32>,\n yaw: f32,\n pitch: f32,\n zoom: f32,\n tensor_mode: u32,\n // _padding0.x = frame time; _padding0.yzw = camera eye xyz for T_pull.\n _padding0: vec4<f32>,\n _padding1: vec4<f32>,\n _padding2: vec4<f32>,\n};\n\n// Matches portal_telemetry::ObserverStandpoint (128 B). u64 fields as vec2<u32> LE.\nstruct ObserverStandpoint {\n standpoint_hash: vec2<u32>,\n session_nonce: vec2<u32>,\n epistemic_q: f32,\n t_slice: f32,\n t_window: f32,\n deontic_lane: u32,\n standpoint_class: u32,\n fabric_gate: u32,\n _padding0: vec2<f32>,\n _padding1: vec4<f32>,\n _padding2: vec4<f32>,\n _padding3: vec4<f32>,\n _padding4: vec4<f32>,\n _padding5: vec4<f32>,\n};\n\n// Matches Tensor10D SOA stride (40 B).\nstruct Tensor10D {\n q: f32,\n v: f32,\n w: f32,\n x: f32,\n y: f32,\n z: f32,\n t: f32,\n alpha: f32,\n mu: f32,\n sigma: f32,\n};\n\n// 3D PGA motor \u{2014} rotation (r) + translation (d). Phase 1 uses r only.\nstruct Motor {\n r: vec4<f32>, // scalar + e12, e13, e23\n d: vec4<f32>, // e0123 + e01, e02, e03 (identity in Phase 1)\n};\n\n@group(0) @binding(0) var<uniform> camera: Camera;\n@group(0) @binding(1) var<uniform> observer: ObserverStandpoint;\n@group(1) @binding(0) var<storage, read> tensors: array<Tensor10D>;\n\nstruct VertexOutput {\n @builtin(position) clip_position: vec4<f32>,\n @location(0) color: vec4<f32>,\n @location(1) local_uv: vec2<f32>,\n @location(2) epistemic_q: f32,\n @location(3) v_band: f32,\n @location(4) alpha_gain: f32,\n // Dawn (WebGPU) rejects non-flat integral inter-stage outputs; naga (native) is lenient.\n @location(5) @interpolate(flat) pick_id: u32,\n};\n\nconst TWO_PI: f32 = 6.283185307;\nconst MANIFOLD_COUNT: f32 = 5.0;\nconst Q_COLLAPSED_EPS: f32 = 0.001;\n\n// Human-Centric observer standpoint classes (portal_telemetry.rs)\nconst STANDPOINT_SPECTATOR: u32 = 0u;\nconst STANDPOINT_EPHEMERAL: u32 = 1u;\nconst STANDPOINT_IDENTIFIER: u32 = 2u;\nconst STANDPOINT_VAULT: u32 = 3u;\n\nconst DEONTIC_LANE_BILATERAL: u32 = 2u;\nconst T_PULL_GAIN: f32 = 0.12;\nconst CLUSTER_COUNT: u32 = 8u;\nconst T_RADIAL_GAIN: f32 = 0.06;\nconst ANCHOR_RING_RADIUS: f32 = 0.35;\nconst T_SCALE: f32 = 2.0;\n\n// \u{3c3} \u{2192} linear sRGB via spectral.wgsl (prepended by mod.rs)\n\n// \u{2500}\u{2500} Cl(3,0) rotor as vec4(s, e12, e13, e23) \u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\n\nfn rotor_identity() -> vec4<f32> {\n return vec4<f32>(1.0, 0.0, 0.0, 0.0);\n}\n\nfn motor_identity() -> Motor {\n return Motor(rotor_identity(), vec4<f32>(0.0));\n}\n\nfn rotor_from_axis_angle(axis: vec3<f32>, angle: f32) -> vec4<f32> {\n let half = angle * 0.5;\n let c = cos(half);\n let s = sin(half);\n // R = cos(\u{3b8}/2) + sin(\u{3b8}/2)(ax\u{b7}e23 - ay\u{b7}e13 + az\u{b7}e12) (right-handed Cl(3,0))\n return vec4<f32>(c, s * (-axis.z), s * axis.y, s * (-axis.x));\n}\n\nfn rotor_mul(a: vec4<f32>, b: vec4<f32>) -> vec4<f32> {\n return vec4<f32>(\n a.x * b.x - a.y * b.y - a.z * b.z - a.w * b.w,\n a.x * b.y + a.y * b.x + a.z * b.w - a.w * b.z,\n a.x * b.z - a.y * b.w + a.z * b.x + a.w * b.y,\n a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x\n );\n}\n\nfn rotor_reverse(r: vec4<f32>) -> vec4<f32> {\n return vec4<f32>(r.x, -r.y, -r.z, -r.w);\n}\n\n// Map Cl(3,0) rotor \u{2192} quaternion (w, x, y, z) for sandwich on grade-1 vectors.\nfn rotor_to_quat(r: vec4<f32>) -> vec4<f32> {\n return vec4<f32>(r.x, -r.w, -r.z, -r.y);\n}\n\nfn quat_mul(a: vec4<f32>, b: vec4<f32>) -> vec4<f32> {\n return vec4<f32>(\n a.x * b.x - a.y * b.y - a.z * b.z - a.w * b.w,\n a.x * b.y + a.y * b.x + a.z * b.w - a.w * b.z,\n a.x * b.z - a.y * b.w + a.z * b.x + a.w * b.y,\n a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x\n );\n}\n\nfn quat_to_blade4(q: vec4<f32>) -> vec4<f32> {\n return vec4<f32>(q.x, -q.w, -q.z, -q.y);\n}\n\nfn quat_conj(q: vec4<f32>) -> vec4<f32> {\n return vec4<f32>(q.x, -q.y, -q.z, -q.w);\n}\n\nfn quat_add(a: vec4<f32>, b: vec4<f32>) -> vec4<f32> {\n return a + b;\n}\n\n// PGA reversion: flip bivector signs; scalar + pseudoscalar stay positive.\nfn motor_reverse(m: Motor) -> Motor {\n return Motor(\n vec4<f32>(m.r.x, -m.r.y, -m.r.z, -m.r.w),\n vec4<f32>(m.d.x, -m.d.y, -m.d.z, -m.d.w)\n );\n}\n\n// Dual-quaternion product (qr1, qd1) \u{2297} (qr2, qd2).\nfn motor_mul(a: Motor, b: Motor) -> Motor {\n let qr1 = rotor_to_quat(a.r);\n let qd1 = rotor_to_quat(a.d);\n let qr2 = rotor_to_quat(b.r);\n let qd2 = rotor_to_quat(b.d);\n let qr3 = quat_mul(qr1, qr2);\n let qd3 = quat_add(quat_mul(qr1, qd2), quat_mul(qd1, qr2));\n return Motor(quat_to_blade4(qr3), quat_to_blade4(qd3));\n}\n\nfn motor_translate(v: vec3<f32>) -> Motor {\n let half = vec4<f32>(0.0, v.x * 0.5, v.y * 0.5, v.z * 0.5);\n return Motor(vec4<f32>(1.0, 0.0, 0.0, 0.0), quat_to_blade4(half));\n}\n\nfn tensor_deontic_lane(mu: f32) -> u32 {\n return u32(round(mu));\n}\n\nfn bilateral_pull_active(tensor_mu: f32, standpoint_class: u32) -> bool {\n return tensor_deontic_lane(tensor_mu) == DEONTIC_LANE_BILATERAL\n && standpoint_class >= STANDPOINT_IDENTIFIER;\n}\n\nfn pull_vector(node: vec3<f32>, camera_eye: vec3<f32>, alpha: f32, epistemic_q: f32) -> vec3<f32> {\n let dir = camera_eye - node;\n let len = length(dir);\n if (len < 1e-6) {\n return vec3<f32>(0.0);\n }\n let gain = clamp(alpha, 0.2, 1.0);\n let delta = T_PULL_GAIN * gain * clamp(epistemic_q, 0.0, 1.0);\n return (dir / len) * delta;\n}\n\n// PGA null point P = e0 + x\u{b7}e1 + y\u{b7}e2 + z\u{b7}e3 \u{2014} P\' = r P r\u{303} + 2(d r\u{303}) vector part.\n// When d = 0, \u{3b5} terms vanish \u{2192} exact Phase 1 quaternion sandwich.\nfn sandwich_point(m: Motor, p: vec3<f32>) -> vec3<f32> {\n let qr = rotor_to_quat(m.r);\n let qd = rotor_to_quat(m.d);\n let qr_conj = quat_conj(qr);\n let p_q = vec4<f32>(0.0, p.x, p.y, p.z);\n let p_rot = quat_mul(quat_mul(qr, p_q), qr_conj);\n let t_q = quat_mul(qd, qr_conj);\n return vec3<f32>(\n p_rot.y + T_SCALE * t_q.y,\n p_rot.z + T_SCALE * t_q.z,\n p_rot.w + T_SCALE * t_q.w\n );\n}\n\nfn cluster_id_from_sigma(sigma: f32) -> u32 {\n let frac = fract(sigma);\n return u32(floor(frac * f32(CLUSTER_COUNT))) % CLUSTER_COUNT;\n}\n\nfn cluster_centroid_lattice(cluster_id: u32) -> vec3<f32> {\n let k = cluster_id % CLUSTER_COUNT;\n let angle = f32(k) * TWO_PI / f32(CLUSTER_COUNT);\n return vec3<f32>(ANCHOR_RING_RADIUS * cos(angle), 0.0, ANCHOR_RING_RADIUS * sin(angle));\n}\n\n// Phase 3 v-band: [0,1) Euclidean \u{b7} [1,2) cyclic \u{b7} [2,3) hyperbolic \u{b7} [3,\u{221e}) boundary clique.\nfn motor_v_band(v: f32, node: vec3<f32>, sigma: f32, time: f32, alpha: f32) -> Motor {\n let gain = clamp(alpha, 0.2, 1.0);\n if (v < 1.0) {\n return motor_identity();\n }\n if (v < 2.0) {\n let band = v - 1.0;\n let theta = band * TWO_PI * sin(time * 0.5 + sigma) * gain;\n return Motor(rotor_from_axis_angle(vec3<f32>(0.0, 1.0, 0.0), theta), vec4<f32>(0.0));\n }\n if (v < 3.0) {\n let band = v - 2.0;\n let len = max(length(node), 1e-4);\n let dir = node / len;\n let delta = T_RADIAL_GAIN * band * gain;\n return motor_translate(dir * delta);\n }\n let centroid = cluster_centroid_lattice(cluster_id_from_sigma(sigma));\n let blend = min(v - 3.0, 1.0) * gain;\n return motor_translate((centroid - node) * blend);\n}\n\nfn motor_rw(w: f32, alpha: f32) -> vec4<f32> {\n let theta_w = w * (TWO_PI / MANIFOLD_COUNT);\n let gain = clamp(alpha, 0.2, 1.0);\n return rotor_from_axis_angle(vec3<f32>(0.0, 1.0, 0.0), theta_w * gain);\n}\n\n// Phase 2a: Human-Centric standpoint gates on epistemic spin (quaternion slice retained).\n// Vault \u{2192} freeze R_q. Identifier (DID) \u{2192} dampen \u{3b8}_q by observer.epistemic_q (certainty aperture).\nfn motor_rq(q: f32, sigma: f32, time: f32, alpha: f32, obs: ObserverStandpoint) -> vec4<f32> {\n if (obs.standpoint_class == STANDPOINT_VAULT) {\n return rotor_identity();\n }\n if (q <= Q_COLLAPSED_EPS) {\n return rotor_identity();\n }\n let gain = clamp(alpha, 0.2, 1.0);\n var theta_q = q * sin(time * 2.0 + sigma * TWO_PI) * gain;\n if (obs.standpoint_class == STANDPOINT_IDENTIFIER) {\n // Dampen spin amplitude \u{2014} lower epistemic_q = slower, tighter orbital bound.\n theta_q = theta_q * clamp(obs.epistemic_q, 0.0, 1.0);\n }\n let ax = cos(sigma * TWO_PI);\n let az = sin(sigma * TWO_PI);\n let len = max(sqrt(ax * ax + az * az), 1e-4);\n let axis = vec3<f32>(ax / len, 0.0, az / len);\n return rotor_from_axis_angle(axis, theta_q);\n}\n\nfn semantic_motor_intrinsic(tensor: Tensor10D, time: f32, obs: ObserverStandpoint, node: vec3<f32>) -> Motor {\n let r_v = motor_v_band(tensor.v, node, tensor.sigma, time, tensor.alpha);\n let r_w = motor_rw(tensor.w, tensor.alpha);\n let r_q = motor_rq(tensor.q, tensor.sigma, time, tensor.alpha, obs);\n return motor_mul(Motor(r_w, vec4<f32>(0.0)), motor_mul(Motor(r_q, vec4<f32>(0.0)), r_v));\n}\n\n// Phase 2c: \u{3a9} = T_pull \u{b7} (R_w \u{b7} R_q) \u{2014} subjective bilateral bias after intrinsic motors.\nfn semantic_motor(tensor: Tensor10D, time: f32, obs: ObserverStandpoint, node: vec3<f32>, camera_eye: vec3<f32>) -> Motor {\n let r_intrinsic = semantic_motor_intrinsic(tensor, time, obs, node);\n var t_motor = motor_identity();\n if (bilateral_pull_active(tensor.mu, obs.standpoint_class)) {\n t_motor = motor_translate(pull_vector(node, camera_eye, tensor.alpha, obs.epistemic_q));\n }\n return motor_mul(t_motor, r_intrinsic);\n}\n\nfn apply_semantic_motor(local: vec3<f32>, tensor: Tensor10D, time: f32, obs: ObserverStandpoint, camera_eye: vec3<f32>) -> vec3<f32> {\n let omega = semantic_motor(tensor, time, obs, local, camera_eye);\n return sandwich_point(omega, local);\n}\n\n@vertex\nfn vertex_main(\n @builtin(vertex_index) vertex_index: u32,\n @builtin(instance_index) instance_index: u32\n) -> VertexOutput {\n let quad_vertices = array<vec2<f32>, 6>(\n vec2<f32>(-1.0, -1.0),\n vec2<f32>(1.0, -1.0),\n vec2<f32>(-1.0, 1.0),\n vec2<f32>(-1.0, 1.0),\n vec2<f32>(1.0, -1.0),\n vec2<f32>(1.0, 1.0)\n );\n\n let tensor = tensors[instance_index];\n let frame_time = camera._padding0.x;\n let camera_eye = camera._padding0.yzw;\n\n // Temporal scrub \u{2014} smooth spawn/decay \u{3b1} ramp.\n let temporal_delta = abs(tensor.t - observer.t_slice);\n let ramp_width = observer.t_window * 0.2; // 20% fade on the edges\n let time_dist_to_edge = observer.t_window - temporal_delta;\n let alpha_fade = smoothstep(0.0, ramp_width, time_dist_to_edge);\n let outside_time = alpha_fade <= 0.0;\n\n let local = vec3<f32>(tensor.x, tensor.y, tensor.z);\n let world_pos = apply_semantic_motor(local, tensor, frame_time, observer, camera_eye);\n let clip = camera.view_projection * vec4<f32>(world_pos, 1.0);\n\n let base_vertex = quad_vertices[vertex_index];\n let point_scale = 0.012 * (0.65 + tensor.alpha * 0.55);\n\n var output: VertexOutput;\n output.v_band = tensor.v;\n output.alpha_gain = tensor.alpha;\n if (outside_time) {\n output.clip_position = vec4<f32>(0.0, 0.0, 2.0, 1.0);\n } else {\n output.clip_position = vec4<f32>(\n clip.x + base_vertex.x * point_scale * clip.w,\n clip.y + base_vertex.y * point_scale * clip.w,\n clip.z,\n clip.w\n );\n }\n output.local_uv = base_vertex;\n let rgb = sigma_to_linear_rgb(tensor.sigma);\n let alpha = clamp(0.4 + tensor.alpha * 0.55, 0.25, 1.0) * alpha_fade;\n output.color = vec4<f32>(rgb, alpha);\n output.epistemic_q = tensor.q;\n output.pick_id = instance_index;\n return output;\n}\n\n// PR-C11: R32Uint picking pass \u{2014} outputs tensor SOA index per pixel.\n@fragment\nfn picking_fragment_main(input: VertexOutput) -> @location(0) u32 {\n let dist = length(input.local_uv);\n if (dist > 1.0) {\n discard;\n }\n return input.pick_id;\n}\n\n@fragment\nfn fragment_main(input: VertexOutput) -> @location(0) vec4<f32> {\n let dist = length(input.local_uv);\n let alpha = smoothstep(1.0, 0.0, dist);\n let collapsed = step(input.epistemic_q, 0.001);\n let sandbox = 1.0 - collapsed;\n let certainty_opacity = mix(0.35, 1.0, collapsed);\n let sandbox_pulse = 0.8 + 0.2 * sin(input.epistemic_q * 14.0);\n let epistemic_alpha = mix(certainty_opacity * sandbox_pulse, certainty_opacity, collapsed);\n let ring_boost = select(0.0, 0.4 * smoothstep(0.75, 1.0, dist), sandbox > 0.5);\n // HDR \u{3c3}\u{2192}CIE luminance: \u{3b1} gain + boundary-clique density boost for bloom threshold.\n var hdr_gain = (0.75 + input.alpha_gain * 1.1) * (1.0 + ring_boost);\n if (input.v_band >= 3.0) {\n hdr_gain = hdr_gain * (1.0 + 0.45 * min(input.v_band - 3.0, 1.0));\n }\n let rgb = input.color.rgb * hdr_gain;\n return vec4<f32>(rgb, input.color.a * alpha * epistemic_alpha);\n}\n";