Skip to main content

AMBIENT_WGSL

Constant AMBIENT_WGSL 

Source
pub const AMBIENT_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}// Ambient visualization \u{2014} GPU-driven particle field (U2 Viewport)\n// Full 48-byte SystemTelemetry uniform; zero per-frame CPU particle work.\n\nstruct Uniforms {\n    time: f32,\n    view_width: f32,\n    view_height: f32,\n    _padding: f32,\n};\n\n// Matches portal_telemetry::SystemTelemetry (12 \u{d7} f32, WGSL-aligned).\nstruct Telemetry {\n    memory_pressure: f32,\n    network_ripple: f32,\n    baking_crystallization: f32,\n    logic_flashes: f32,\n    llm_heat: f32,\n    quantum_activity: f32,\n    spectral_shift: f32,\n    temporal_pulse: f32,\n    epistemic_density: f32,\n    manifold_pressure: f32,\n    _pad0: f32,\n    _pad1: f32,\n};\n\nstruct ParticleInstance {\n    position: vec3<f32>,\n    epistemic_q: f32,\n};\n\n// Matches portal_telemetry::CameraUniform (128 B). Binding 0 field is `view_projection`\n// for `projector.wgsl`; ambient reads the full block at binding 3.\nstruct Camera {\n    view_projection: mat4x4<f32>,\n    yaw: f32,\n    pitch: f32,\n    zoom: f32,\n    tensor_mode: u32,\n    _padding0: vec4<f32>,\n    _padding1: vec4<f32>,\n    _padding2: vec4<f32>,\n};\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n@group(0) @binding(1) var<uniform> telemetry: Telemetry;\n@group(0) @binding(2) var<storage, read> particles: array<ParticleInstance>;\n@group(0) @binding(3) var<uniform> camera: Camera;\n\nstruct VertexOutput {\n    @builtin(position) position: vec4<f32>,\n    @location(0) color: vec4<f32>,\n    @location(1) local_uv: vec2<f32>,\n    @location(2) epistemic_q: f32,\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 base_vertex = quad_vertices[vertex_index];\n    let particle = particles[instance_index];\n    let base_pos = particle.position;\n    let t = uniforms.time;\n\n    let compression = 1.0 - telemetry.memory_pressure * 0.5;\n    let pos = base_pos * compression;\n\n    let ripple_phase = pos.x * 2.0 + pos.z * 2.0;\n    let ripple = sin(t * 3.0 + ripple_phase) * telemetry.network_ripple * 0.3;\n\n    let chaos = sin(t * 0.5 + pos.x) * cos(t * 0.3 + pos.y) * sin(t * 0.4 + pos.z);\n    let order = floor(pos.x * 2.0) * 0.5 + floor(pos.y * 2.0) * 0.5 + floor(pos.z * 2.0) * 0.5;\n    let morph = mix(chaos, order, telemetry.baking_crystallization);\n\n    let heat_jitter = sin(t * 20.0 + pos.x * 10.0) * telemetry.llm_heat * 0.1;\n    let quantum_flicker = sin(t * 7.0 + f32(instance_index) * 0.05) * telemetry.quantum_activity * 0.08;\n    let temporal_wave = sin(t * 1.5 + length(pos) * 2.0) * telemetry.temporal_pulse * 0.12;\n\n    let animated_pos = pos + vec3<f32>(\n        ripple + heat_jitter + quantum_flicker,\n        morph + heat_jitter + temporal_wave,\n        ripple + heat_jitter\n    );\n\n    var output: VertexOutput;\n    if (camera.tensor_mode != 0u) {\n        let clip = camera.view_projection * vec4<f32>(animated_pos, 1.0);\n        let inv_w = 1.0 / max(abs(clip.w), 1e-4);\n        let ndc = clip.xyz * inv_w;\n        let particle_size = 0.018 * (1.0 + telemetry.llm_heat * 0.5) / max(abs(clip.w), 0.35);\n        output.position = vec4<f32>(\n            ndc.x + base_vertex.x * particle_size,\n            ndc.y + base_vertex.y * particle_size,\n            ndc.z,\n            1.0\n        );\n    } else {\n        let fov = 1.0;\n        let z_depth = 5.0 + animated_pos.z;\n        let scale = fov / max(z_depth, 0.1);\n        let aspect = uniforms.view_width / max(uniforms.view_height, 1.0);\n        let screen_x = animated_pos.x * scale / aspect;\n        let screen_y = animated_pos.y * scale;\n        let particle_size = 0.02 * scale * (1.0 + telemetry.llm_heat * 0.5);\n        let final_x = screen_x + base_vertex.x * particle_size;\n        let final_y = screen_y + base_vertex.y * particle_size;\n        output.position = vec4<f32>(final_x, final_y, 0.0, 1.0);\n    }\n    output.local_uv = base_vertex;\n\n    let sigma = fract(telemetry.spectral_shift + f32(instance_index) * 0.0017);\n    let linear_spectral = sigma_to_linear_rgb(sigma);\n    let ripple_energy = vec3<f32>(0.02, 0.08, 0.08) * telemetry.network_ripple;\n    let heat_energy = vec3<f32>(0.12, 0.10, 0.08) * telemetry.llm_heat;\n    let flash = step(0.9, sin(t * 10.0 + f32(instance_index) * 0.1)) * telemetry.logic_flashes;\n    let flash_energy = vec3<f32>(0.18, 0.16, 0.12) * flash;\n    let density_gain = 0.35 + telemetry.epistemic_density * 0.25;\n\n    let rgb = linear_spectral * density_gain + ripple_energy + heat_energy + flash_energy;\n    output.color = vec4<f32>(rgb, 0.6 + telemetry.llm_heat * 0.4);\n    output.epistemic_q = particle.epistemic_q;\n\n    return output;\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 glow = 1.0 - dist;\n    let glow_intensity = glow * glow;\n    let collapsed = step(input.epistemic_q, 0.001);\n    let sandbox = 1.0 - collapsed;\n    let certainty_opacity = mix(0.45, 1.0, collapsed);\n    let sandbox_pulse = 0.85 + 0.15 * sin(input.epistemic_q * 12.0);\n    let epistemic_alpha = mix(certainty_opacity * sandbox_pulse, certainty_opacity, collapsed);\n    let ring_boost = select(0.0, 0.35 * smoothstep(0.7, 1.0, dist), sandbox > 0.5);\n    // HDR epistemic density + llm_heat drive bloom extraction.\n    let hdr_gain = 1.0 + telemetry.epistemic_density * 0.65 + telemetry.llm_heat * 0.45;\n    let final_color = input.color.rgb * hdr_gain * (1.0 + glow_intensity * 0.5 + ring_boost);\n    let final_alpha = input.color.a * alpha * epistemic_alpha;\n    return vec4<f32>(final_color, final_alpha);\n}\n";