언어 참조 › 함수 acos 함수 아크코사인은 코사인 값에 대응하는 각도를 라디안으로 구하는 역함수입니다. 결과는 정해진 주값 범위에 속합니다. 함수 그래프y = acos(x) y = 3.5 y = -0.25 x = -1 x = 1 초기화파란 곡선은 출력이고, 주황색 점은 선택한 입력의 위치입니다. 휠로 확대·축소하고 드래그로 이동한다. 3D에서는 드래그로 회전한다. 키보드: 방향키, +/-, Home으로 초기화.축 옆에 표시한 범위만 그립니다. 이 범위 밖의 값은 화면에 나타나지 않습니다. 입력 변화 관찰 x가 왼쪽에서 오른쪽으로 증가할수록 출력 각도는 감소합니다. 전체 셰이더 코드 코드 수정 Playground에서 열기 acos-plot.shade.ts"use typeshade"; import { PlotUniforms, plot2D, plot3D } from "./function-plot.shade.ts"; class Uniforms extends PlotUniforms {}declare const u: uniform<Uniforms>; // Inputs outside the mathematical domain are omitted, including after pan or zoom.function sample(x: f32): f32 { if (abs(x) > 1.) { return 1e20; } return acos(x);} function trajectory(t: f32): vec3 { return vec3(t, sample(t), 0.);} @fragmentexport function main(uv: location<0, vec2>): vec4 { const flat = plot2D(sample, uv, u, false); if (u.plotBlend <= 0.) { return flat; } const space = plot3D(trajectory, uv, u, false); return mix(flat, space, clamp(u.plotBlend, 0., 1.));} function-plot.shade.ts function-plot.shade.ts… "use typeshade"; import { glyphCoverage, glyphLayers, tickNumberLayers, numberPlate, numberWidth, tickLevels, tickOpacity, coarseTickOpacity, pixelWidth, tickMark } from "./font.shade.ts"; import { colorMap } from "./palette.shade.ts"; /** Host-controlled viewport, in data units; rotation is yaw/pitch in radians. */ export class PlotViewport { resolution: vec2; plotCenter: vec2; plotSpan: vec2; plotRotation: vec2; rotationBasis: vec4; plotPan: vec2; plotBlend: f32; appearance: vec4; decorations: u32; labelStyle: vec4; decorationOpacity: vec3; } export class PlotUniforms extends PlotViewport { model: mat4; inverseModel: mat4; axesModel: mat4; inverseAxesModel: mat4; sceneOpacity: vec2; cameraLens: vec2; plotCenterZ: f32; probe: f32; parameterFocusSeed: f32; view3d: u32; parameterBounds: vec2; parameterMode: u32; curveQuality: vec2u; curvePattern: vec4; curveTiles: vec4u; surfaceBounds: vec4; surfaceDomainMode: u32; surfaceRange: vec2; surfaceHeight: vec2; surfaceDepth: vec2; surfaceRender: vec4; surfaceFlags: u32; } /** Coordinate-frame fields use their own matrix while the callback remains in content space. */ export function axesUniforms(u: PlotUniforms): PlotUniforms { return { resolution: u.resolution, plotCenter: u.plotCenter, plotSpan: u.plotSpan, plotRotation: u.plotRotation, rotationBasis: u.rotationBasis, plotPan: u.plotPan, plotBlend: u.plotBlend, appearance: u.appearance, decorations: u.decorations, labelStyle: u.labelStyle, decorationOpacity: u.decorationOpacity, model: u.axesModel, inverseModel: u.inverseAxesModel, axesModel: u.axesModel, inverseAxesModel: u.inverseAxesModel, sceneOpacity: u.sceneOpacity, cameraLens: u.cameraLens, plotCenterZ: u.plotCenterZ, probe: u.probe, parameterFocusSeed: u.parameterFocusSeed, view3d: u.view3d, parameterBounds: u.parameterBounds, parameterMode: u.parameterMode, curveQuality: u.curveQuality, curvePattern: u.curvePattern, curveTiles: u.curveTiles, surfaceBounds: u.surfaceBounds, surfaceDomainMode: u.surfaceDomainMode, surfaceRange: u.surfaceRange, surfaceHeight: u.surfaceHeight, surfaceDepth: u.surfaceDepth, surfaceRender: u.surfaceRender, surfaceFlags: u.surfaceFlags }; } declare const curveIntervals: texture_2d<u32>; declare const curveSeeds: texture_2d<u32>; declare const curveCandidates: texture_2d<u32>; declare const curveGroups: texture_2d<u32>; declare const spatialLabels: texture_2d<u32>; function labelRecord(at: vec2i): vec4 {return bitcast<vec4>(textureLoad(spatialLabels,at,0));} function curveRecord(at: vec2i): vec4 {return bitcast<vec4>(textureLoad(curveIntervals,at,0));} function seedRecord(at: vec2i): vec4 {return bitcast<vec4>(textureLoad(curveSeeds,at,0));} type ScalarCurve = (x: f32) => f32; type SpaceCurve = (t: f32) => vec3; type HeightField = (x: f32, z: f32) => f32; export class PickUniforms { pixel: vec2; radius: f32; } declare const query: uniform<PickUniforms>; /** Axis names use the same compact plate as single-character numeric labels. */ export function axisLabel(pixel: vec2, at: vec2, code: i32, u: PlotViewport): vec3 { if (any(abs(pixel - at) > vec2(u.appearance.w * 1.5 + 4 + pixelWidth()))) return vec3(0); const local = vec2(pixel.x - at.x, at.y - pixel.y + u.appearance.w * 0.75); return vec3(glyphLayers(local + vec2(u.appearance.w * 0.42, 0), code, u.appearance.w, u.labelStyle.y), numberPlate(local, 0, 1, 0.5, u.appearance.w) * u.labelStyle.z); } /** CSS-pixel layout keeps line widths and text stable across sizes and display density. */ export function plotSize(resolution: vec2): vec2 { return max(resolution, vec2(1)); } export function distanceCoverage(distance: f32, width: f32): f32 { if (width <= 0) return 0; const aa = pixelWidth() * 0.5; return 1 - smoothstep(max(0, width * 0.5 - aa), width * 0.5 + aa, distance); } function stroke(p: vec2, a: vec2, b: vec2, width: f32): f32 { const radius = width * 0.5; if (width <= 0 || any(p < min(a, b) - vec2(radius + 1)) || any(p > max(a, b) + vec2(radius + 1))) return 0; const ab = b - a; const t = clamp(dot(p - a, ab) / max(dot(ab, ab), 0.0001), 0, 1); return distanceCoverage(length(p - a - ab * t), width); } /** SDF labels share the font and antialiasing used by the data renderer. */ function glyph(p: vec2, origin: vec2, axis: i32, size: f32): f32 { return glyphCoverage(vec2(p.x - origin.x + size * 0.42, origin.y - p.y + size * 0.75), 120 + axis, size); } function axisLevels(center: f32, span: f32, pixels: f32, horizontal: bool, u: PlotViewport): vec3 { const size = u.appearance.w; const rough = span * size * 4 / max(pixels, 1); const width = max(numberWidth(center - span * 0.5, rough, size), numberWidth(center + span * 0.5, rough, size)); const gap = horizontal ? max(size * 3.5, width + size * 1.3) : size * 2.6; return tickLevels(span * gap / max(pixels * u.labelStyle.x, 1)); } function numberAt(pixel: vec2, anchor: vec2, value: f32, spacing: f32, align: f32, size: f32, halo: f32, plate: f32): vec3 { const delta = vec2(pixel.x - anchor.x, anchor.y - pixel.y); if (delta.y < 0 || delta.y > size * 1.5 || abs(delta.x) > size * 16) return vec3(0); return vec3(tickNumberLayers(delta, value, spacing, align, size, halo), numberPlate(delta, value, spacing, align, size) * plate); } function labelColor(color: vec3, labels: vec3): vec3 { const plated = mix(color, vec3(0.995), labels.z * 0.94); return mix(mix(plated, vec3(0.965, 0.973, 0.985), labels.y), vec3(0.25, 0.29, 0.35), labels.x); } function pointColor(color: vec3, p: vec2, selected: vec2): vec3 { if (any(abs(p - selected) > vec2(7))) return color; const radius = length(p - selected); const halo = 1 - smoothstep(5, 7, radius); const dot = 1 - smoothstep(3, 4.5, radius); return mix(mix(color, vec3(1), halo), vec3(0.89, 0.29, 0.04), dot); } /** Shared spines, data ticks and axis glyphs for all two-dimensional plot styles. */ function axes2D(uv: vec2, u: PlotViewport, vertical: i32): vec4 { const size = plotSize(u.resolution); const span = max(u.plotSpan, vec2(0.00001)); const lo = u.plotCenter - span * 0.5; const p = lo + uv * span; const pixel = uv * size; // When zero is outside the viewport, a boundary spine marks the visible frame. const origin = clamp((-lo / span) * size, vec2(14), size - vec2(14)); let axes = max( stroke(pixel, vec2(12, origin.y), vec2(size.x - 12, origin.y), u.appearance.x), stroke(pixel, vec2(origin.x, 12), vec2(origin.x, size.y - 12), u.appearance.x), ); const xLevels = axisLevels(u.plotCenter.x, span.x, size.x, true, u); const yLevels = axisLevels(u.plotCenter.y, span.y, size.y, false, u); let labels = vec3(0); let backgroundGrid = 0; for (let level = 0; level < 2; level++) { const tickStep = level == 0 ? vec2(xLevels.x, yLevels.x) : vec2(xLevels.y, yLevels.y); const nearest = floor(p / tickStep + 0.5) * tickStep; const weights = level == 0 ? vec2(tickOpacity(nearest.x, xLevels), tickOpacity(nearest.y, yLevels)) : vec2(coarseTickOpacity(nearest.x, xLevels), coarseTickOpacity(nearest.y, yLevels)); const grid = abs(p - nearest) / span * size; const at = (nearest - lo) / span * size; axes = max(axes, max( tickMark(pixel, vec2(at.x, origin.y), vec2(1, 0), 4, u.appearance.x) * weights.x, tickMark(pixel, vec2(origin.x, at.y), vec2(0, 1), 4, u.appearance.x) * weights.y )); backgroundGrid = max(backgroundGrid, max(distanceCoverage(grid.x, u.appearance.y) * weights.x, distanceCoverage(grid.y, u.appearance.y) * weights.y)); const width = numberWidth(nearest.x, xLevels.x, u.appearance.w); const xFit = smoothstep(width + 6, width + 14, tickStep.x / span.x * size.x); const yFit = smoothstep(u.appearance.w * 1.6, u.appearance.w * 2.2, tickStep.y / span.y * size.y); if ((u.decorations & u32(2)) != u32(0) && at.x > width * 0.5 + 6 && at.x < size.x - width * 0.5 - 6) labels = max(labels, numberAt(pixel, vec2(at.x, origin.y < u.appearance.w * 2 ? origin.y + u.appearance.w * 2 : origin.y - u.appearance.w * 0.65), nearest.x, xLevels.x, 0.5, u.appearance.w, u.labelStyle.y, u.labelStyle.z) * weights.x * xFit); if ((u.decorations & u32(2)) != u32(0) && at.y > 25 && at.y < size.y - 25 && abs(nearest.y) > yLevels.x * 0.001) labels = max(labels, numberAt(pixel, vec2(origin.x < u.appearance.w * 6 ? origin.x + 8 : origin.x - 8, at.y + u.appearance.w * 0.75), nearest.y, yLevels.x, origin.x < u.appearance.w * 6 ? 0 : 1, u.appearance.w, u.labelStyle.y, u.labelStyle.z) * weights.y * yFit); } labels *= u.decorationOpacity.y; if ((u.decorations & u32(4)) != u32(0)) labels = max(labels, axisLabel(pixel, vec2(size.x - 12, clamp(origin.y + 30, 40, size.y - 40)), 120, u) * u.decorationOpacity.z); if ((u.decorations & u32(4)) != u32(0)) labels = max(labels, axisLabel(pixel, vec2(clamp(origin.x + 14, 28, size.x - 28), size.y - 40), vertical, u) * u.decorationOpacity.z); // The same data-space ticks define the grid; no host-generated line geometry. return vec4(max(axes, ((u.decorations & u32(1)) != u32(0) ? backgroundGrid * 0.2 * u.decorationOpacity.x : 0)), labels); } function curveCoverage(p: vec2, value: f32, span: vec2, size: vec2, thickness: f32): f32 { // Clamp infinities before taking derivatives. A comparison also rejects a NaN result. const d = (p.y - clamp(value, -1e18, 1e18)) / span.y; const width = max(1 / size.y, min(fwidth(d), 0.025)); return abs(value) < 1e18 ? 1 - smoothstep(0, width * thickness, abs(d)) : 0; } /** Filled scalar graph with a quarter-unit grid and the reference diagonal y = x. */ export function plotFilled(sample: ScalarCurve, uv: vec2, u: PlotViewport): vec4 { const span = max(u.plotSpan, vec2(0.00001)); const p = u.plotCenter + (uv - 0.5) * span; const size = plotSize(u.resolution); const value = sample(p.x); const d = (p.y - clamp(value, -1e18, 1e18)) / span.y; const width = max(fwidth(d), 1 / size.y); const fill = abs(value) < 1e18 ? 1 - smoothstep(-width, width, d) : 0; let color = mix(vec3(0.95, 0.96, 0.98), vec3(0.09, 0.47, 1), fill); const g = p * 4; const distance = abs(fract(g + 0.5) - 0.5); const gridWidth = max(fwidth(g), vec2(0.000001)); const grid = max( 1 - smoothstep(0, gridWidth.x, distance.x), 1 - smoothstep(0, gridWidth.y, distance.y), ); color = mix(color, vec3(0.45), 0.35 * grid); const diagonal = curveCoverage(p, p.x, span, size, 1.5); color = mix(color, vec3(0.15), 0.6 * diagonal); const decor = axes2D(uv, u, 121); return vec4(labelColor(mix(color, vec3(0.39, 0.43, 0.49), decor.x), decor.yzw), 1); } /** Compare a wider blue curve with a narrow orange curve, including undefined raw pow. */ export function plotComparison( first: ScalarCurve, second: ScalarCurve, uv: vec2, u: PlotViewport, ): vec4 { const span = max(u.plotSpan, vec2(0.00001)); const p = u.plotCenter + (uv - 0.5) * span; const size = plotSize(u.resolution); const blue = curveCoverage(p, first(p.x), span, size, 2.5); const orange = curveCoverage(p, second(p.x), span, size, 1); const decor = axes2D(uv, u, 121); let color = mix(vec3(0.97, 0.97, 0.98), vec3(0.39, 0.43, 0.49), decor.x); color = mix(color, vec3(0.09, 0.47, 1), blue); return vec4(labelColor(mix(color, vec3(0.98, 0.42, 0.06), orange), decor.yzw), 1); } /** A parameter-space dash field. No path mesh or cumulative length buffer. */ function patternDistance(t: f32, rate: f32, u: PlotUniforms): f32 { if (u.curvePattern.x == 0) return 0; const period = u.curvePattern.y; const phase = fract((t + u.curvePattern.z) / period); const gap = max(0, abs(phase - 0.5) - u.curvePattern.w * 0.5) * period; return gap / max(rate, 1e-20) * pixelWidth(); } /** Evaluate the graph itself in a local pixel footprint, never a sampled path. * Derivatives are taken only of the coordinate transform, not across callback jumps. */ function scalarField(sample: ScalarCurve, p: vec2, dx: vec2, dy: vec2, u: PlotUniforms, jumps: bool): f32 { const value = sample(p.x); const xGradient = vec2(dx.x, dy.x); const yGradient = vec2(dx.y, dy.y); const h = max(max(length(xGradient) * 0.125, abs(p.x) * 1e-6), 1e-7); const before = sample(p.x - h), after = sample(p.x + h); let slope = (after - before) / (2 * h); if (!(abs(before) < 1e18)) slope = (after - value) / h; if (!(abs(after) < 1e18)) slope = (value - before) / h; const normal = yGradient - slope * xGradient; const normSquared = max(dot(normal, normal), 1e-30); const residual = p.y - value; const normalDistance = abs(residual) / sqrt(normSquared) * pixelWidth(); const parameter = p.x - residual * dot(xGradient, normal) / normSquared; // The determinant form avoids cancellation at steep tangents. const rate = abs(xGradient.x * yGradient.y - xGradient.y * yGradient.x) / sqrt(normSquared); const gapDistance = patternDistance(parameter, rate, u); // A discontinuity must not become an invented vertical connecting stroke. const continuous = !jumps || abs(value - (before + after) * 0.5) <= max(length(yGradient) * 2, abs(after - before) * 0.2); return abs(value) < 1e18 && abs(slope) < 1e18 && continuous ? distanceCoverage(length(vec2(normalDistance, gapDistance)), u.appearance.z) : 0; } /** Unbounded scalar field in two dimensions; the camera never sets a function domain. */ export function plot2D(sample: ScalarCurve, uv: vec2, u: PlotUniforms, jumps: bool): vec4 { const size = plotSize(u.resolution); const span = max(u.plotSpan, vec2(0.00001)); const p = u.plotCenter + (uv - 0.5) * span; const dx = dpdx(p), dy = dpdy(p); // Four footprint samples integrate the procedural field, rather than weakening // the stroke when a high-frequency function becomes smaller than a pixel. let curve = 0; for (let i = 0; i < 4; i++) { const offset = vec2((i & 1) == 0 ? -0.25 : 0.25, (i & 2) == 0 ? -0.25 : 0.25); curve += scalarField(sample, p + dx * offset.x + dy * offset.y, dx, dy, u, jumps) * 0.25; } const decor = axes2D(uv, u, 121) * u.sceneOpacity.x; let color = mix(vec3(0.965, 0.973, 0.985), vec3(0.39, 0.43, 0.49), decor.x); color = mix(color, vec3(0.09, 0.42, 0.92), curve); color = labelColor(color, decor.yzw); const selected = ((vec2(u.probe, sample(u.probe)) - u.plotCenter) / span + 0.5) * size; const base = labelColor(mix(vec3(0.965, 0.973, 0.985), vec3(0.39, 0.43, 0.49), decor.x), decor.yzw); return vec4(mix(base, abs(sample(u.probe)) < 1e18 ? pointColor(color, uv * size, selected) : color, u.sceneOpacity.y), 1); } /** Camera coordinates in normalized world units, shared by projection and inverse rays. */ function basisVector(p: vec3, u: PlotUniforms): vec3 { const span = max(u.plotSpan, vec2(0.00001)); const q = p / vec3(span, max(span.x, span.y)); const basis = u.rotationBasis; const horizontal = q.x * basis.y + q.z * basis.x; const depth = -q.x * basis.x + q.z * basis.y; return vec3(horizontal, q.y * basis.w - depth * basis.z, q.y * basis.z + depth * basis.w); } function cameraPoint(p: vec3, u: PlotUniforms): vec3 { return basisVector((u.model * vec4(p, 1)).xyz - vec3(u.plotCenter, u.plotCenterZ), u); } export function cameraVector(p: vec3, u: PlotUniforms): vec3 { return basisVector((u.model * vec4(p, 0)).xyz, u); } function sceneCenter(u: PlotUniforms): vec3 { return (u.inverseModel * vec4(u.plotCenter, u.plotCenterZ, 1)).xyz; } export function inverseCamera(p: vec3, u: PlotUniforms): vec3 { const basis = u.rotationBasis; const y = p.y * basis.w + p.z * basis.z; const depth = -p.y * basis.z + p.z * basis.w; const q = vec3(p.x * basis.y - depth * basis.x, y, p.x * basis.x + depth * basis.y); return (u.inverseModel * vec4(q * vec3(u.plotSpan, max(u.plotSpan.x, u.plotSpan.y)), 0)).xyz; } /** Project without division so implicit line fields also work at vanishing points. */ export function homogeneous(p: vec3, u: PlotUniforms, direction: bool): vec3 { const size = plotSize(u.resolution); const camera = direction ? cameraVector(p, u) : cameraPoint(p, u); const w = u.view3d == u32(2) ? (direction ? -camera.z : u.cameraLens.y - camera.z) : (direction ? 0 : u.cameraLens.y); const focal = 1 / u.cameraLens.x; return vec3((vec2(camera.x / (size.x / size.y), camera.y) * focal + (vec2(0.5) + u.plotPan) * w) * size, w); } export function project(p: vec3, u: PlotUniforms): vec2 { const h = homogeneous(p, u, false); return h.xy / max(h.z, 0.101); } function cameraDistance(p: vec3, u: PlotUniforms): f32 { return u.cameraLens.y - cameraPoint(p, u).z; } function inFront(p: vec3, u: PlotUniforms): bool { return u.view3d != u32(2) || cameraDistance(p, u) >= 0.101; } export class ViewRay { origin: vec3; direction: vec3; } export function viewRay(uv: vec2, u: PlotUniforms): ViewRay { const screen = uv - vec2(0.5) - u.plotPan; const size = plotSize(u.resolution); const cameraXY = vec2(screen.x * (size.x / size.y), screen.y) * u.cameraLens.x; const origin = u.view3d == u32(2) ? vec3(0, 0, u.cameraLens.y) : vec3(cameraXY * u.cameraLens.y, u.cameraLens.y); const direction = u.view3d == u32(2) ? vec3(cameraXY, -1) : vec3(0, 0, -1); return { origin: inverseCamera(origin, u) + sceneCenter(u), direction: inverseCamera(direction, u) }; } /** Infinite world axis as a projected implicit line SDF; no range-derived endpoints. */ function axisField(pixel: vec2, axis: vec3, ray: ViewRay, u: PlotUniforms): f32 { const origin = homogeneous(vec3(0), u, false); const direction = homogeneous(axis, u, true); const coefficients = cross(origin, direction); const magnitude = length(coefficients.xy); let distance = length(pixel - project(vec3(0), u)); if (magnitude > 1e-12) distance = abs(dot(coefficients, vec3(pixel, 1))) / magnitude; // Reject the portion of the infinite line behind the camera. const transverse = vec3(1) - axis; const a = ray.origin * transverse, b = ray.direction * transverse; const depth = -dot(a, b) / max(dot(b, b), 1e-20); return u.view3d != u32(2) || depth >= 0.101 ? distanceCoverage(distance, u.appearance.x) : 0; } /** Intersect the camera ray with y=0, then evaluate the world lattice as a distance field. */ function groundField(ray: ViewRay, u: PlotUniforms, xLevels: vec3, zLevels: vec3): f32 { const denominator = abs(ray.direction.y) < 1e-8 ? (ray.direction.y < 0 ? -1e-8 : 1e-8) : ray.direction.y; const depth = -ray.origin.y / denominator; const ground = (ray.origin + ray.direction * depth).xz; const gradient = max(vec2(length(vec2(dpdx(ground.x), dpdy(ground.x))), length(vec2(dpdx(ground.y), dpdy(ground.y)))), vec2(1e-20)); let field = 0; for (let level = 0; level < 2; level++) { const spacing = level == 0 ? vec2(xLevels.x, zLevels.x) : vec2(xLevels.y, zLevels.y); const distance = abs(fract(ground / spacing + 0.5) - 0.5) * spacing / gradient * pixelWidth(); const separation = spacing / gradient * pixelWidth(); const density = clamp(u.labelStyle.x,0.5,2); const fade = smoothstep(vec2(12/density),vec2(28/density),separation); const nearest = floor(ground / spacing + 0.5) * spacing; const weights = level == 0 ? vec2(tickOpacity(nearest.x, xLevels), tickOpacity(nearest.y, zLevels)) : vec2(coarseTickOpacity(nearest.x, xLevels), coarseTickOpacity(nearest.y, zLevels)); field = max(field, max(distanceCoverage(distance.x, u.appearance.y) * fade.x * weights.x, distanceCoverage(distance.y, u.appearance.y) * fade.y * weights.y)); } return (u.view3d != u32(2) || depth >= 0.101) && abs(ray.direction.y) >= 1e-8 && (u.decorations & u32(1)) != u32(0) ? field * u.decorationOpacity.x : 0; } /** Invert the projected infinite axis at the perpendicular screen foot. * This queries visible world ticks directly, without a camera-sized tick domain. */ function axisParameter(pixel: vec2, axis: vec3, u: PlotUniforms): f32 { const origin = homogeneous(vec3(0), u, false); const direction = homogeneous(axis, u, true); const line = cross(origin, direction); const foot = pixel - line.xy * dot(line, vec3(pixel, 1)) / max(dot(line.xy, line.xy), 1e-20); const slope = direction.xy - foot * direction.z; return dot(foot * origin.z - origin.xy, slope) / max(dot(slope, slope), 1e-20); } function spatialLevels(axis: vec3, u: PlotUniforms): vec3 { const center = axisParameter(plotSize(u.resolution) * 0.5, axis, u); const span = max(u.plotSpan.x, u.plotSpan.y); const h = span * 0.001; const tangent = (project(axis * (center + h), u) - project(axis * (center - h), u)) / (2 * h); const pixels = max(length(tangent) * span, 1); const horizontal = abs(tangent.x) >= abs(tangent.y) * 0.7; return axisLevels(center, span, pixels, horizontal, u); } /** Label fill and halo plus tick stroke. Adjacent projected boxes determine * collision fading; candidates are world anchored and remain camera independent. */ function spatialTicks(pixel: vec2, axis: vec3, levels: vec3, priority: f32, u: PlotUniforms): vec4 { const size = plotSize(u.resolution); const fontSize = u.appearance.w; const originH = homogeneous(vec3(0), u, false); const directionH = homogeneous(axis, u, true); const axisLine = cross(originH, directionH); const magnitude = length(axisLine.xy); if (magnitude <= 1e-12 || abs(dot(axisLine, vec3(pixel, 1))) / magnitude > fontSize * 6 + 12) return vec4(0); const normal = axisLine.xy / magnitude; const tangent = vec2(normal.y, -normal.x); const sign = axis.y > 0 ? (normal.x > 0 ? -1 : 1) : (normal.y > 0 ? -1 : 1); const outward = normal * sign; const value = axisParameter(pixel, axis, u); let labels = vec3(0); let ticks = 0; for (let index = 0; index < 6; index++) { const stride = index < 3 ? levels.x : levels.y; const nearest = floor(value / stride + 0.5) * stride; const t = nearest + f32(index % 3 - 1) * stride; const world = axis * t; if (inFront(world, u)) { const at = project(world, u); const anchor = at + outward * (fontSize * 0.95 + 6) + vec2(0, fontSize * 0.65); const delta = pixel - anchor; const nearLabel = (u.decorations & u32(2)) != u32(0) && abs(delta.x) <= fontSize * 9 && delta.y >= -fontSize * 1.5 - 3 && delta.y <= 3; const nearTick = u.appearance.x > 0 && all(abs(pixel - at) <= vec2(u.appearance.x * 0.5 + 4 + pixelWidth())); if (!nearLabel && !nearTick) continue; const before = project(axis * (t - stride), u); const after = project(axis * (t + stride), u); const width = numberWidth(t, levels.x, fontSize); const room = min(min(anchor.x - width * 0.5 - 3, size.x - anchor.x - width * 0.5 - 3), min(anchor.y - fontSize * 1.5, size.y - anchor.y)); const separation = min(abs(at - before), abs(after - at)); const box = vec2(width + fontSize, fontSize * 1.8 + 6); const fit = smoothstep(0.85, 1.15, max(separation.x / box.x, separation.y / box.y)); const visibility = (index < 3 ? tickOpacity(t, levels) : coarseTickOpacity(t, levels)) * fit; ticks = max(ticks, tickMark(pixel, at, tangent, 3, u.appearance.x) * visibility); const zero = abs(t) <= levels.x * 0.001; const originDistance = length(at - project(vec3(0), u)); const crossing = zero ? (axis.x > 0 ? 1 : 0) : smoothstep(fontSize * 2, fontSize * 4, originDistance); if ((u.decorations & u32(2)) != u32(0)) { labels = max(labels, numberAt(pixel, anchor, t, levels.x, 0.5, fontSize, u.labelStyle.y, u.labelStyle.z) * u.decorationOpacity.y * visibility * smoothstep(0, 6, room) * crossing * priority); } } } return vec4(ticks, labels); } class SpatialDecor { color: vec3; labels: vec3; } /** Shared projection, nested grid and labels. No finite tick list or path mesh. */ function spatialBackground(uv: vec2, u: PlotUniforms): SpatialDecor { const size = plotSize(u.resolution); const pixel = uv * size; const xLevels = spatialLevels(vec3(1, 0, 0), u); const yLevels = spatialLevels(vec3(0, 1, 0), u); const zLevels = spatialLevels(vec3(0, 0, 1), u); const ray = viewRay(uv, u); const grid = groundField(ray, u, xLevels, zLevels); const xTicks = spatialTicks(pixel, vec3(1, 0, 0), xLevels, 1, u); const yTicks = spatialTicks(pixel, vec3(0, 1, 0), yLevels, 1, u); const origin = project(vec3(0), u); const xDirection = homogeneous(vec3(1, 0, 0), u, true); const zDirection = homogeneous(vec3(0, 0, 1), u, true); const xTangent = normalize(xDirection.xy - origin * xDirection.z + vec2(1e-12)); const zTangent = normalize(zDirection.xy - origin * zDirection.z + vec2(1e-12)); const angle = abs(xTangent.x * zTangent.y - xTangent.y * zTangent.x); const zTicks = spatialTicks(pixel, vec3(0, 0, 1), zLevels, smoothstep(0.08, 0.25, angle), u); let labels = max(max(xTicks.yzw, yTicks.yzw), zTicks.yzw); let color = mix(vec3(0.965, 0.973, 0.985), vec3(0.8, 0.82, 0.85), grid * 0.65); color = mix(color, vec3(0.67, 0.28, 0.25), axisField(pixel, vec3(1, 0, 0), ray, u)); color = mix(color, vec3(0.23, 0.47, 0.3), axisField(pixel, vec3(0, 1, 0), ray, u)); color = mix(color, vec3(0.4, 0.35, 0.62), axisField(pixel, vec3(0, 0, 1), ray, u)); color = mix(color, vec3(0.25, 0.29, 0.35), max(max(xTicks.x, yTicks.x), zTicks.x)); if ((u.decorations & u32(4)) != u32(0)) { for (let index = 0; index < 3; index++) { const axis = index == 0 ? vec3(1, 0, 0) : index == 1 ? vec3(0, 1, 0) : vec3(0, 0, 1); const edge = index == 1 ? vec2(size.x * 0.5, size.y - 30) : vec2(size.x - 30, size.y * 0.5); const world = axis * axisParameter(edge, axis, u); if (inFront(world, u)) { const at = clamp(project(world, u) + vec2(10, 18), vec2(18), size - vec2(18)); labels = max(labels, axisLabel(pixel, at, 120 + index, u) * u.decorationOpacity.z); } } } return { color: mix(vec3(0.965, 0.973, 0.985), color, u.sceneOpacity.x), labels: labels * u.sceneOpacity.x }; } /** Parameter coordinate of a ray/graph-plane intersection, with visibility. */ function scalarParameter(pixel: vec2, u: PlotUniforms): vec2 { const ray = viewRay(pixel / plotSize(u.resolution), u); if (abs(ray.direction.z) < 1e-12) return vec2(0); const depth = -ray.origin.z / ray.direction.z; return vec2((ray.origin + ray.direction * depth).x, u.view3d != u32(2) || depth >= 0.101 ? 1 : 0); } /** Bracket within the pixel's inverse-projected interval. This resolves dense * crossings without trusting a single tangent, and accepts only actual projected * callback points. No chord supplies coverage, including at the horizon. */ function scalarFootprintDistance(sample: ScalarCurve, pixel: vec2, seed: f32, u: PlotUniforms): f32 { const h = max(abs(seed) * 1e-6, 0.0001); const direction = project(vec3(seed + h, 0, 0), u) - project(vec3(seed - h, 0, 0), u); const along = normalize(direction + vec2(1e-20)); const normal = vec2(-along.y, along.x); const radius = u.appearance.z * 0.5 + pixelWidth(); const first = scalarParameter(pixel - along * radius, u); const last = scalarParameter(pixel + along * radius, u); if (first.y <= 0 || last.y <= 0) return 1e20; const low = min(first.x, last.x), high = max(first.x, last.x); // Well-resolved areas already have an accurate local closest-point query. if (high - low < u.plotSpan.x / max(u.resolution.x, 1) * 4) return 1e20; let best = 1e20; let previous = low; let previousValue = sample(previous); let previousWorld = vec3(previous, previousValue, 0); let previousSide = dot(project(previousWorld, u) - pixel, normal); for (let i = 1; i <= 8; i++) { const next = mix(low, high, f32(i) / 8); const nextValue = sample(next); const nextWorld = vec3(next, nextValue, 0); const nextSide = dot(project(nextWorld, u) - pixel, normal); if (abs(previousValue) < 1e18 && abs(nextValue) < 1e18 && inFront(previousWorld, u) && inFront(nextWorld, u) && previousSide * nextSide <= 0) { let a = previous, b = next, side = previousSide; for (let step = 0; step < 8; step++) { const t = (a + b) * 0.5; const at = vec3(t, sample(t), 0); const signed = dot(project(at, u) - pixel, normal); if (side * signed <= 0) b = t; else { a = t; side = signed; } } const t = (a + b) * 0.5; const value = sample(t), at = vec3(t, value, 0); if (abs(value) < 1e18 && inFront(at, u)) { const before = project(vec3(t - h, sample(t - h), 0), u); const after = project(vec3(t + h, sample(t + h), 0), u); const rate = pixelWidth() * 2 * h / max(length(after - before), 1e-20); const gap = patternDistance(t, rate, u); best = min(best, length(vec2(length(project(at, u) - pixel), gap))); } } previous = next; previousValue = nextValue; previousWorld = nextWorld; previousSide = nextSide; } return best; } /** A projected scalar query measures an actual point on the callback. Dividing * a world-space residual by an unbounded inverse-projection derivative invents * coverage near the projective pole, even far outside the projected graph. */ function projectedScalarDistance(sample: ScalarCurve, pixel: vec2, u: PlotUniforms, jumps: bool): f32 { const ray = viewRay(pixel / plotSize(u.resolution), u); if (abs(ray.direction.z) < 1e-12) return 1e20; const depth = -ray.origin.z / ray.direction.z; if (u.view3d == u32(2) && depth < 0.101) return 1e20; const world = ray.origin + ray.direction * depth; let t = world.x; let best = 1e20; for (let iteration = 0; iteration < 5; iteration++) { const value = sample(t); const point = vec3(t, value, 0); const h = max(abs(t) * 1e-6, 0.0001); const before = sample(t - h), after = sample(t + h); const at = project(point, u); const validBefore = abs(before) < 1e18 && inFront(vec3(t - h, before, 0), u); const validAfter = abs(after) < 1e18 && inFront(vec3(t + h, after, 0), u); const a = validBefore ? project(vec3(t - h, before, 0), u) : at; const b = validAfter ? project(vec3(t + h, after, 0), u) : at; const tangent = (b - a) / (validBefore && validAfter ? 2 * h : h); const norm = dot(tangent, tangent); const continuous = !jumps || abs(value - (before + after) * 0.5) <= max(u.plotSpan.y * 1e-4, abs(after - before) * 0.2); if (abs(value) < 1e18 && inFront(point, u) && continuous) { const gap = patternDistance(t, pixelWidth() / max(sqrt(norm), 1e-20), u); best = min(best, length(vec2(length(pixel - at), gap))); } if (!(norm > 1e-20 && norm < 1e30)) break; const correction = dot(at - pixel, tangent) / norm; const limit = max(u.plotSpan.x, abs(t) * 0.5); t -= clamp(correction, -limit, limit); } if (best > u.appearance.z * 0.25) best = min(best, scalarFootprintDistance(sample, pixel, world.x, u)); return best; } /** Invert each physical subpixel separately. The projective plane has a pole; * linearizing one center ray across that pole is not a valid pixel footprint. */ export function plotScalar3D(sample: ScalarCurve, trajectory: SpaceCurve, uv: vec2, u: PlotUniforms, jumps: bool): vec4 { const size = plotSize(u.resolution); const pixel = uv * size; const background = spatialBackground(uv, axesUniforms(u)); let curve = 0; const edgeOn = abs(inverseCamera(vec3(0, 0, -1), u).z) < max(u.plotSpan.x, u.plotSpan.y) * 0.003; if (edgeOn) { const extent = max(u.plotSpan.x, u.plotSpan.y) * 32; curve = distanceCoverage(trajectoryDistance(trajectory, pixel, u, vec2(u.plotCenter.x - extent, u.plotCenter.x + extent), jumps), u.appearance.z); } else { for (let i = 0; i < 4; i++) { const offset = vec2((i & 1) == 0 ? -0.25 : 0.25, (i & 2) == 0 ? -0.25 : 0.25) * pixelWidth(); curve += distanceCoverage(projectedScalarDistance(sample, pixel + offset, u, jumps), u.appearance.z) * 0.25; } } let color = mix(background.color, vec3(0.09, 0.42, 0.92), curve); color = labelColor(color, background.labels); const selected = vec3(u.probe, sample(u.probe), 0); return vec4(mix(labelColor(background.color, background.labels), abs(selected.y) < 1e18 && inFront(selected, u) ? pointColor(color, pixel, project(selected, u)) : color, u.sceneOpacity.y), 1); } /** Refine a candidate against the actual projected callback, never a chord SDF. */ function refineTrajectoryHit(trajectory: SpaceCurve, pixel: vec2, candidate: vec4, u: PlotUniforms, jumps: bool): vec2 { let t = candidate.y; const low = candidate.z, high = candidate.w; const epsilon = max(max((high - low) * 0.001, abs(t) * 1e-6), 1e-7); for (let iteration = 0; iteration < 12; iteration++) { const before = max(low, t - epsilon), after = min(high, t + epsilon); const a = project(trajectory(before), u), b = project(trajectory(after), u); const tangent = (b - a) / max(after - before, 1e-20); const atWorld = trajectory(t); const at = project(atWorld, u); const delta = dot(at - pixel, tangent) / max(dot(tangent, tangent), 1e-20); let next = clamp(t - delta, low, high); let world = trajectory(next); let projected = project(world, u); const error = dot(at - pixel, at - pixel); if (!jumps && all(abs(atWorld) < vec3(1e18)) && inFront(atWorld, u) && error <= ((max(0, u.appearance.z * 0.5 - pixelWidth() * 0.5)) ** (2))) return vec2(sqrt(error), t); if (!(all(abs(world) < vec3(1e18)) && inFront(world, u) && dot(projected - pixel, projected - pixel) <= error)) { next = (t + next) * 0.5; world = trajectory(next); projected = project(world, u); } // Safeguard the numerical step: refinement may not make a valid seed worse. if (all(abs(world) < vec3(1e18)) && inFront(world, u) && dot(projected - pixel, projected - pixel) <= error) { if (next == t) break; const movement=length(projected-at); t = next; if(movement < pixelWidth()*0.01)break; } else break; } const world = trajectory(t); const middle = trajectory((low + high) * 0.5); const continuous = !jumps || length(middle - (trajectory(low) + trajectory(high)) * 0.5) <= max(1e-6, length(trajectory(high) - trajectory(low)) * 0.2); return vec2(all(abs(world) < vec3(1e18)) && continuous && inFront(world, u) ? length(pixel - project(world, u)) : 1e20, t); } function refineTrajectory(trajectory: SpaceCurve, pixel: vec2, candidate: vec4, u: PlotUniforms, jumps: bool): f32 { return refineTrajectoryHit(trajectory, pixel, candidate, u, jumps).x; } /** Projected chord distance is a search bound only; it never supplies coverage. */ function intervalChordDistance(pixel: vec2, a: vec2, b: vec2): f32 { const delta = b - a; const along = clamp(dot(pixel - a, delta) / max(dot(delta, delta), 1e-20), 0, 1); return length(pixel - a - along * delta); } /** Query one actual callback interval, keeping its boundary points in the result. */ function intervalHit(trajectory: SpaceCurve, pixel: vec2, low: f32, high: f32, u: PlotUniforms, jumps: bool): vec2 { let start = low, end = high; let a = trajectory(start), b = trajectory(end); const frontA = inFront(a, u), frontB = inFront(b, u); if (!(all(abs(a) < vec3(1e18)) && all(abs(b) < vec3(1e18))) || (!frontA && !frontB)) return vec2(1e20, low); if (frontA != frontB) { // Clip the parameter against actual callback evaluations, rather than a // world-space chord which can put the seed behind the near plane. let left = start, right = end; for (let i = 0; i < 12; i++) { const middle = (left + right) * 0.5; if (inFront(trajectory(middle), u) == frontA) left = middle; else right = middle; } if (frontA) end = left; else start = right; a = trajectory(start); b = trajectory(end); } const ha = homogeneous(a, u, false), hb = homogeneous(b, u, false); const pa = ha.xy / ha.z, pb = hb.xy / hb.z; const delta = pb - pa; const screenFraction = clamp(dot(pixel - pa, delta) / max(dot(delta, delta), 1e-20), 0, 1); // Undo perspective interpolation. A screen midpoint is not generally the // midpoint of the callback's parameter interval. const fraction = screenFraction * ha.z / max(mix(hb.z, ha.z, screenFraction), 1e-20); const seed = mix(start, end, fraction); const candidate = vec4(0, seed, start, end); let refined = refineTrajectoryHit(trajectory, pixel, candidate, u, jumps); // Shared interval endpoints make changing the search partition continuous. // Apply the same jump rejection as refinement to avoid inventing connections. const middle = trajectory((start + end) * 0.5); const continuous = !jumps || length(middle - (a + b) * 0.5) <= max(1e-6, length(b - a) * 0.2); const first = length(pixel - pa), last = length(pixel - pb); if (first < refined.x) refined = vec2(first, start); if (last < refined.x) refined = vec2(last, end); return continuous ? refined : vec2(1e20, start); } function intervalDistance(trajectory: SpaceCurve, pixel: vec2, low: f32, high: f32, u: PlotUniforms, jumps: bool): f32 { return intervalHit(trajectory, pixel, low, high, u, jumps).x; } /** Compactify unbounded parameter space instead of clipping to a finite domain. * The mathematical tails approach infinity; f32 precision and numerical quality * still bound the detail any finite GPU invocation can resolve. */ function parameterAt(q: f32, scale: f32, center: f32, u: PlotUniforms): f32 { const safe = clamp(q, -0.99999, 0.99999); if (u.parameterMode == u32(3)) return center + scale * safe / (1 - abs(safe)); const positive = (safe + 1) * 0.5; if (u.parameterMode == u32(2)) return u.parameterBounds.x + scale * positive / max(1 - positive, 0.00001); return u.parameterBounds.y - scale * (1 - positive) / max(positive, 0.00001); } /** Local world-space focus controls where the compactified search spends detail. * This seed is numerical; an arbitrary callback has no guaranteed global inverse. */ function parameterFocus(trajectory: SpaceCurve, u: PlotUniforms): vec2 { const pixel = plotSize(u.resolution) * 0.5; let center = u.parameterFocusSeed; const initial = trajectory(center); let error = all(abs(initial) < vec3(1e18)) && inFront(initial,u) ? dot(project(initial,u)-pixel,project(initial,u)-pixel) : 1e30; // Search long-baseline trends before a local tangent. Periodic transverse // motion must not trap the visible window near the original parameter zero. for (let level = 0; level < 8; level++) { const radius = ((4) ** (f32(level))); const a = trajectory(u.parameterFocusSeed-radius), b = trajectory(u.parameterFocusSeed+radius); if (all(abs(a) < vec3(1e18)) && all(abs(b) < vec3(1e18))) { const middle = (a+b)*0.5, direction = (b-a)/(2*radius); const originH = homogeneous(middle,u,false), directionH = homogeneous(direction,u,true); const slope = directionH.xy - pixel*directionH.z; const norm = dot(slope,slope); if (norm > 1e-20) { const candidate = u.parameterFocusSeed + dot(pixel*originH.z-originH.xy,slope)/norm; const point = trajectory(candidate); if (abs(candidate) < 1e18 && all(abs(point) < vec3(1e18)) && inFront(point,u)) { const delta = project(point,u)-pixel, nextError = dot(delta,delta); if (nextError < error) {center=candidate;error=nextError;} } } } } let speed = 1; for (let i = 0; i < 4; i++) { const h = max(abs(center)*1e-5,0.001); const at = trajectory(center), left = trajectory(center-h), right = trajectory(center+h); const normalized = cameraVector((right-left)/(2*h),u); speed = max(length(normalized),1e-10); const tangent = (project(right,u)-project(left,u))/(2*h); const correction = clamp(dot(pixel-project(at,u),tangent)/max(dot(tangent,tangent),1e-20),-32/speed,32/speed); let candidate = center+correction; for (let backtrack=0;backtrack<4;backtrack++) { const point = trajectory(candidate), delta=project(point,u)-pixel; const nextError=dot(delta,delta); if(all(abs(point)<vec3(1e18))&&inFront(point,u)&&nextError<=error){center=candidate;error=nextError;break;} candidate=(candidate+center)*0.5; } } let scale = clamp(2/speed,0.00001,1e10); if(u.parameterMode == u32(1)) scale=max(scale,abs(center-u.parameterBounds.y)); if(u.parameterMode == u32(2)) scale=max(scale,abs(center-u.parameterBounds.x)); return vec2(center,scale); } /** Inspect every projected interval that can cover this fragment. Ranking a * fixed number of midpoint samples drops valid branches at folds/crossings. * Bounds use sampled bending as a numerical guard, not a proof for an arbitrary * callback; quality still determines how much detail the search can resolve. */ function trajectoryDistance(trajectory: SpaceCurve, pixel: vec2, u: PlotUniforms, bounds: vec2, jumps: bool): f32 { const requested = f32(u.curveQuality.x); const range = bounds.y - bounds.x; const unbounded = u.parameterMode != u32(0); const focus = unbounded ? parameterFocus(trajectory, u) : vec2(0, 1); const count = i32(min(512, unbounded || u.curvePattern.x == 0 ? requested : max(requested, ceil(range / u.curvePattern.y * 4)))); const stepSize = range / f32(count); let distance = 1e20; for (let i = 0; i < count; i++) { let low = bounds.x + f32(i) * stepSize; let high = min(bounds.y, low + stepSize); if (unbounded) { low = parameterAt(-1 + 2 * f32(i) / f32(count), focus.y, focus.x, u); high = parameterAt(-1 + 2 * f32(i + 1) / f32(count), focus.y, focus.x, u); } let t = (low + high) * 0.5; if (u.curvePattern.x != 0) { const period = u.curvePattern.y; const center = (floor((t + u.curvePattern.z) / period) + 0.5) * period - u.curvePattern.z; low = max(low, center - period * u.curvePattern.w * 0.5); high = min(high, center + period * u.curvePattern.w * 0.5); t = (low + high) * 0.5; } if (high >= low) { const a = trajectory(low), middle = trajectory(t), b = trajectory(high); const finite = all(abs(a) < vec3(1e18)) && all(abs(middle) < vec3(1e18)) && all(abs(b) < vec3(1e18)); if (finite) { let possible = true; if (inFront(a, u) && inFront(middle, u) && inFront(b, u)) { const pa = project(a, u), pm = project(middle, u), pb = project(b, u); const bending = intervalChordDistance(pm, pa, pb); const guard = bending * 4 + u.appearance.z * 0.5 + pixelWidth() * 2; possible = min(intervalChordDistance(pixel, pa, pm), intervalChordDistance(pixel, pm, pb)) <= guard; } if (possible) { distance = min(distance, intervalDistance(trajectory, pixel, low, t, u, jumps)); distance = min(distance, intervalDistance(trajectory, pixel, t, high, u, jumps)); } } } } return distance; } function spatialProbe(trajectory: SpaceCurve, u: PlotUniforms): vec3 { const selected = trajectory(u.probe); const visible = ((u.parameterMode & u32(1)) != u32(0) || u.probe >= u.parameterBounds.x) && ((u.parameterMode & u32(2)) != u32(0) || u.probe <= u.parameterBounds.y) && all(abs(selected) < vec3(1e18)) && inFront(selected, u); return vec3(project(selected, u), visible ? 1 : 0); } function spatialCurveColor(uv: vec2, u: PlotUniforms, distance: f32, background: SpatialDecor, probe: vec3): vec4 { const pixel = uv * plotSize(u.resolution); let color = mix(background.color, vec3(0.09, 0.42, 0.92), distanceCoverage(distance, u.appearance.z)); color = labelColor(color, background.labels); return vec4(mix(labelColor(background.color, background.labels), probe.z > 0 ? pointColor(color, pixel, probe.xy) : color, u.sceneOpacity.y), 1); } export function plot3D(trajectory: SpaceCurve, uv: vec2, u: PlotUniforms, jumps: bool): vec4 { const distance = u.appearance.z > 0 ? trajectoryDistance(trajectory, uv * plotSize(u.resolution), u, u.parameterBounds, jumps) : 1e20; return spatialCurveColor(uv, u, distance, spatialBackground(uv, axesUniforms(u)), spatialProbe(trajectory, u)); } export function plot3DAccelerated(trajectory: SpaceCurve, uv: vec2, u: PlotUniforms): vec4 { const distance = u.appearance.z > 0 ? cachedTrajectoryDistance(trajectory, uv * plotSize(u.resolution), u) : 1e20; return spatialCurveColor(uv, u, distance, cachedSpatialBackground(uv, axesUniforms(u)), curveRecord(vec2i(0, 5)).xyz); } function curveIntervalCount(u: PlotUniforms): i32 { // Search density follows the image footprint, not a user-selected quality floor. const requested = clamp(max(f32(u.curveQuality.x),ceil(max(u.resolution.x, u.resolution.y) * 0.5)), 128, 512); const range = u.parameterBounds.y - u.parameterBounds.x; return i32(min(512, u.parameterMode != u32(0) || u.curvePattern.x == 0 ? requested : max(requested, ceil(range / u.curvePattern.y * 4)))); } function searchParameter(q: f32, focus: vec2, u: PlotUniforms): f32 { return u.parameterMode == u32(0) ? mix(u.parameterBounds.x, u.parameterBounds.y, (q+1)*0.5) : parameterAt(q, focus.y, focus.x, u); } function visibleChordLength(a: vec2, b: vec2, u: PlotUniforms): f32 { const delta = b-a; let low=0, high=1; for(let axis=0;axis<2;axis++) { const start=axis==0?a.x:a.y, direction=axis==0?delta.x:delta.y; const extent=axis==0?u.resolution.x:u.resolution.y; if(abs(direction)<1e-12) {if(start < -8 || start > extent+8)return 0;} else {const x=(-8-start)/direction,y=(extent+8-start)/direction;low=max(low,min(x,y));high=min(high,max(x,y));} } return length(delta)*max(0,high-low); } /** Estimate image work, including local oscillation, instead of spending equal * records on equal compactified coordinates. These records only seed the SDF. */ function intervalWork(trajectory: SpaceCurve, low: f32, high: f32, focus: vec2, u: PlotUniforms): f32 { const t0=searchParameter(low,focus,u), t1=searchParameter(high,focus,u); const mid=searchParameter((low+high)*0.5,focus,u); let total=0; let previous=trajectory(t0); for(let i=1;i<=4;i++) { const point=trajectory(searchParameter(mix(low,high,f32(i)*0.25),focus,u)); if(all(abs(previous)<vec3(1e18))&&all(abs(point)<vec3(1e18))&&(inFront(previous,u)||inFront(point,u))) total+=visibleChordLength(project(previous,u),project(point,u),u); previous=point; } const h=max(abs(mid)*1e-5,min(abs(t1-t0)*0.125,0.02)); const before=trajectory(mid-h),after=trajectory(mid+h); let lengthEstimate=total; if(inFront(before,u)&&inFront(after,u)) lengthEstimate=max(total,length(project(after,u)-project(before,u))*abs(t1-t0)/max(2*h,1e-20)); return max(0.001,total*sqrt(clamp(lengthEstimate/max(total,1),1,144))); } function adaptiveInterval(trajectory: SpaceCurve, index: i32, count: i32, focus: vec2, u: PlotUniforms, explore: bool): vec2 { // Keep exploration in every part of the domain. A temporarily off-screen // chord must not starve a later fold that re-enters the viewport. let low=-1,high=1,budget=count,slot=index; if(explore) { const group=index*32/count; const first=(group*count+31)/32,last=((group+1)*count+31)/32; low=-1+2*f32(group)/32;high=-1+2*f32(group+1)/32;budget=last-first;slot=index-first; } for(let depth=0;depth<24;depth++) { if(budget<=1)break; const middle=(low+high)*0.5; const left=intervalWork(trajectory,low,middle,focus,u),right=intervalWork(trajectory,middle,high,focus,u); const allocated=clamp(i32(floor(f32(budget)*left/(left+right)+0.5)),1,budget-1); if(slot<allocated){high=middle;budget=allocated;} else {low=middle;slot-=allocated;budget-=allocated;} } return vec2(searchParameter(low,focus,u),searchParameter(high,focus,u)); } export function prepareCurveSeeds(trajectory: SpaceCurve, position: vec4, u: PlotUniforms): vec4 { const index=i32(position.x),count=curveIntervalCount(u); if(index>=count*2)return vec4(0); const focus=u.parameterMode != u32(0)?parameterFocus(trajectory,u):vec2(0,1); return vec4(adaptiveInterval(trajectory,index%count,count,focus,u,index>=count),0,0); } /** A resident search record, never a renderable segment. Each original search * interval has two independently clipped parts, matching the uncached query. */ export function prepareCurveIntervals(trajectory: SpaceCurve, position: vec4, u: PlotUniforms, jumps: bool): vec4 { const part = i32(position.x), row = i32(position.y); if (row == 5) return part == 0 ? vec4(spatialProbe(trajectory, u), 0) : vec4(0); const count = curveIntervalCount(u); const index = part / 2, half = part % 2; const empty = row == 4 ? vec4(1e20, 1e20, -1e20, -1e20) : vec4(0); if (part >= count*4) return empty; const interval=seedRecord(vec2i(index,0)).xy; let low=interval.x,high=interval.y; if (u.curvePattern.x != 0) { const period = u.curvePattern.y; const center = (floor(((low + high) * 0.5 + u.curvePattern.z) / period) + 0.5) * period - u.curvePattern.z; low = max(low, center - period * u.curvePattern.w * 0.5); high = min(high, center + period * u.curvePattern.w * 0.5); } if (high < low) return empty; const middle = (low + high) * 0.5; let start = half == 0 ? low : middle; let end = half == 0 ? middle : high; let a = trajectory(start), b = trajectory(end); const frontA = inFront(a, u), frontB = inFront(b, u); const initialMiddle=trajectory((start+end)*0.5); if (!(all(abs(a) < vec3(1e18)) && all(abs(b) < vec3(1e18))) || (!frontA && !frontB && !inFront(initialMiddle,u))) return empty; if (frontA != frontB) { let left = start, right = end; for (let i = 0; i < 12; i++) { const at = (left + right) * 0.5; if (inFront(trajectory(at), u) == frontA) left = at; else right = at; } if (frontA) end = left; else start = right; a = trajectory(start); b = trajectory(end); } const m = trajectory((start + end) * 0.5); if (!all(abs(m) < vec3(1e18))) return empty; const continuous = !jumps || length(m - (a + b) * 0.5) <= max(1e-6, length(b - a) * 0.2); if (!continuous) return empty; const ha = homogeneous(a, u, false), hb = homogeneous(b, u, false); const pa = ha.xy / ha.z, pb = hb.xy / hb.z, pm = project(m, u); const quarter=project(trajectory(mix(start,end,0.25)),u),third=project(trajectory(mix(start,end,0.75)),u); const guard = max(intervalChordDistance(pm, pa, pb),max(intervalChordDistance(quarter,pa,pm),intervalChordDistance(third,pm,pb))) * 4 + u.appearance.z * 0.5 + pixelWidth() * 2; if (row == 0) return vec4(start, end, 1, 0); if (row == 1) return vec4(pa, ha.z, 0); if (row == 2) return vec4(pb, hb.z, 0); if (row == 3) return vec4(pm, guard, 0); if (!inFront(m, u)||!inFront(a,u)||!inFront(b,u)) return vec4(vec2(0), u.resolution); return vec4(min(min(min(pa, pb), pm),min(quarter,third)) - vec2(guard), max(max(max(pa, pb), pm),max(quarter,third)) + vec2(guard)); } /** Every part gets a bit. There is no top-k list, atomic race or overflow drop. */ export function prepareCurveCandidates(position: vec4, u: PlotUniforms): vec4u { const column = u32(position.x), row = u32(position.y); const group = column % u32(16), tileX = column / u32(16); const count = curveIntervalCount(u) * 4; const start = i32(group) * 128; if (start >= count) return vec4u(0); const lo = vec2(f32(tileX), f32(row)) * f32(u.curveTiles.z); const hi = lo + vec2(f32(u.curveTiles.z)); let bits = vec4u(0); for (let i = 0; i < 128; i++) { const part = start + i; if (part >= count) break; const bounds = curveRecord(vec2i(part, 4)); if (all(bounds.xy <= hi) && all(bounds.zw >= lo)) { const a = curveRecord(vec2i(part, 1)).xy; const b = curveRecord(vec2i(part, 2)).xy; const middle = curveRecord(vec2i(part, 3)); const center = (lo + hi) * 0.5; // Segment distance is 1-Lipschitz: beyond guard + tile radius no pixel // in this tile can pass the same conservative fragment-side guard. const radius = f32(u.curveTiles.z) * 0.7071068 + 1; if (min(intervalChordDistance(center, a, middle.xy), intervalChordDistance(center, middle.xy, b)) > middle.z + radius) continue; const bit = u32(1) << u32(i % 32); if (i < 32) bits.x |= bit; else if (i < 64) bits.y |= bit; else if (i < 96) bits.z |= bit; else bits.w |= bit; } } return bits; } export function prepareCurveGroups(position: vec4, u: PlotUniforms): vec4u { let mask=u32(0); for(let group=0;group<16;group++) { if(any(textureLoad(curveCandidates,vec2i(i32(position.x)*16+group,i32(position.y)),0)!=vec4u(0)))mask|=u32(1)<<u32(group); } return vec4u(mask,0,0,0); } /** Shared traversal for display, scene depth and radius-based picking. */ function cachedCurveHit(trajectory: SpaceCurve, pixel: vec2, u: PlotUniforms, radius: f32, depthOrder: bool): vec4 { const lower=min(vec2u(max(vec2(0),floor((pixel-vec2(radius))/f32(u.curveTiles.z)))),u.curveTiles.xy-vec2u(1)); const upper=min(vec2u(max(vec2(0),floor((pixel+vec2(radius))/f32(u.curveTiles.z)))),u.curveTiles.xy-vec2u(1)); let active=u32(0); for(let y=lower.y;y<=upper.y;y++)for(let x=lower.x;x<=upper.x;x++)active|=textureLoad(curveGroups,vec2i(i32(x),i32(y)),0).x; let best=vec4(1e20,0,1e20,0); for(let remainingGroup=0;remainingGroup<16;remainingGroup++) { if(active==u32(0))break; const group=i32(firstTrailingBit(active));active&=active-u32(1); let packed=vec4u(0); for(let y=lower.y;y<=upper.y;y++)for(let x=lower.x;x<=upper.x;x++) { const value=textureLoad(curveCandidates,vec2i(i32(x)*16+group,i32(y)),0); packed=vec4u(packed.x|value.x,packed.y|value.y,packed.z|value.z,packed.w|value.w); } for(let lane=0;lane<4;lane++) { let bits=packed[lane]; for(let remaining=0;remaining<32;remaining++) { if(bits==u32(0))break; const bit=firstTrailingBit(bits);bits&=bits-u32(1); const index=group*128+lane*32+i32(bit); const bounds=curveRecord(vec2i(index,4)); if(any(pixel<bounds.xy-vec2(radius))||any(pixel>bounds.zw+vec2(radius)))continue; const middle=curveRecord(vec2i(index,3)); const a=curveRecord(vec2i(index,1)),b=curveRecord(vec2i(index,2)); const bend=max(0,middle.z-u.appearance.z*0.5-pixelWidth()*2); const limit=depthOrder&&best.w>=1?max(0,u.appearance.z*0.5-pixelWidth()*0.5):best.x; if(min(intervalChordDistance(pixel,a.xy,middle.xy),intervalChordDistance(pixel,middle.xy,b.xy))>min(middle.z+radius,bend+limit))continue; const parameters=curveRecord(vec2i(index,0)); const delta=b.xy-a.xy; const fraction=clamp(dot(pixel-a.xy,delta)/max(dot(delta,delta),1e-20),0,1); const seed=mix(parameters.x,parameters.y,fraction*a.z/max(mix(b.z,a.z,fraction),1e-20)); let hit=refineTrajectoryHit(trajectory,pixel,vec4(0,seed,parameters.xy),u,false); const first=length(pixel-a.xy),last=length(pixel-b.xy); if(first<hit.x)hit=vec2(first,parameters.x); if(last<hit.x)hit=vec2(last,parameters.y); if(depthOrder)best=chooseSceneHit(trajectory,hit,best,u); else if(hit.x<best.x)best=vec4(hit,0,0); if(!depthOrder&&radius==0&&best.x<=max(0,u.appearance.z*0.5-pixelWidth()*0.5))return best; } } } return best; } function cachedTrajectoryDistance(trajectory: SpaceCurve, pixel: vec2, u: PlotUniforms): f32 { return cachedCurveHit(trajectory,pixel,u,0,false).x; } /** One-dimensional projected-axis layout. The table's column spacing is at most * one physical pixel; candidates retain exact world multiples and anchors. */ export function prepareSpatialLabels(position: vec4, u: PlotUniforms): vec4 { const row = i32(position.y), column = i32(position.x); const size = plotSize(u.resolution); if (row >= 36) { if (column >= 3) return vec4(0); const axis = column == 0 ? vec3(1, 0, 0) : column == 1 ? vec3(0, 1, 0) : vec3(0, 0, 1); if (row == 37) return vec4(spatialLevels(axis, u), 1); const edge = column == 1 ? vec2(size.x * 0.5, size.y - 30) : vec2(size.x - 30, size.y * 0.5); const world = axis * axisParameter(edge, axis, u); const at = clamp(project(world, u) + vec2(10, 18), vec2(18), size - vec2(18)); return vec4(at, f32(120 + column), inFront(world, u) ? 1 : 0); } const axisIndex = row / 12, candidate = (row / 2) % 6; const axis = axisIndex == 0 ? vec3(1, 0, 0) : axisIndex == 1 ? vec3(0, 1, 0) : vec3(0, 0, 1); const originH = homogeneous(vec3(0), u, false); const axisLine = cross(originH, homogeneous(axis, u, true)); const magnitude = length(axisLine.xy); if (magnitude <= 1e-12) return vec4(0); const normal = axisLine.xy / magnitude; const tangent = vec2(normal.y, -normal.x); const extent = dot(abs(tangent), size); const low = min(0, tangent.x * size.x) + min(0, tangent.y * size.y); const along = low + position.x / f32(u.curveTiles.w) * extent; const foot = tangent * along - normal * (axisLine.z / magnitude); const levels = spatialLevels(axis, u); const stride = candidate < 3 ? levels.x : levels.y; const nearest = floor(axisParameter(foot, axis, u) / stride + 0.5) * stride; const t = nearest + f32(candidate % 3 - 1) * stride; const world = axis * t; if (!inFront(world, u)) return vec4(0); const at = project(world, u); const fontSize = u.appearance.w; const sign = axis.y > 0 ? (normal.x > 0 ? -1 : 1) : (normal.y > 0 ? -1 : 1); const outward = normal * sign; if (row % 2 == 0) return vec4(at, outward); const anchor = at + outward * (fontSize * 0.95 + 6) + vec2(0, fontSize * 0.65); const width = numberWidth(t, levels.x, fontSize); const before = project(axis * (t - stride), u), after = project(axis * (t + stride), u); const separation = min(abs(at - before), abs(after - at)); const box = vec2(width + fontSize, fontSize * 1.8 + 6); const fit = smoothstep(0.85, 1.15, max(separation.x / box.x, separation.y / box.y)); const visibility = (candidate < 3 ? tickOpacity(t, levels) : coarseTickOpacity(t, levels)) * fit; const room = min(min(anchor.x - width * 0.5 - 3, size.x - anchor.x - width * 0.5 - 3), min(anchor.y - fontSize * 1.5, size.y - anchor.y)); const zero = abs(t) <= levels.x * 0.001; const crossing = zero ? (axis.x > 0 ? 1 : 0) : smoothstep(fontSize * 2, fontSize * 4, length(at - project(vec3(0), u))); let priority = 1; if (axisIndex == 2) { const origin = project(vec3(0), u); const xDirection = homogeneous(vec3(1, 0, 0), u, true), zDirection = homogeneous(vec3(0, 0, 1), u, true); const xTangent = normalize(xDirection.xy - origin * xDirection.z + vec2(1e-12)); const zTangent = normalize(zDirection.xy - origin * zDirection.z + vec2(1e-12)); priority = smoothstep(0.08, 0.25, abs(xTangent.x * zTangent.y - xTangent.y * zTangent.x)); } return vec4(t, levels.x, visibility, visibility * smoothstep(0, 6, room) * crossing * priority); } function cachedSpatialTicks(pixel: vec2, axis: vec3, index: i32, u: PlotUniforms): vec4 { const size = plotSize(u.resolution), fontSize = u.appearance.w; const axisLine = cross(homogeneous(vec3(0), u, false), homogeneous(axis, u, true)); const magnitude = length(axisLine.xy); if (magnitude <= 1e-12 || abs(dot(axisLine, vec3(pixel, 1))) / magnitude > fontSize * 6 + 12 + pixelWidth()) return vec4(0); const normal = axisLine.xy / magnitude; const tangent = vec2(normal.y, -normal.x); const low = min(0, tangent.x * size.x) + min(0, tangent.y * size.y); const coordinate = (dot(pixel, tangent) - low) / max(dot(abs(tangent), size), 1e-20); const column = clamp(i32(floor(coordinate * f32(u.curveTiles.w))), 0, i32(u.curveTiles.w) - 1); let labels = vec3(0); let ticks = 0; for (let candidate = 0; candidate < 6; candidate++) { const row = index * 12 + candidate * 2; const location = labelRecord(vec2i(column, row)); const at = location.xy, outward = location.zw; const anchor = at + outward * (fontSize * 0.95 + 6) + vec2(0, fontSize * 0.65); const delta = pixel - anchor; const nearLabel = (u.decorations & u32(2)) != u32(0) && abs(delta.x) <= fontSize * 9 && delta.y >= -fontSize * 1.5 - 3 - pixelWidth() && delta.y <= 3 + pixelWidth(); const nearTick = u.appearance.x > 0 && all(abs(pixel - at) <= vec2(u.appearance.x * 0.5 + 4 + pixelWidth())); if (!nearLabel && !nearTick) continue; const style = labelRecord(vec2i(column, row + 1)); if (nearTick && style.z > 0) ticks = max(ticks, tickMark(pixel, at, tangent, 3, u.appearance.x) * style.z); if (nearLabel && style.w > 0) labels = max(labels, numberAt(pixel, anchor, style.x, style.y, 0.5, fontSize, u.labelStyle.y, u.labelStyle.z) * style.w * u.decorationOpacity.y); } return vec4(ticks, labels); } function cachedSpatialBackground(uv: vec2, u: PlotUniforms): SpatialDecor { const size = plotSize(u.resolution), pixel = uv * size; const ray = viewRay(uv, u); const xLevels = labelRecord(vec2i(0, 37)).xyz; const zLevels = labelRecord(vec2i(2, 37)).xyz; const grid = groundField(ray, u, xLevels, zLevels); const xTicks = cachedSpatialTicks(pixel, vec3(1, 0, 0), 0, u); const yTicks = cachedSpatialTicks(pixel, vec3(0, 1, 0), 1, u); const zTicks = cachedSpatialTicks(pixel, vec3(0, 0, 1), 2, u); let labels = max(max(xTicks.yzw, yTicks.yzw), zTicks.yzw); let color = mix(vec3(0.965, 0.973, 0.985), vec3(0.8, 0.82, 0.85), grid * 0.65); color = mix(color, vec3(0.67, 0.28, 0.25), axisField(pixel, vec3(1, 0, 0), ray, u)); color = mix(color, vec3(0.23, 0.47, 0.3), axisField(pixel, vec3(0, 1, 0), ray, u)); color = mix(color, vec3(0.4, 0.35, 0.62), axisField(pixel, vec3(0, 0, 1), ray, u)); color = mix(color, vec3(0.25, 0.29, 0.35), max(max(xTicks.x, yTicks.x), zTicks.x)); if ((u.decorations & u32(4)) != u32(0)) { for (let index = 0; index < 3; index++) { const name = labelRecord(vec2i(index, 36)); if (name.w > 0) labels = max(labels, axisLabel(pixel, name.xy, i32(name.z), u) * u.decorationOpacity.z); } } return { color: mix(vec3(0.965, 0.973, 0.985), color, u.sceneOpacity.x), labels: labels * u.sceneOpacity.x }; } class SurfaceHit { point: vec3; depth: f32; valid: bool; } function surfaceInside(p: vec2, u: PlotUniforms): bool { return ((u.surfaceDomainMode & u32(1)) == u32(0) || p.x >= u.surfaceBounds.x) && ((u.surfaceDomainMode & u32(2)) == u32(0) || p.x <= u.surfaceBounds.z) && ((u.surfaceDomainMode & u32(4)) == u32(0) || p.y >= u.surfaceBounds.y) && ((u.surfaceDomainMode & u32(8)) == u32(0) || p.y <= u.surfaceBounds.w); } /** Intersect the height field itself; no host samples or triangle surface mesh. */ function surfaceHit(field: HeightField, uv: vec2, u: PlotUniforms): SurfaceHit { const ray = viewRay(uv, u); let near = u.surfaceDepth.x, far = u.surfaceDepth.y; for (let axis = 0; axis < 2; axis++) { const origin = axis == 0 ? ray.origin.x : ray.origin.z; const direction = axis == 0 ? ray.direction.x : ray.direction.z; const lower = axis == 0 ? u.surfaceBounds.x : u.surfaceBounds.y; const upper = axis == 0 ? u.surfaceBounds.z : u.surfaceBounds.w; const lowerFlag = axis == 0 ? u32(1) : u32(4), upperFlag = lowerFlag * u32(2); if (abs(direction) < 1e-20) { if (((u.surfaceDomainMode & lowerFlag) != u32(0) && origin < lower) || ((u.surfaceDomainMode & upperFlag) != u32(0) && origin > upper)) return {point: vec3(0), depth: 0, valid: false}; } else { if ((u.surfaceDomainMode & lowerFlag) != u32(0)) { const at = (lower - origin) / direction; if (direction > 0) near = max(near, at); else far = min(far, at); } if ((u.surfaceDomainMode & upperFlag) != u32(0)) { const at = (upper - origin) / direction; if (direction > 0) far = min(far, at); else near = max(near, at); } } } if (far < near) return {point: vec3(0), depth: 0, valid: false}; const fullSpan=max(far-near,1e-6); if((u.surfaceFlags & u32(96))!=u32(0)) { const lower=u.surfaceHeight.x-max(1e-7,abs(u.surfaceHeight.x)*1e-6),upper=u.surfaceHeight.y+max(1e-7,abs(u.surfaceHeight.y)*1e-6); if(abs(ray.direction.y)<1e-20) { if(((u.surfaceFlags & u32(32))!=u32(0)&&ray.origin.y<lower)||((u.surfaceFlags & u32(64))!=u32(0)&&ray.origin.y>upper))return {point:vec3(0),depth:0,valid:false}; } else { if((u.surfaceFlags & u32(32))!=u32(0)) {const at=(lower-ray.origin.y)/ray.direction.y;if(ray.direction.y>0)near=max(near,at);else far=min(far,at);} if((u.surfaceFlags & u32(64))!=u32(0)) {const at=(upper-ray.origin.y)/ray.direction.y;if(ray.direction.y>0)far=min(far,at);else near=max(near,at);} } } if(far<near)return {point:vec3(0),depth:0,valid:false}; let previous = near; const first = ray.origin + ray.direction * near; let before = first.y - field(first.x, first.z); const automatic=clamp(ceil(max(u.resolution.x,u.resolution.y)/8),32,256); const count = max(u32(1),u32(ceil(f32(max(u32(automatic),u.curveQuality.x))*(far-near)/fullSpan))); const tolerance=max(1e-6,min(u.plotSpan.x,u.plotSpan.y)/max(u.resolution.x,u.resolution.y)*0.01); for (let i: u32 = 1; i <= count; i++) { const at = mix(near, far, f32(i) / f32(count)); const p = ray.origin + ray.direction * at; const value = p.y - field(p.x, p.z); let bracketEnd=at,bracketValue=value; if(abs(value)<1e18&&abs(before)<1e18&&(value>=0)==(before>=0)) { // A narrow grazing intersection can enter and leave between two samples. // Inspect its local extremum instead of silently discarding the interval. const middle=(previous+at)*0.5,point=ray.origin+ray.direction*middle; const midValue=point.y-field(point.x,point.z); if(abs(midValue)<1e18) { if((midValue>=0)!=(before>=0)||midValue==0){bracketEnd=middle;bracketValue=midValue;} else { const curvature=before+value-2*midValue; const fraction=0.5+(before-value)/max(abs(4*curvature),1e-20)*(curvature<0?-1:1); if(curvature*before>0&&fraction>0&&fraction<1) { const candidate=mix(previous,at,fraction),q=ray.origin+ray.direction*candidate; const sample=q.y-field(q.x,q.z); if(abs(sample)<1e18&&((sample>=0)!=(before>=0)||sample==0)){bracketEnd=candidate;bracketValue=sample;} } } } } if (abs(bracketValue) < 1e18 && abs(before) < 1e18 && ((bracketValue >= 0) != (before >= 0) || bracketValue == 0 || before == 0)) { let low = previous, high = bracketEnd, residual = before,rightResidual=bracketValue; for (let iteration: u32 = 0; iteration < u32(40); iteration++) { const fraction=iteration%u32(3)==u32(2)?0.5:clamp(residual/(residual-rightResidual),0.25,0.75); const middle = mix(low,high,fraction); const point = ray.origin + ray.direction * middle; const sample = point.y - field(point.x, point.z); if (!(abs(sample) < 1e18)) break; if(abs(sample)<=tolerance&&length(project(vec3(point.x,point.y-sample,point.z),u)-uv*plotSize(u.resolution))<=0.02){low=middle;high=middle;break;} if ((sample >= 0) == (residual >= 0)) {low = middle; residual = sample;} else {high = middle;rightResidual=sample;} } const depth = (low + high) * 0.5; const point = ray.origin + ray.direction * depth; const sample = field(point.x, point.z); if (abs(sample) < 1e18 && abs(point.y - sample) <= tolerance && length(project(vec3(point.x,sample,point.z),u)-uv*plotSize(u.resolution))<=0.04 && surfaceInside(point.xz, u)) return {point: vec3(point.x, sample, point.z), depth, valid: true}; } before = value; previous = at; } return {point: vec3(0), depth: 0, valid: false}; } export function surfaceColorBar(color: vec3, uv: vec2, u: PlotUniforms): vec3 { if ((u.surfaceFlags & u32(8)) == u32(0)) return color; const size = plotSize(u.resolution), pixel = uv * size; const height = min(160, size.y * 0.36); const lower = vec2(size.x - 25, size.y - 70 - height), upper = lower + vec2(10, height); const q = max(lower - pixel, pixel - upper); const distance = max(q.x, q.y); const coverage = distanceCoverage(max(0, distance), 1.2); const t = clamp((pixel.y - lower.y) / height, 0, 1); let result = mix(color, colorMap(t, u32(u.surfaceRender.x)), coverage); const border = max(stroke(pixel, lower, vec2(lower.x, upper.y), 0.7), stroke(pixel, upper, vec2(upper.x, lower.y), 0.7)); result = mix(result, vec3(0.3), border); let labels = vec3(0); for (let index = 0; index < 3; index++) { const fraction = f32(index) * 0.5; const value = mix(u.surfaceRange.x, u.surfaceRange.y, fraction); const at = vec2(lower.x - 5, mix(lower.y, upper.y, fraction) + u.appearance.w * 0.7); labels = max(labels, numberAt(pixel, at, value, (u.surfaceRange.y - u.surfaceRange.x) * 0.5, 1, u.appearance.w, u.labelStyle.y, 0)); } return labelColor(result, labels); } function surfaceMaterial(field: HeightField, hit: SurfaceHit, u: PlotUniforms): vec4 { // Derivatives execute uniformly, including miss pixels. They filter contour and // wire fields at physical-pixel scale instead of tessellating their geometry. const footprint = max(vec2(length(vec2(dpdx(hit.point.x), dpdy(hit.point.x))), length(vec2(dpdx(hit.point.z), dpdy(hit.point.z)))), vec2(1e-20)); const valueRate = max(length(vec2(dpdx(hit.point.y), dpdy(hit.point.y))), 1e-20); const xLevels = axisLevels(u.plotCenter.x, u.plotSpan.x, u.resolution.x, true, u); const zLevels = axisLevels(0, max(u.plotSpan.x, u.plotSpan.y), u.resolution.y, false, u); const spacing = vec2(xLevels.x, zLevels.x); const wireDistance = abs(fract(hit.point.xz / spacing + vec2(0.5)) - vec2(0.5)) * spacing / footprint * pixelWidth(); const separation = spacing / footprint * pixelWidth(); const wire = max(distanceCoverage(wireDistance.x, u.appearance.z) * smoothstep(2, 6, separation.x), distanceCoverage(wireDistance.y, u.appearance.z) * smoothstep(2, 6, separation.y)); const contourDistance = abs(fract(hit.point.y / u.surfaceRender.z + 0.5) - 0.5) * u.surfaceRender.z / valueRate * pixelWidth(); const contours = distanceCoverage(contourDistance, u.appearance.z) * smoothstep(2, 6, u.surfaceRender.z / valueRate * pixelWidth()); let result = vec4(0); if (hit.valid) { const t = (hit.point.y - u.surfaceRange.x) / (u.surfaceRange.y - u.surfaceRange.x); let ink = colorMap(t, u32(u.surfaceRender.x)); if (u.view3d != u32(0) && (u.surfaceFlags & u32(1)) != u32(0)) { const h = max(1e-5, max(footprint.x, footprint.y) * 0.25); const left = field(hit.point.x - h, hit.point.z), right = field(hit.point.x + h, hit.point.z); const before = field(hit.point.x, hit.point.z - h), after = field(hit.point.x, hit.point.z + h); // Observation-grid edges and missing neighbors use one-sided derivatives. // Undefined sentinel values must never enter the lighting normal. const dx = abs(left) < 1e18 && abs(right) < 1e18 ? (right - left) / (2 * h) : abs(right) < 1e18 ? (right - hit.point.y) / h : abs(left) < 1e18 ? (hit.point.y - left) / h : 0; const dz = abs(before) < 1e18 && abs(after) < 1e18 ? (after - before) / (2 * h) : abs(after) < 1e18 ? (after - hit.point.y) / h : abs(before) < 1e18 ? (hit.point.y - before) / h : 0; const tx = cameraVector(vec3(1, dx, 0), u), tz = cameraVector(vec3(0, dz, 1), u); const crossNormal = cross(tz / max(max(max(abs(tz.x), abs(tz.y)), abs(tz.z)), 1e-20), tx / max(max(max(abs(tx.x), abs(tx.y)), abs(tx.z)), 1e-20)); const normalLength = length(crossNormal); let normal = normalLength > 1e-12 ? crossNormal / normalLength : vec3(0, 0, 1); if (normal.z < 0) normal = -normal; const diffuse = max(0, dot(normal, normalize(vec3(-0.4, 0.7, 1)))); const specular = ((max(0, dot(normal, normalize(vec3(-0.2, 0.35, 1))))) ** (32)) * 0.16; ink = ink * (0.4 + diffuse * 0.6) + vec3(specular); } const lines = max((u.surfaceFlags & u32(2)) != u32(0) ? wire : 0, (u.surfaceFlags & u32(4)) != u32(0) ? contours : 0); const filled = (u.surfaceFlags & u32(16)) != u32(0); if (filled) ink = mix(ink, vec3(0.12, 0.16, 0.22), lines * 0.65); result = vec4(ink, u.surfaceRender.y * (filled ? 1 : lines)); } return result; } /** Both flat scalar fields and spatial height fields share color normalization. */ export function plotSurface(field: HeightField, uv: vec2, u: PlotUniforms, cached: bool): vec4 { const flat = u.plotCenter + (uv - vec2(0.5)) * u.plotSpan; let hit: SurfaceHit = {point: vec3(flat.x, field(flat.x, flat.y), flat.y), depth: 0, valid: false}; if (u.view3d != u32(0)) hit = surfaceHit(field, uv, u); else hit.valid = abs(hit.point.y) < 1e18 && surfaceInside(flat, u); const material = surfaceMaterial(field, hit, u); let color = vec3(0.965, 0.973, 0.985), labels = vec3(0); let decor = vec4(0); if (u.view3d != u32(0)) { const background = cached ? cachedSpatialBackground(uv, axesUniforms(u)) : spatialBackground(uv, axesUniforms(u)); color = background.color; labels = background.labels; } else decor = axes2D(uv, u, 122) * u.sceneOpacity.x; color = mix(color, material.xyz, material.w * u.sceneOpacity.y); if (u.view3d == u32(0)) {color = mix(color, vec3(0.39, 0.43, 0.49), decor.x); labels = decor.yzw;} const decorated = labelColor(color, labels); return vec4(mix(decorated, surfaceColorBar(decorated, uv, u), u.sceneOpacity.y), 1); } /** Integer targets preserve exact f32 point bits on both backends, without float targets. */ export function pickSurface(field: HeightField, position: vec4, u: PlotUniforms): vec4u { const uv = query.pixel / plotSize(u.resolution); const p = u.plotCenter + (uv - vec2(0.5)) * u.plotSpan; let hit: SurfaceHit = {point: vec3(p.x, field(p.x, p.y), p.y), depth: 0, valid: false}; if (u.view3d != u32(0)) hit = surfaceHit(field, uv, u); else hit.valid = abs(hit.point.y) < 1e18 && surfaceInside(p, u); if (!hit.valid) return vec4u(0); return position.x < 1 ? vec4u(bitcast<vec3u>(hit.point), 1) : vec4u(bitcast<u32>(hit.point.y), 0, 0, 1); } function queryProjection(point: vec3, u: PlotUniforms): vec2 { return u.view3d == u32(0) ? ((point.xy-u.plotCenter)/u.plotSpan+vec2(0.5))*u.resolution : project(point,u); } function queryVisible(point: vec3, u: PlotUniforms): bool {return all(abs(point)<vec3(1e18))&&(u.view3d==u32(0)||inFront(point,u));} /** One-pixel query: use the same domains, clipped dash bands and half intervals as rendering. */ export function pickTrajectory(trajectory: SpaceCurve, position: vec4, u: PlotUniforms, scalar: bool, jumps: bool): vec4u { const pixel=query.pixel,focus=parameterFocus(trajectory,u); let lower=u.parameterBounds.x,upper=u.parameterBounds.y,unbounded=u.parameterMode!=u32(0); if(scalar) { unbounded=false; if(u.view3d==u32(0)) { const x=u.plotCenter.x+(pixel.x/u.resolution.x-0.5)*u.plotSpan.x; const span=u.plotSpan.x*(query.radius+u.appearance.z+2)/u.resolution.x; lower=x-span;upper=x+span; } else { const at=scalarParameter(pixel,u); const before=scalarParameter(pixel-vec2(query.radius,0),u),after=scalarParameter(pixel+vec2(query.radius,0),u); const span=max(abs(after.x-before.x),u.plotSpan.x*0.01); lower=at.x-span;upper=at.x+span; if(at.y==0){lower=focus.x-focus.y*32;upper=focus.x+focus.y*32;} } } const count=scalar?i32(u.curveQuality.x):curveIntervalCount(u); let best=1e20,parameter=u.probe; for(let index=0;index<count;index++) { let low=unbounded?parameterAt(-1+2*f32(index)/f32(count),focus.y,focus.x,u):mix(lower,upper,f32(index)/f32(count)); let high=unbounded?parameterAt(-1+2*f32(index+1)/f32(count),focus.y,focus.x,u):mix(lower,upper,f32(index+1)/f32(count)); if(u.curvePattern.x!=0) { const period=u.curvePattern.y; const center=(floor(((low+high)*0.5+u.curvePattern.z)/period)+0.5)*period-u.curvePattern.z; low=max(low,center-period*u.curvePattern.w*0.5);high=min(high,center+period*u.curvePattern.w*0.5); } if(high<low)continue; const middle=(low+high)*0.5; for(let half=0;half<2;half++) { let start=half==0?low:middle,end=half==0?middle:high; let a=trajectory(start),b=trajectory(end); if(!(all(abs(a)<vec3(1e18))&&all(abs(b)<vec3(1e18))))continue; const frontA=u.view3d!=u32(2)||inFront(a,u),frontB=u.view3d!=u32(2)||inFront(b,u); if(!frontA&&!frontB)continue; if(frontA!=frontB) { let left=start,right=end; for(let iteration=0;iteration<12;iteration++) { const t=(left+right)*0.5; if(inFront(trajectory(t),u)==frontA)left=t;else right=t; } if(frontA)end=left;else start=right; a=trajectory(start);b=trajectory(end); } const m=trajectory((start+end)*0.5); if(!(all(abs(m)<vec3(1e18)))||(jumps&&length(m-(a+b)*0.5)>max(1e-6,length(b-a)*0.2)))continue; const pa=queryProjection(a,u),pb=queryProjection(b,u),delta=pb-pa; const fraction=clamp(dot(pixel-pa,delta)/max(dot(delta,delta),1e-20),0,1); const wa=u.view3d==u32(0)?1:homogeneous(a,u,false).z,wb=u.view3d==u32(0)?1:homogeneous(b,u,false).z; let t=mix(start,end,fraction*wa/max(mix(wb,wa,fraction),1e-20)); const epsilon=max(max((end-start)*0.001,abs(t)*1e-6),1e-7); for(let iteration:u32=0;iteration<u.curveQuality.y;iteration++) { const left=max(start,t-epsilon),right=min(end,t+epsilon); const tangent=(queryProjection(trajectory(right),u)-queryProjection(trajectory(left),u))/max(right-left,1e-20); const at=queryProjection(trajectory(t),u),error=dot(at-pixel,at-pixel); let next=clamp(t-dot(at-pixel,tangent)/max(dot(tangent,tangent),1e-20),start,end); let world=trajectory(next),projected=queryProjection(world,u); if(!queryVisible(world,u)||dot(projected-pixel,projected-pixel)>error){next=(next+t)*0.5;world=trajectory(next);projected=queryProjection(world,u);} if(!queryVisible(world,u)||dot(projected-pixel,projected-pixel)>error||next==t)break; t=next; } const point=trajectory(t),distance=length(queryProjection(point,u)-pixel); if(queryVisible(point,u)&&distance<best){best=distance;parameter=t;} const first=length(pa-pixel),last=length(pb-pixel); if(first<best){best=first;parameter=start;} if(last<best){best=last;parameter=end;} } } if(best>query.radius+u.appearance.z*0.5||u.appearance.z<=0)return vec4u(0); const point=trajectory(parameter); return position.x<1?vec4u(bitcast<vec3u>(point),1):vec4u(bitcast<u32>(parameter),bitcast<u32>(best),0,1); } /** Straight color and exact f32 camera distance for one mathematical object. */ export class SceneLayer { color: location<0, vec4>; depth: location<1, vec4>; } class SceneMaterial { ink: vec4; bias: f32; } declare const sceneMaterial: uniform<SceneMaterial>; function packedDepth(depth: f32): vec4 { const bits = bitcast<u32>(depth); return vec4(f32(bits & u32(255)), f32((bits >> u32(8)) & u32(255)), f32((bits >> u32(16)) & u32(255)), f32(bits >> u32(24))) / 255; } function sceneLayer(color: vec4, depth: f32): SceneLayer { return { color, depth: packedDepth(depth + sceneMaterial.bias) }; } /** Union SDF coverage before resolving depth. Adjacent interval endpoint caps must * not replace a continuous stroke's opaque center with partial AA coverage. * Equally covered branches resolve front to back, including at curve folds. */ function chooseSceneHit(trajectory: SpaceCurve, hit: vec2, current: vec4, u: PlotUniforms): vec4 { const coverage = distanceCoverage(hit.x, u.appearance.z); if (coverage <= 0) return current; const depth = cameraDistance(trajectory(hit.y), u); if (!(depth >= 0.101 && depth < 1e30)) return current; return coverage > current.w || (coverage == current.w && (depth < current.z || (depth == current.z && hit.x < current.x))) ? vec4(hit, depth, coverage) : current; } function cachedSceneHit(trajectory: SpaceCurve, pixel: vec2, u: PlotUniforms): vec4 { return cachedCurveHit(trajectory,pixel,u,0,true); } function referenceSceneHit(trajectory: SpaceCurve, pixel: vec2, u: PlotUniforms, bounds: vec2, jumps: bool): vec4 { const requested = f32(u.curveQuality.x); const range = bounds.y - bounds.x; const unbounded = u.parameterMode != u32(0); const focus = unbounded ? parameterFocus(trajectory, u) : vec2(0, 1); const count = i32(min(512, unbounded || u.curvePattern.x == 0 ? requested : max(requested, ceil(range / u.curvePattern.y * 4)))); const stepSize = range / f32(count); let best = vec4(1e20, 0, 1e20, 0); for (let i = 0; i < count; i++) { let low = bounds.x + f32(i) * stepSize; let high = min(bounds.y, low + stepSize); if (unbounded) { low = parameterAt(-1 + 2 * f32(i) / f32(count), focus.y, focus.x, u); high = parameterAt(-1 + 2 * f32(i + 1) / f32(count), focus.y, focus.x, u); } let t = (low + high) * 0.5; if (u.curvePattern.x != 0) { const period = u.curvePattern.y; const center = (floor((t + u.curvePattern.z) / period) + 0.5) * period - u.curvePattern.z; low = max(low, center - period * u.curvePattern.w * 0.5); high = min(high, center + period * u.curvePattern.w * 0.5); t = (low + high) * 0.5; } if (high >= low) { const a = trajectory(low), middle = trajectory(t), b = trajectory(high); const finite = all(abs(a) < vec3(1e18)) && all(abs(middle) < vec3(1e18)) && all(abs(b) < vec3(1e18)); if (finite) { let possible = true; if (inFront(a, u) && inFront(middle, u) && inFront(b, u)) { const pa = project(a, u), pm = project(middle, u), pb = project(b, u); const bending = intervalChordDistance(pm, pa, pb); const guard = bending * 4 + u.appearance.z * 0.5 + pixelWidth() * 2; possible = min(intervalChordDistance(pixel, pa, pm), intervalChordDistance(pixel, pm, pb)) <= guard; } if (possible) { best = chooseSceneHit(trajectory, intervalHit(trajectory, pixel, low, t, u, jumps), best, u); best = chooseSceneHit(trajectory, intervalHit(trajectory, pixel, t, high, u, jumps), best, u); } } } } return best; } export function sceneCurve(trajectory: SpaceCurve, uv: vec2, u: PlotUniforms): SceneLayer { if (u.sceneOpacity.y <= 0 || u.appearance.z <= 0) return sceneLayer(vec4(0), 0); const hit = cachedSceneHit(trajectory, uv * plotSize(u.resolution), u); return sceneLayer(vec4(sceneMaterial.ink.xyz, hit.w * u.sceneOpacity.y * sceneMaterial.ink.w), hit.z); } export function sceneCurveReference(trajectory: SpaceCurve, uv: vec2, u: PlotUniforms, jumps: bool): SceneLayer { if (u.sceneOpacity.y <= 0 || u.appearance.z <= 0) return sceneLayer(vec4(0), 0); const hit = referenceSceneHit(trajectory, uv * plotSize(u.resolution), u, u.parameterBounds, jumps); return sceneLayer(vec4(sceneMaterial.ink.xyz, hit.w * u.sceneOpacity.y * sceneMaterial.ink.w), hit.z); } export function sceneSurface(field: HeightField, uv: vec2, u: PlotUniforms): SceneLayer { if (u.sceneOpacity.y <= 0) return sceneLayer(vec4(0), 0); const hit = surfaceHit(field, uv, u); const ink = surfaceMaterial(field, hit, u); return sceneLayer(vec4(ink.xyz, ink.w * u.sceneOpacity.y), hit.valid ? cameraDistance(hit.point, u) : 0); } export function sceneBackdrop(uv: vec2, u: PlotUniforms): vec4 { return vec4(cachedSpatialBackground(uv, axesUniforms(u)).color, 1); } export function sceneBackdropReference(uv: vec2, u: PlotUniforms): vec4 { return vec4(spatialBackground(uv, axesUniforms(u)).color, 1); } /** Isolate the affine label/halo/color-bar overlay without sampling scene objects. */ function sceneDecorLabels(uv: vec2, u: PlotUniforms, decor: SpatialDecor, surface: bool): vec4 { let black = labelColor(vec3(0), decor.labels), white = labelColor(vec3(1), decor.labels); if (surface) { black = mix(black, surfaceColorBar(black, uv, u), u.sceneOpacity.y); white = mix(white, surfaceColorBar(white, uv, u), u.sceneOpacity.y); } const alpha = clamp(1 - (white.x - black.x), 0, 1); return vec4(alpha > 0 ? black / alpha : vec3(0), alpha); } export function sceneLabels(uv: vec2, u: PlotUniforms, surface: bool): vec4 { return sceneDecorLabels(uv, u, cachedSpatialBackground(uv, axesUniforms(u)), surface); } export function sceneLabelsReference(uv: vec2, u: PlotUniforms, surface: bool): vec4 { return sceneDecorLabels(uv, u, spatialBackground(uv, axesUniforms(u)), surface); } export function querySceneCurve(trajectory: SpaceCurve, position: vec4, u: PlotUniforms): vec4u { const hit = cachedCurveHit(trajectory, query.pixel, u, query.radius, false); if (hit.x > query.radius+u.appearance.z*0.5+pixelWidth()*0.5 || u.sceneOpacity.y <= 0 || u.appearance.z<=0) return vec4u(0); const point = trajectory(hit.y); return position.x < 1 ? vec4u(bitcast<vec3u>(point), 1) : vec4u(bitcast<u32>(hit.y), bitcast<u32>(hit.x), 0, 1); } export function querySceneCurveReference(trajectory: SpaceCurve, position: vec4, u: PlotUniforms, jumps: bool): vec4u { const hit = referenceSceneHit(trajectory, query.pixel, u, u.parameterBounds, jumps); if (hit.w <= 0 || u.sceneOpacity.y <= 0) return vec4u(0); return position.x < 1 ? vec4u(bitcast<vec3u>(trajectory(hit.y)), 1) : vec4u(bitcast<u32>(hit.y), bitcast<u32>(hit.x), 0, 1); } font.shade.ts font.shade.ts… "use typeshade"; declare const glyphAtlas: texture_2d<f32>; class FontUniforms { pixelRatio: f32; } declare const font: uniform<FontUniforms>; export function pixelWidth(): f32 { return 1 / max(font.pixelRatio, 0.0001); } /** A square-ended tick in the screen-axis frame, with physical-pixel AA. * The long edge follows the exact perpendicular of the projected axis tangent. * Evaluate locally instead of subtracting short, rounded segment endpoints. */ export function tickMark(pixel: vec2, center: vec2, tangent: vec2, halfLength: f32, width: f32): f32 { if (width <= 0 || halfLength <= 0) return 0; const delta = pixel - center; const normal = vec2(-tangent.y, tangent.x); const q = abs(vec2(dot(delta, tangent), dot(delta, normal))) - vec2(width * 0.5, halfLength); const distance = length(max(q, vec2(0))) + min(max(q.x, q.y), 0); const aa = pixelWidth() * 0.5; return 1 - smoothstep(-aa, aa, distance); } /** X-GIS/TinySDF distance encoding over licensed IBM Plex input glyphs. * Source conventions: X-GIS/X-GIS map/src/shaders/dsl/text.ts (MIT). */ export function glyphIndex(code: i32): i32 { if (code >= 32 && code < 256) return code - 32; if (code >= 880 && code < 1024) return 224 + code - 880; if (code >= 12592 && code < 12688) return 368 + code - 12592; if (code >= 44032 && code <= 55203) return 464 + code - 44032; if (code >= 8192 && code < 8960) return 11636 + code - 8192; return 12404; } export function glyphLayers(p: vec2, code: i32, fontSize: f32, halo: f32): vec2 { // Match the physical display size to a native hinted glyph bucket. This // follows X-GIS's local-glyph size routing while keeping the atlas offline. const index = glyphIndex(code); const physicalSize = fontSize * font.pixelRatio; let referenceSize = 24; let cell = vec2(30, 36); let origin = vec2i((index % 132) * 30, (index / 132) * 36); if (code >= 32 && code < 128) { if (physicalSize <= 14) { referenceSize = 12; cell = vec2(15, 18); origin = vec2i((code - 32) * 15, 3384); } else if (physicalSize > 28) { referenceSize = 48; cell = vec2(60, 72); origin = vec2i(((code - 32) % 66) * 60, 3402 + ((code - 32) / 66) * 72); } } const q = p * (referenceSize / fontSize) - vec2(0.5); if (q.x < 0 || q.y < 0 || q.x >= cell.x - 1 || q.y >= cell.y - 1) return vec2(0); const base = vec2i(floor(q)); const t = fract(q); const a = textureLoad(glyphAtlas, origin + base, 0).r; const b = textureLoad(glyphAtlas, origin + base + vec2i(1, 0), 0).r; const c = textureLoad(glyphAtlas, origin + base + vec2i(0, 1), 0).r; const d = textureLoad(glyphAtlas, origin + base + vec2i(1, 1), 0).r; const distance = mix(mix(a, b, t.x), mix(c, d, t.x), t.y); // X-GIS fill edge and analytic AA: EDGE_GAMMA 0.105 * ONE_EM 24. // Explicit physical size keeps the rule valid inside numeric label branches. const edge = 0.75; const width = max(2.52 / max(fontSize * font.pixelRatio, 1), 1 / 255); const fill = smoothstep(edge - width, edge + width, distance); // Atlas radius is one third em. Expand the same distance field in CSS pixels. const outerEdge = edge - min(halo, fontSize * 0.1) * 3 / fontSize; return vec2(fill, smoothstep(outerEdge - width, outerEdge + width, distance)); } export function glyphCoverage(p: vec2, code: i32, fontSize: f32): f32 { return glyphLayers(p, code, fontSize, 0).x; } class NumberFormat { value: f32; negative: bool; scientific: bool; decimals: i32; digits: i32; exponent: i32; length: i32; } function numberFormat(input: f32, spacing: f32): NumberFormat { const value = abs(input) < abs(spacing) * 0.0001 ? 0 : input; let magnitude = abs(value); let exponent = i32(floor(log2(max(magnitude, 1e-30)) / log2(10))); const scientific = magnitude > 0 && (exponent >= 5 || exponent < -3); let decimals = i32(clamp(ceil(-log2(max(abs(spacing), 1e-30)) / log2(10)), 0, 6)); let digits: i32 = 1; if (scientific) { decimals = i32(clamp(ceil(f32(exponent) - log2(max(abs(spacing), 1e-30)) / log2(10)), 0, 6)); const scale = ((10) ** (f32(decimals))); magnitude = floor(magnitude / ((10) ** (f32(exponent))) * scale + 0.5); if (magnitude >= 10 * scale) { magnitude = scale; exponent = exponent + 1; } } else { magnitude = floor(magnitude * ((10) ** (f32(decimals))) + 0.5); digits = i32(floor(log2(max(floor(magnitude / ((10) ** (f32(decimals)))), 1)) / log2(10))) + 1; } for (let i = 0; i < 6; i++) { if (decimals > 0 && abs(magnitude - floor(magnitude / 10) * 10) < 0.01) { magnitude /= 10; decimals -= 1; } } const negative = value < 0; const length: i32 = scientific ? 5 + (decimals > 0 ? 1 + decimals : 0) + (negative ? i32(1) : i32(0)) : digits + (decimals > 0 ? 1 + decimals : 0) + (negative ? i32(1) : i32(0)); return { value: magnitude, negative, scientific, decimals, digits, exponent, length }; } /** Select a formatted character independently of its padded atlas cell. */ function numberGlyph(n: NumberFormat, column: i32): i32 { let i = column; if (n.negative && i == 0) return 45; i = i - (n.negative ? i32(1) : i32(0)); if (n.scientific) { const mantissaLength = 1 + (n.decimals > 0 ? 1 + n.decimals : 0); if (i < mantissaLength) { if (n.decimals > 0 && i == 1) return 46; const digit = i - (i > 1 ? i32(1) : i32(0)); return 48 + i32(floor(n.value / ((10) ** (f32(n.decimals - digit))))) % 10; } const suffix = i - mantissaLength; if (suffix == 0) return 101; if (suffix == 1) return n.exponent < 0 ? 45 : 43; if (suffix == 2) return 48 + abs(n.exponent) / 10; return 48 + abs(n.exponent) % 10; } if (n.decimals > 0 && i == n.digits) return 46; const digit = i - (i > n.digits ? i32(1) : i32(0)); return 48 + i32(floor(n.value / ((10) ** (f32(n.digits + n.decimals - digit - 1))))) % 10; } /** Keep full SDF padding at character boundaries, as X-GIS glyph slots do. * Advance locates each glyph; it must never act as a clipping rectangle. */ export function tickNumberLayers(p: vec2, value: f32, spacing: f32, align: f32, fontSize: f32, halo: f32): vec2 { const n = numberFormat(value, spacing); const advance = fontSize * 0.625; const offset = p + vec2(f32(n.length) * advance * align, 0); if (offset.y < 0 || offset.y > fontSize * 1.5) return vec2(0); const column = i32(floor(offset.x / advance)); const atlasBearing = fontSize * (3 / 24); let coverage = vec2(0); for (let neighbor = -1; neighbor <= 1; neighbor++) { const index = column + neighbor; if (index >= 0 && index < n.length) { const local = vec2(offset.x - f32(index) * advance + atlasBearing, offset.y); coverage = max(coverage, glyphLayers(local, numberGlyph(n, index), fontSize, halo)); } } return coverage; } export function tickNumber(p: vec2, value: f32, spacing: f32, align: f32): f32 { return tickNumberSized(p, value, spacing, align, 11); } export function tickNumberSized(p: vec2, value: f32, spacing: f32, align: f32, fontSize: f32): f32 { return tickNumberLayers(p, value, spacing, align, fontSize, 0).x; } export function numberWidth(value: f32, spacing: f32, size: f32): f32 { return f32(numberFormat(value, spacing).length) * size * 0.625; } /** Hierarchical decimal lattices: shared ticks retain full opacity at every LOD boundary. * Intermediate ticks fade as a continuous function of scale, without camera lag. */ export function tickLevels(raw: f32): vec3 { const safe = max(raw, 1e-25); const unit = ((10) ** (floor(log2(safe) / log2(10)))); const fine = safe < unit * 2 ? unit : safe < unit * 5 ? unit * 2 : unit * 5; const coarse = safe < unit * 2 ? unit * 2 : safe < unit * 5 ? unit * 5 : unit * 10; const phase = log2(safe / fine) / log2(coarse / fine); return vec3(fine, coarse, 1 - smoothstep(0, 1, phase)); } export function tickOpacity(value: f32, levels: vec3): f32 { const multiple = value / levels.y; return abs(multiple - floor(multiple + 0.5)) < 0.001 ? 1 : levels.z; } /** Compact rounded label plate, using the exact formatted numeric advance. */ export function numberPlate(p: vec2, value: f32, spacing: f32, align: f32, size: f32): f32 { const width = numberWidth(value, spacing, size); const center = vec2(width * (0.5 - align), size * 0.76); const half = vec2(width * 0.5 + 3.5, size * 0.55 + 2); const q = abs(p - center) - half + vec2(3); const distance = length(max(q, vec2(0))) + min(max(q.x, q.y), 0) - 3; return 1 - smoothstep(-pixelWidth() * 0.5, pixelWidth() * 0.5, distance); } /** At non-nested 2/5 transitions only shared multiples remain fully opaque. */ export function coarseTickOpacity(value: f32, levels: vec3): f32 { const multiple = value / levels.x; return abs(multiple - floor(multiple + 0.5)) < 0.001 ? 1 : 1 - levels.z; } palette.shade.ts palette.shade.ts… "use typeshade"; /** Compact linear color-map anchors, evaluated on the GPU. */ export function colorMap(value: f32, palette: u32): vec3 { const t = clamp(value, 0, 1); if (palette == u32(3)) return vec3(t); if (palette == u32(2)) return t < 0.5 ? mix(vec3(0.23, 0.30, 0.75), vec3(0.87), t * 2) : mix(vec3(0.87), vec3(0.71, 0.02, 0.15), t * 2 - 1); let a = vec3(0.267, 0.005, 0.329), b = vec3(0.230, 0.322, 0.546), c = vec3(0.128, 0.567, 0.551), d = vec3(0.369, 0.789, 0.383), e = vec3(0.993, 0.906, 0.144); if (palette == u32(1)) {a = vec3(0.050, 0.030, 0.528); b = vec3(0.495, 0.012, 0.658); c = vec3(0.798, 0.280, 0.470); d = vec3(0.973, 0.586, 0.252); e = vec3(0.940, 0.975, 0.131);} if (t < 0.25) return mix(a, b, t * 4); if (t < 0.5) return mix(b, c, t * 4 - 1); if (t < 0.75) return mix(c, d, t * 4 - 2); return mix(d, e, t * 4 - 3); } 페이지가 매 프레임 채우는 값이라 컨트롤이 없습니다: resolution, plotCenter, plotSpan, plotRotation, plotBlend. 출력 결과 컴파일러가 본 모듈 전체입니다. 버텍스 진입점과 그것이 돌려주는 VsOut 구조체는 페이지가 붙였고, 나머지는 위 파일입니다. WGSL…struct FontUniforms { pixelRatio: f32, } struct NumberFormat { value: f32, negative: bool, scientific: bool, decimals: i32, digits: i32, exponent: i32, length: i32, } struct PlotViewport { resolution: vec2<f32>, plotCenter: vec2<f32>, plotSpan: vec2<f32>, plotRotation: vec2<f32>, rotationBasis: vec4<f32>, plotPan: vec2<f32>, plotBlend: f32, appearance: vec4<f32>, decorations: u32, labelStyle: vec4<f32>, decorationOpacity: vec3<f32>, } struct PlotUniforms { resolution: vec2<f32>, plotCenter: vec2<f32>, plotSpan: vec2<f32>, plotRotation: vec2<f32>, rotationBasis: vec4<f32>, plotPan: vec2<f32>, plotBlend: f32, appearance: vec4<f32>, decorations: u32, labelStyle: vec4<f32>, decorationOpacity: vec3<f32>, model: mat4x4<f32>, inverseModel: mat4x4<f32>, axesModel: mat4x4<f32>, inverseAxesModel: mat4x4<f32>, sceneOpacity: vec2<f32>, cameraLens: vec2<f32>, plotCenterZ: f32, probe: f32, parameterFocusSeed: f32, view3d: u32, parameterBounds: vec2<f32>, parameterMode: u32, curveQuality: vec2<u32>, curvePattern: vec4<f32>, curveTiles: vec4<u32>, surfaceBounds: vec4<f32>, surfaceDomainMode: u32, surfaceRange: vec2<f32>, surfaceHeight: vec2<f32>, surfaceDepth: vec2<f32>, surfaceRender: vec4<f32>, surfaceFlags: u32, } struct ViewRay { origin: vec3<f32>, direction: vec3<f32>, } struct SpatialDecor { color: vec3<f32>, labels: vec3<f32>, } struct VsOut { @builtin(position) pos: vec4<f32>, @location(0) uv: vec2<f32>, } struct Uniforms { resolution: vec2<f32>, plotCenter: vec2<f32>, plotSpan: vec2<f32>, plotRotation: vec2<f32>, rotationBasis: vec4<f32>, plotPan: vec2<f32>, plotBlend: f32, appearance: vec4<f32>, decorations: u32, labelStyle: vec4<f32>, decorationOpacity: vec3<f32>, model: mat4x4<f32>, inverseModel: mat4x4<f32>, axesModel: mat4x4<f32>, inverseAxesModel: mat4x4<f32>, sceneOpacity: vec2<f32>, cameraLens: vec2<f32>, plotCenterZ: f32, probe: f32, parameterFocusSeed: f32, view3d: u32, parameterBounds: vec2<f32>, parameterMode: u32, curveQuality: vec2<u32>, curvePattern: vec4<f32>, curveTiles: vec4<u32>, surfaceBounds: vec4<f32>, surfaceDomainMode: u32, surfaceRange: vec2<f32>, surfaceHeight: vec2<f32>, surfaceDepth: vec2<f32>, surfaceRender: vec4<f32>, surfaceFlags: u32, } @group(0) @binding(0) var<uniform> u: Uniforms; @group(0) @binding(1) var glyphAtlas: texture_2d<f32>; @group(0) @binding(2) var<uniform> font: FontUniforms; fn tickMark(pixel: vec2<f32>, center: vec2<f32>, tangent: vec2<f32>, halfLength: f32, width: f32) -> f32 { if (((width <= 0.0) || (halfLength <= 0.0))) { return 0.0; } let delta = (pixel - center); let normal = vec2<f32>((-tangent.y), tangent.x); let q = (abs(vec2<f32>(dot(delta, tangent), dot(delta, normal))) - vec2<f32>((width * 0.5), halfLength)); let distance = (length(max(q, vec2<f32>(0.0))) + min(max(q.x, q.y), 0.0)); let aa = ((1.0 / max(font.pixelRatio, 0.0001)) * 0.5); return (1.0 - smoothstep((-aa), aa, distance)); } fn glyphLayers(p: vec2<f32>, code: i32, fontSize: f32, halo: f32) -> vec2<f32> { var _i0ret: i32; let _cse0 = (code >= 32); let _cse1 = (code - 32); if ((_cse0 && (code < 256))) { _i0ret = _cse1; } else { if (((code >= 880) && (code < 1024))) { _i0ret = ((224 + code) - 880); } else { if (((code >= 12592) && (code < 12688))) { _i0ret = ((368 + code) - 12592); } else { _i0ret = select(select(12404, ((11636 + code) - 8192), ((code >= 8192) && (code < 8960))), ((464 + code) - 44032), ((code >= 44032) && (code <= 55203))); } } } let index = _i0ret; let _cse2 = (fontSize * font.pixelRatio); var referenceSize: f32 = 24.0; var cell: vec2<f32> = vec2<f32>(30.0, 36.0); var origin: vec2<i32> = vec2<i32>(((index % 132) * 30), ((index / 132) * 36)); if ((_cse0 && (code < 128))) { if ((_cse2 <= 14.0)) { referenceSize = 12.0; cell = vec2<f32>(15.0, 18.0); origin = vec2<i32>((_cse1 * 15), 3384); } else if ((_cse2 > 28.0)) { referenceSize = 48.0; cell = vec2<f32>(60.0, 72.0); origin = vec2<i32>(((_cse1 % 66) * 60), (3402 + ((_cse1 / 66) * 72))); } } let q = ((p * (referenceSize / fontSize)) - vec2<f32>(0.5)); if (((((q.x < 0.0) || (q.y < 0.0)) || (q.x >= (cell.x - 1.0))) || (q.y >= (cell.y - 1.0)))) { return vec2<f32>(0.0); } let base = vec2<i32>(floor(q)); let t = fract(q); let _gv0 = (origin + base); let a = textureLoad(glyphAtlas, _gv0, 0u).r; let b = textureLoad(glyphAtlas, (_gv0 + vec2<i32>(1, 0)), 0u).r; let c = textureLoad(glyphAtlas, (_gv0 + vec2<i32>(0, 1)), 0u).r; let d = textureLoad(glyphAtlas, (_gv0 + vec2<i32>(1, 1)), 0u).r; let distance = mix(mix(a, b, t.x), mix(c, d, t.x), t.y); let width = max((2.52 / max(_cse2, 1.0)), 0.00392156862745098); let fill = smoothstep((0.75 - width), (0.75 + width), distance); let outerEdge = (0.75 - ((min(halo, (fontSize * 0.1)) * 3.0) / fontSize)); return vec2<f32>(fill, smoothstep((outerEdge - width), (outerEdge + width), distance)); } fn numberFormat(input: f32, spacing: f32) -> NumberFormat { let _cse2 = abs(spacing); let value = select(input, 0.0, (abs(input) < (_cse2 * 0.0001))); var magnitude: f32 = abs(value); let _cse0 = log2(10.0); var exponent: i32 = i32(floor((log2(max(magnitude, 1e-30)) / _cse0))); let scientific = ((magnitude > 0.0) && ((exponent >= 5) || (exponent < -3))); let _cse1 = log2(max(_cse2, 1e-30)); var decimals: i32 = i32(clamp(ceil(((-_cse1) / _cse0)), 0.0, 6.0)); var digits: i32 = 1; if (scientific) { let _gv0 = f32(exponent); decimals = i32(clamp(ceil((_gv0 - (_cse1 / _cse0))), 0.0, 6.0)); let scale = pow(10.0, f32(decimals)); magnitude = floor((((magnitude / pow(10.0, _gv0)) * scale) + 0.5)); let _ifc0 = (magnitude >= (10.0 * scale)); magnitude = select(magnitude, scale, _ifc0); exponent = select(exponent, (exponent + 1), _ifc0); } else { let _gv1 = pow(10.0, f32(decimals)); magnitude = floor(((magnitude * _gv1) + 0.5)); digits = (i32(floor((log2(max(floor((magnitude / _gv1)), 1.0)) / _cse0))) + 1); } for (var i: i32 = 0; (i < 6); i = (i + 1)) { let _ifc1 = ((decimals > 0) && (abs((magnitude - (floor((magnitude / 10.0)) * 10.0))) < 0.01)); magnitude = select(magnitude, (magnitude / 10.0), _ifc1); decimals = select(decimals, (decimals - 1), _ifc1); } let negative = (value < 0.0); let length = select(((digits + select(0, (1 + decimals), (decimals > 0))) + select(0, 1, negative)), ((5 + select(0, (1 + decimals), (decimals > 0))) + select(0, 1, negative)), scientific); return NumberFormat(magnitude, negative, scientific, decimals, digits, exponent, length); } fn numberFormat_into(_dst: ptr<function, NumberFormat>, input: f32, spacing: f32) { let _cse2 = abs(spacing); let value = select(input, 0.0, (abs(input) < (_cse2 * 0.0001))); var magnitude: f32 = abs(value); let _cse0 = log2(10.0); var exponent: i32 = i32(floor((log2(max(magnitude, 1e-30)) / _cse0))); let scientific = ((magnitude > 0.0) && ((exponent >= 5) || (exponent < -3))); let _cse1 = log2(max(_cse2, 1e-30)); var decimals: i32 = i32(clamp(ceil(((-_cse1) / _cse0)), 0.0, 6.0)); var digits: i32 = 1; if (scientific) { let _gv0 = f32(exponent); decimals = i32(clamp(ceil((_gv0 - (_cse1 / _cse0))), 0.0, 6.0)); let scale = pow(10.0, f32(decimals)); magnitude = floor((((magnitude / pow(10.0, _gv0)) * scale) + 0.5)); let _ifc0 = (magnitude >= (10.0 * scale)); magnitude = select(magnitude, scale, _ifc0); exponent = select(exponent, (exponent + 1), _ifc0); } else { let _gv1 = pow(10.0, f32(decimals)); magnitude = floor(((magnitude * _gv1) + 0.5)); digits = (i32(floor((log2(max(floor((magnitude / _gv1)), 1.0)) / _cse0))) + 1); } for (var i: i32 = 0; (i < 6); i = (i + 1)) { let _ifc1 = ((decimals > 0) && (abs((magnitude - (floor((magnitude / 10.0)) * 10.0))) < 0.01)); magnitude = select(magnitude, (magnitude / 10.0), _ifc1); decimals = select(decimals, (decimals - 1), _ifc1); } let negative = (value < 0.0); let length = select(((digits + select(0, (1 + decimals), (decimals > 0))) + select(0, 1, negative)), ((5 + select(0, (1 + decimals), (decimals > 0))) + select(0, 1, negative)), scientific); (*_dst) = NumberFormat(magnitude, negative, scientific, decimals, digits, exponent, length); } fn tickNumberLayers(p: vec2<f32>, value: f32, spacing: f32, align: f32, fontSize: f32, halo: f32) -> vec2<f32> { var n: NumberFormat; numberFormat_into(&n, value, spacing); let advance = (fontSize * 0.625); let offset = (p + vec2<f32>(((f32(n.length) * advance) * align), 0.0)); let _cse0 = vec2<f32>(0.0); if (((offset.y < 0.0) || (offset.y > (fontSize * 1.5)))) { return _cse0; } let column = i32(floor((offset.x / advance))); let atlasBearing = (fontSize * 0.125); var coverage: vec2<f32> = _cse0; for (var neighbor: i32 = -1; (neighbor <= 1); neighbor = (neighbor + 1)) { let index = (column + neighbor); if (((index >= 0) && (index < n.length))) { let local = vec2<f32>(((offset.x - (f32(index) * advance)) + atlasBearing), offset.y); var _i1ret: i32; var _i1_i: i32 = index; if ((n.negative && (_i1_i == 0))) { _i1ret = 45; } else { _i1_i = (_i1_i - select(0, 1, n.negative)); if (n.scientific) { let _gv0 = (n.decimals > 0); let _i1_mantissaLength = (1 + select(0, (1 + n.decimals), _gv0)); if ((_i1_i < _i1_mantissaLength)) { if ((_gv0 && (_i1_i == 1))) { _i1ret = 46; } else { let _i1_digit = (_i1_i - select(0, 1, (_i1_i > 1))); _i1ret = (48 + (i32(floor((n.value / pow(10.0, f32((n.decimals - _i1_digit)))))) % 10)); } } else { let _i1_suffix = (_i1_i - _i1_mantissaLength); if ((_i1_suffix == 0)) { _i1ret = 101; } else { if ((_i1_suffix == 1)) { _i1ret = select(43, 45, (n.exponent < 0)); } else { _i1ret = select((48 + (abs(n.exponent) % 10)), (48 + (abs(n.exponent) / 10)), (_i1_suffix == 2)); } } } } else { if (((n.decimals > 0) && (_i1_i == n.digits))) { _i1ret = 46; } else { let _i1_digit_1 = (_i1_i - select(0, 1, (_i1_i > n.digits))); _i1ret = (48 + (i32(floor((n.value / pow(10.0, f32((((n.digits + n.decimals) - _i1_digit_1) - 1)))))) % 10)); } } } coverage = max(coverage, glyphLayers(local, _i1ret, fontSize, halo)); } } return coverage; } fn numberWidth(value: f32, spacing: f32, size: f32) -> f32 { return ((f32(numberFormat(value, spacing).length) * size) * 0.625); } fn tickLevels(raw: f32) -> vec3<f32> { let safe = max(raw, 1e-25); let unit = pow(10.0, floor((log2(safe) / log2(10.0)))); let _gv0 = (safe < (unit * 2.0)); let fine = select(select((unit * 5.0), (unit * 2.0), (safe < (unit * 5.0))), unit, _gv0); let coarse = select(select((unit * 10.0), (unit * 5.0), (safe < (unit * 5.0))), (unit * 2.0), _gv0); let phase = (log2((safe / fine)) / log2((coarse / fine))); return vec3<f32>(fine, coarse, (1.0 - smoothstep(0.0, 1.0, phase))); } fn tickOpacity(value: f32, levels: vec3<f32>) -> f32 { let multiple = (value / levels.y); return select(levels.z, 1.0, (abs((multiple - floor((multiple + 0.5)))) < 0.001)); } fn numberPlate(p: vec2<f32>, value: f32, spacing: f32, align: f32, size: f32) -> f32 { let width = numberWidth(value, spacing, size); let center = vec2<f32>((width * (0.5 - align)), (size * 0.76)); let half = vec2<f32>(((width * 0.5) + 3.5), ((size * 0.55) + 2.0)); let q = ((abs((p - center)) - half) + vec2<f32>(3.0)); let distance = ((length(max(q, vec2<f32>(0.0))) + min(max(q.x, q.y), 0.0)) - 3.0); let _cse0 = (1.0 / max(font.pixelRatio, 0.0001)); return (1.0 - smoothstep(((-_cse0) * 0.5), (_cse0 * 0.5), distance)); } fn coarseTickOpacity(value: f32, levels: vec3<f32>) -> f32 { let multiple = (value / levels.x); return select((1.0 - levels.z), 1.0, (abs((multiple - floor((multiple + 0.5)))) < 0.001)); } fn axisLabel(pixel: vec2<f32>, at: vec2<f32>, code: i32, function_plot_u_2: PlotViewport) -> vec3<f32> { if (_flow139_shared(pixel, at, function_plot_u_2.appearance.w, font.pixelRatio)) { return vec3<f32>(0.0); } let local = vec2<f32>((pixel.x - at.x), ((at.y - pixel.y) + (function_plot_u_2.appearance.w * 0.75))); return vec3<f32>(glyphLayers((local + vec2<f32>((function_plot_u_2.appearance.w * 0.42), 0.0)), code, function_plot_u_2.appearance.w, function_plot_u_2.labelStyle.y), (numberPlate(local, 0.0, 1.0, 0.5, function_plot_u_2.appearance.w) * function_plot_u_2.labelStyle.z)); } fn distanceCoverage(distance: f32, width: f32) -> f32 { if ((width <= 0.0)) { return 0.0; } let aa = ((1.0 / max(font.pixelRatio, 0.0001)) * 0.5); let _cse0 = (width * 0.5); return (1.0 - smoothstep(max(0.0, (_cse0 - aa)), (_cse0 + aa), distance)); } fn stroke(p: vec2<f32>, a: vec2<f32>, b: vec2<f32>, width: f32) -> f32 { let radius = (width * 0.5); if ((((width <= 0.0) || any((p < (min(a, b) - vec2<f32>((radius + 1.0)))))) || any((p > (max(a, b) + vec2<f32>((radius + 1.0))))))) { return 0.0; } let ab = (b - a); let _cse0 = (p - a); let t = clamp((dot(_cse0, ab) / max(dot(ab, ab), 0.0001)), 0.0, 1.0); return distanceCoverage(length((_cse0 - (ab * t))), width); } fn numberAt(pixel: vec2<f32>, anchor: vec2<f32>, value: f32, spacing: f32, align: f32, size: f32, halo: f32, plate: f32) -> vec3<f32> { let _cse0 = (pixel.x - anchor.x); let _cse1 = (anchor.y - pixel.y); let delta = vec2<f32>(_cse0, _cse1); if ((((_cse1 < 0.0) || (_cse1 > (size * 1.5))) || (abs(_cse0) > (size * 16.0)))) { return vec3<f32>(0.0); } return vec3<f32>(tickNumberLayers(delta, value, spacing, align, size, halo), (numberPlate(delta, value, spacing, align, size) * plate)); } fn labelColor(color: vec3<f32>, labels: vec3<f32>) -> vec3<f32> { let plated = mix(color, vec3<f32>(0.995), (labels.z * 0.94)); return mix(mix(plated, vec3<f32>(0.965, 0.973, 0.985), labels.y), vec3<f32>(0.25, 0.29, 0.35), labels.x); } fn pointColor(color: vec3<f32>, p: vec2<f32>, selected: vec2<f32>) -> vec3<f32> { let _cse0 = (p - selected); if (any((abs(_cse0) > vec2<f32>(7.0)))) { return color; } let radius = length(_cse0); let halo = (1.0 - smoothstep(5.0, 7.0, radius)); let dot = (1.0 - smoothstep(3.0, 4.5, radius)); return mix(mix(color, vec3<f32>(1.0), halo), vec3<f32>(0.89, 0.29, 0.04), dot); } fn axes2D(uv: vec2<f32>, function_plot_u_4: PlotViewport, vertical: i32) -> vec4<f32> { let _licm0 = vec2<f32>(1.0, 0.0); let _licm1 = function_plot_u_4.appearance.x; let _licm2 = vec2<f32>(0.0, 1.0); let _licm3 = function_plot_u_4.appearance.y; let _licm4 = function_plot_u_4.appearance.w; let _licm5 = (function_plot_u_4.appearance.w * 1.6); let _licm6 = (function_plot_u_4.appearance.w * 2.2); let _licm7 = (function_plot_u_4.appearance.w * 0.65); let _licm8 = function_plot_u_4.labelStyle.y; let _licm9 = function_plot_u_4.labelStyle.z; let _licm10 = (function_plot_u_4.appearance.w * 0.75); let size = max(function_plot_u_4.resolution, vec2<f32>(1.0)); let span = max(function_plot_u_4.plotSpan, vec2<f32>(0.00001)); let lo = (function_plot_u_4.plotCenter - (span * 0.5)); let p = (lo + (uv * span)); let pixel = (uv * size); let _cse0 = vec2<f32>(14.0); let origin = clamp((((-lo) / span) * size), _cse0, (size - _cse0)); let _gv0 = (size.x - 12.0); var axes: f32 = max(stroke(pixel, vec2<f32>(12.0, origin.y), vec2<f32>(_gv0, origin.y), _licm1), stroke(pixel, vec2<f32>(origin.x, 12.0), vec2<f32>(origin.x, (size.y - 12.0)), _licm1)); let _i14a0 = function_plot_u_4.plotCenter.x; let _i14a1 = span.x; let _i14a2 = size.x; let _i14_rough = (((_i14a1 * _licm4) * 4.0) / max(_i14a2, 1.0)); let _lc0 = (_i14a1 * 0.5); let _i14_width = max(numberWidth((_i14a0 - _lc0), _i14_rough, _licm4), numberWidth((_i14a0 + _lc0), _i14_rough, _licm4)); let _i14_gap = max((_licm4 * 3.5), (_i14_width + (_licm4 * 1.3))); let _i14ret = tickLevels(((_i14a1 * _i14_gap) / max((_i14a2 * function_plot_u_4.labelStyle.x), 1.0))); let _i15a1 = span.y; let _i15a2 = size.y; let _i15_gap = (_licm4 * 2.6); let _i15ret = tickLevels(((_i15a1 * _i15_gap) / max((_i15a2 * function_plot_u_4.labelStyle.x), 1.0))); var labels: vec3<f32> = vec3<f32>(0.0); var backgroundGrid: f32 = 0.0; let _cse1 = ((function_plot_u_4.decorations & 2u) != 0u); let _cse2 = (_licm4 * 2.0); let _cse3 = (_licm4 * 6.0); for (var level: i32 = 0; (level < 2); level = (level + 1)) { let _gv1 = (level == 0); let tickStep = select(vec2<f32>(_i14ret.y, _i15ret.y), vec2<f32>(_i14ret.x, _i15ret.x), _gv1); let nearest = (floor(((p / tickStep) + 0.5)) * tickStep); var _sel0: vec2<f32>; if (_gv1) { _sel0 = vec2<f32>(tickOpacity(nearest.x, _i14ret), tickOpacity(nearest.y, _i15ret)); } else { _sel0 = vec2<f32>(coarseTickOpacity(nearest.x, _i14ret), coarseTickOpacity(nearest.y, _i15ret)); } let weights = _sel0; let grid = ((abs((p - nearest)) / span) * size); let at = (((nearest - lo) / span) * size); axes = max(axes, max((tickMark(pixel, vec2<f32>(at.x, origin.y), _licm0, 4.0, _licm1) * weights.x), (tickMark(pixel, vec2<f32>(origin.x, at.y), _licm2, 4.0, _licm1) * weights.y))); backgroundGrid = max(backgroundGrid, max((distanceCoverage(grid.x, _licm3) * weights.x), (distanceCoverage(grid.y, _licm3) * weights.y))); let width = numberWidth(nearest.x, _i14ret.x, _licm4); let xFit = smoothstep((width + 6.0), (width + 14.0), ((tickStep.x / span.x) * size.x)); let yFit = smoothstep(_licm5, _licm6, ((tickStep.y / span.y) * size.y)); if (((_cse1 && (at.x > ((width * 0.5) + 6.0))) && (at.x < ((size.x - (width * 0.5)) - 6.0)))) { labels = max(labels, ((numberAt(pixel, vec2<f32>(at.x, select((origin.y - _licm7), (origin.y + _cse2), (origin.y < _cse2))), nearest.x, _i14ret.x, 0.5, _licm4, _licm8, _licm9) * weights.x) * xFit)); } if ((((_cse1 && (at.y > 25.0)) && (at.y < (size.y - 25.0))) && (abs(nearest.y) > (_i15ret.x * 0.001)))) { let _lc2 = (origin.x < _cse3); labels = max(labels, ((numberAt(pixel, vec2<f32>(select((origin.x - 8.0), (origin.x + 8.0), _lc2), (at.y + _licm10)), nearest.y, _i15ret.x, select(1.0, 0.0, _lc2), _licm4, _licm8, _licm9) * weights.y) * yFit)); } } labels *= function_plot_u_4.decorationOpacity.y; let _cse4 = ((function_plot_u_4.decorations & 4u) != 0u); if (_cse4) { labels = max(labels, (axisLabel(pixel, vec2<f32>(_gv0, clamp((origin.y + 30.0), 40.0, (size.y - 40.0))), 120, function_plot_u_4) * function_plot_u_4.decorationOpacity.z)); } if (_cse4) { labels = max(labels, (axisLabel(pixel, _flow143_shared(origin.x, size.x, size.y), vertical, function_plot_u_4) * function_plot_u_4.decorationOpacity.z)); } return vec4<f32>(max(axes, select(0.0, ((backgroundGrid * 0.2) * function_plot_u_4.decorationOpacity.x), ((function_plot_u_4.decorations & 1u) != 0u))), labels); } fn basisVector_function(p: vec3<f32>, function_plot_u_8: ptr<function, PlotUniforms>) -> vec3<f32> { let span = max((*function_plot_u_8).plotSpan, vec2<f32>(0.00001)); let q = (p / vec3<f32>(span, max(span.x, span.y))); let basis = (*function_plot_u_8).rotationBasis; let horizontal = ((q.x * basis.y) + (q.z * basis.x)); let depth = (((-q.x) * basis.x) + (q.z * basis.y)); return vec3<f32>(horizontal, ((q.y * basis.w) - (depth * basis.z)), ((q.y * basis.z) + (depth * basis.w))); } fn basisVector_value(p: vec3<f32>, function_plot_u_8: PlotUniforms) -> vec3<f32> { let span = max(function_plot_u_8.plotSpan, vec2<f32>(0.00001)); let q = (p / vec3<f32>(span, max(span.x, span.y))); let basis = function_plot_u_8.rotationBasis; let horizontal = ((q.x * basis.y) + (q.z * basis.x)); let depth = (((-q.x) * basis.x) + (q.z * basis.y)); return vec3<f32>(horizontal, ((q.y * basis.w) - (depth * basis.z)), ((q.y * basis.z) + (depth * basis.w))); } fn cameraPoint_function(p: vec3<f32>, function_plot_u_9: ptr<function, PlotUniforms>) -> vec3<f32> { return basisVector_function((((*function_plot_u_9).model * vec4<f32>(p, 1.0)).xyz - vec3<f32>((*function_plot_u_9).plotCenter, (*function_plot_u_9).plotCenterZ)), function_plot_u_9); } fn cameraPoint_value(p: vec3<f32>, function_plot_u_9: PlotUniforms) -> vec3<f32> { return basisVector_value(((function_plot_u_9.model * vec4<f32>(p, 1.0)).xyz - vec3<f32>(function_plot_u_9.plotCenter, function_plot_u_9.plotCenterZ)), function_plot_u_9); } fn cameraVector_function(p: vec3<f32>, function_plot_u_10: ptr<function, PlotUniforms>) -> vec3<f32> { return basisVector_function(((*function_plot_u_10).model * vec4<f32>(p, 0.0)).xyz, function_plot_u_10); } fn cameraVector_value(p: vec3<f32>, function_plot_u_10: PlotUniforms) -> vec3<f32> { return basisVector_value((function_plot_u_10.model * vec4<f32>(p, 0.0)).xyz, function_plot_u_10); } fn inverseCamera(p: vec3<f32>, function_plot_u_12: PlotUniforms) -> vec3<f32> { let basis = function_plot_u_12.rotationBasis; let y = ((p.y * basis.w) + (p.z * basis.z)); let depth = (((-p.y) * basis.z) + (p.z * basis.w)); let q = vec3<f32>(((p.x * basis.y) - (depth * basis.x)), y, ((p.x * basis.x) + (depth * basis.y))); return (function_plot_u_12.inverseModel * vec4<f32>((q * vec3<f32>(function_plot_u_12.plotSpan, max(function_plot_u_12.plotSpan.x, function_plot_u_12.plotSpan.y))), 0.0)).xyz; } fn project_function(p: vec3<f32>, function_plot_u_14: ptr<function, PlotUniforms>) -> vec2<f32> { let h = _spec2_homogeneous_function(p, function_plot_u_14); return (h.xy / max(h.z, 0.101)); } fn project_value(p: vec3<f32>, function_plot_u_14: PlotUniforms) -> vec2<f32> { let h = _spec2_homogeneous_value(p, function_plot_u_14); return (h.xy / max(h.z, 0.101)); } fn inFront_function(p: vec3<f32>, function_plot_u_16: ptr<function, PlotUniforms>) -> bool { return (((*function_plot_u_16).view3d != 2u) || (((*function_plot_u_16).cameraLens.y - cameraPoint_function(p, function_plot_u_16).z) >= 0.101)); } fn inFront_value(p: vec3<f32>, function_plot_u_16: PlotUniforms) -> bool { return ((function_plot_u_16.view3d != 2u) || ((function_plot_u_16.cameraLens.y - cameraPoint_value(p, function_plot_u_16).z) >= 0.101)); } fn axisField(pixel: vec2<f32>, axis: vec3<f32>, ray: ptr<function, ViewRay>, function_plot_u_18: PlotUniforms) -> f32 { let _cse0 = vec3<f32>(0.0); let origin = _spec2_homogeneous_value(_cse0, function_plot_u_18); let direction = _spec3_homogeneous_value(axis, function_plot_u_18); let coefficients = cross(origin, direction); let magnitude = length(coefficients.xy); var distance: f32 = length((pixel - project_value(_cse0, function_plot_u_18))); distance = select(distance, (abs(dot(coefficients, vec3<f32>(pixel, 1.0))) / magnitude), (magnitude > 1e-12)); let transverse = (vec3<f32>(1.0) - axis); let a = ((*ray).origin * transverse); let b = ((*ray).direction * transverse); let depth = ((-dot(a, b)) / max(dot(b, b), 1e-20)); var _sel1: f32; if (((function_plot_u_18.view3d != 2u) || (depth >= 0.101))) { _sel1 = distanceCoverage(distance, function_plot_u_18.appearance.x); } else { _sel1 = 0.0; } return _sel1; } fn groundField(ray: ptr<function, ViewRay>, function_plot_u_19: PlotUniforms, xLevels: vec3<f32>, zLevels: vec3<f32>) -> f32 { let _licm0 = vec2<f32>(xLevels.x, zLevels.x); let _licm1 = vec2<f32>(xLevels.y, zLevels.y); let _licm2 = clamp(function_plot_u_19.labelStyle.x, 0.5, 2.0); let _licm3 = function_plot_u_19.appearance.y; let _cse0 = abs((*ray).direction.y); let denominator = select((*ray).direction.y, select(1e-8, -1e-8, ((*ray).direction.y < 0.0)), (_cse0 < 1e-8)); let depth = ((-(*ray).origin.y) / denominator); let ground = ((*ray).origin + ((*ray).direction * depth)).xz; let gradient = max(vec2<f32>(length(vec2<f32>(dpdx(ground.x), dpdy(ground.x))), length(vec2<f32>(dpdx(ground.y), dpdy(ground.y)))), vec2<f32>(1e-20)); var field: f32 = 0.0; let _cse1 = (1.0 / max(font.pixelRatio, 0.0001)); let _licm4 = vec2<f32>((12.0 / _licm2)); let _licm5 = vec2<f32>((28.0 / _licm2)); for (var level: i32 = 0; (level < 2); level = (level + 1)) { let _gv0 = (level == 0); let spacing = select(_licm1, _licm0, _gv0); let _gv1 = ((ground / spacing) + 0.5); let distance = (((abs((fract(_gv1) - 0.5)) * spacing) / gradient) * _cse1); let separation = ((spacing / gradient) * _cse1); let fade = smoothstep(_licm4, _licm5, separation); let nearest = (floor(_gv1) * spacing); var _sel2: vec2<f32>; if (_gv0) { _sel2 = vec2<f32>(tickOpacity(nearest.x, xLevels), tickOpacity(nearest.y, zLevels)); } else { _sel2 = vec2<f32>(coarseTickOpacity(nearest.x, xLevels), coarseTickOpacity(nearest.y, zLevels)); } let weights = _sel2; field = max(field, max(((distanceCoverage(distance.x, _licm3) * fade.x) * weights.x), ((distanceCoverage(distance.y, _licm3) * fade.y) * weights.y))); } return select(0.0, (field * function_plot_u_19.decorationOpacity.x), ((((function_plot_u_19.view3d != 2u) || (depth >= 0.101)) && (_cse0 >= 1e-8)) && ((function_plot_u_19.decorations & 1u) != 0u))); } fn axisParameter(pixel: vec2<f32>, axis: vec3<f32>, function_plot_u_20: PlotUniforms) -> f32 { let origin = _spec2_homogeneous_value(vec3<f32>(0.0), function_plot_u_20); let direction = _spec3_homogeneous_value(axis, function_plot_u_20); let line = cross(origin, direction); let foot = (pixel - ((line.xy * dot(line, vec3<f32>(pixel, 1.0))) / max(dot(line.xy, line.xy), 1e-20))); let slope = (direction.xy - (foot * direction.z)); return (dot(((foot * origin.z) - origin.xy), slope) / max(dot(slope, slope), 1e-20)); } fn PlotUniforms_as_PlotViewport(value: ptr<function, PlotUniforms>) -> PlotViewport { return PlotViewport((*value).resolution, (*value).plotCenter, (*value).plotSpan, (*value).plotRotation, (*value).rotationBasis, (*value).plotPan, (*value).plotBlend, (*value).appearance, (*value).decorations, (*value).labelStyle, (*value).decorationOpacity); } fn PlotUniforms_as_PlotViewport_into(_dst: ptr<function, PlotViewport>, value: PlotUniforms) { (*_dst) = PlotViewport(value.resolution, value.plotCenter, value.plotSpan, value.plotRotation, value.rotationBasis, value.plotPan, value.plotBlend, value.appearance, value.decorations, value.labelStyle, value.decorationOpacity); } fn spatialLevels(axis: vec3<f32>, function_plot_u_21: PlotUniforms) -> vec3<f32> { let center = axisParameter((max(function_plot_u_21.resolution, vec2<f32>(1.0)) * 0.5), axis, function_plot_u_21); let span = max(function_plot_u_21.plotSpan.x, function_plot_u_21.plotSpan.y); let h = (span * 0.001); let tangent = ((project_value((axis * (center + h)), function_plot_u_21) - project_value((axis * (center - h)), function_plot_u_21)) / (2.0 * h)); let pixels = max((length(tangent) * span), 1.0); let horizontal = (abs(tangent.x) >= (abs(tangent.y) * 0.7)); var _i2a4: PlotViewport; PlotUniforms_as_PlotViewport_into(&_i2a4, function_plot_u_21); let _i2_size = _i2a4.appearance.w; let _i2_rough = (((span * _i2_size) * 4.0) / max(pixels, 1.0)); let _lc0 = (span * 0.5); let _i2_width = max(numberWidth((center - _lc0), _i2_rough, _i2_size), numberWidth((center + _lc0), _i2_rough, _i2_size)); let _i2_gap = select((_i2_size * 2.6), max((_i2_size * 3.5), (_i2_width + (_i2_size * 1.3))), horizontal); let _i2ret = tickLevels(((span * _i2_gap) / max((pixels * _i2a4.labelStyle.x), 1.0))); return _i2ret; } fn spatialTicks(pixel: vec2<f32>, axis: vec3<f32>, levels: vec3<f32>, priority: f32, function_plot_u_22: PlotUniforms) -> vec4<f32> { let _licm0 = levels.x; let _licm1 = levels.y; let _licm2 = (function_plot_u_22.appearance.x > 0.0); let _licm3 = vec2<f32>((((function_plot_u_22.appearance.x * 0.5) + 4.0) + (1.0 / max(font.pixelRatio, 0.0001)))); let _licm4 = function_plot_u_22.appearance.x; let _licm5 = (levels.x * 0.001); let _licm6 = select(0.0, 1.0, (axis.x > 0.0)); let _licm7 = function_plot_u_22.labelStyle.y; let _licm8 = function_plot_u_22.labelStyle.z; let _licm9 = function_plot_u_22.decorationOpacity.y; let size = max(function_plot_u_22.resolution, vec2<f32>(1.0)); let fontSize = function_plot_u_22.appearance.w; let _cse0 = vec3<f32>(0.0); let originH = _spec2_homogeneous_value(_cse0, function_plot_u_22); let directionH = _spec3_homogeneous_value(axis, function_plot_u_22); let axisLine = cross(originH, directionH); let magnitude = length(axisLine.xy); if (((magnitude <= 1e-12) || ((abs(dot(axisLine, vec3<f32>(pixel, 1.0))) / magnitude) > ((fontSize * 6.0) + 12.0)))) { return vec4<f32>(0.0); } let normal = (axisLine.xy / magnitude); let tangent = vec2<f32>(normal.y, (-normal.x)); let sign = select(select(1.0, -1.0, (normal.y > 0.0)), select(1.0, -1.0, (normal.x > 0.0)), (axis.y > 0.0)); let outward = (normal * sign); let value = axisParameter(pixel, axis, function_plot_u_22); var labels: vec3<f32> = _cse0; var ticks: f32 = 0.0; let _cse1 = ((function_plot_u_22.decorations & 2u) != 0u); for (var index: i32 = 0; (index < 6); index = (index + 1)) { let _gv0 = (index < 3); let stride = select(_licm1, _licm0, _gv0); let nearest = (floor(((value / stride) + 0.5)) * stride); let t = (nearest + (f32(((index % 3) - 1)) * stride)); let world = (axis * t); if (inFront_value(world, function_plot_u_22)) { let at = project_value(world, function_plot_u_22); let anchor = ((at + (outward * ((fontSize * 0.95) + 6.0))) + vec2<f32>(0.0, (fontSize * 0.65))); let delta = (pixel - anchor); let nearLabel = (((_cse1 && (abs(delta.x) <= (fontSize * 9.0))) && (delta.y >= (((-fontSize) * 1.5) - 3.0))) && (delta.y <= 3.0)); let nearTick = (_licm2 && all((abs((pixel - at)) <= _licm3))); if (((nearLabel == false) && (nearTick == false))) { continue; } let before = project_value((axis * (t - stride)), function_plot_u_22); let after = project_value((axis * (t + stride)), function_plot_u_22); let width = numberWidth(t, _licm0, fontSize); let _lc0 = (width * 0.5); let room = min(min(((anchor.x - _lc0) - 3.0), (((size.x - anchor.x) - _lc0) - 3.0)), min((anchor.y - (fontSize * 1.5)), (size.y - anchor.y))); let separation = min(abs((at - before)), abs((after - at))); let _gv1 = (width + fontSize); let _gv2 = ((fontSize * 1.8) + 6.0); let fit = smoothstep(0.85, 1.15, max((separation.x / _gv1), (separation.y / _gv2))); var _sel3: f32; if (_gv0) { _sel3 = tickOpacity(t, levels); } else { _sel3 = coarseTickOpacity(t, levels); } let visibility = (_sel3 * fit); ticks = max(ticks, (tickMark(pixel, at, tangent, 3.0, _licm4) * visibility)); let zero = (abs(t) <= _licm5); let originDistance = length((at - project_value(_cse0, function_plot_u_22))); let crossing = select(smoothstep((fontSize * 2.0), (fontSize * 4.0), originDistance), _licm6, zero); if (_cse1) { labels = max(labels, (((((numberAt(pixel, anchor, t, _licm0, 0.5, fontSize, _licm7, _licm8) * _licm9) * visibility) * smoothstep(0.0, 6.0, room)) * crossing) * priority)); } } } return vec4<f32>(ticks, labels); } fn spatialBackground_into(_dst: ptr<function, SpatialDecor>, uv: vec2<f32>, function_plot_u_23: PlotUniforms) { let _licm0 = vec2<f32>(10.0, 18.0); let _licm1 = function_plot_u_23.decorationOpacity.z; let _cse0 = max(function_plot_u_23.resolution, vec2<f32>(1.0)); let pixel = (uv * _cse0); let _cse1 = vec3<f32>(1.0, 0.0, 0.0); let xLevels = spatialLevels(_cse1, function_plot_u_23); let _cse2 = vec3<f32>(0.0, 1.0, 0.0); let yLevels = spatialLevels(_cse2, function_plot_u_23); let _cse3 = vec3<f32>(0.0, 0.0, 1.0); let zLevels = spatialLevels(_cse3, function_plot_u_23); let _i4_screen = ((uv - vec2<f32>(0.5)) - function_plot_u_23.plotPan); let _i4_cameraXY = (vec2<f32>((_i4_screen.x * (_cse0.x / _cse0.y)), _i4_screen.y) * function_plot_u_23.cameraLens.x); let _cse4 = (function_plot_u_23.view3d == 2u); let _i4_origin = select(vec3<f32>((_i4_cameraXY * function_plot_u_23.cameraLens.y), function_plot_u_23.cameraLens.y), vec3<f32>(0.0, 0.0, function_plot_u_23.cameraLens.y), _cse4); let _i4_direction = select(vec3<f32>(0.0, 0.0, -1.0), vec3<f32>(_i4_cameraXY, -1.0), _cse4); var _i4ret: ViewRay = ViewRay((inverseCamera(_i4_origin, function_plot_u_23) + (function_plot_u_23.inverseModel * vec4<f32>(function_plot_u_23.plotCenter, function_plot_u_23.plotCenterZ, 1.0)).xyz), inverseCamera(_i4_direction, function_plot_u_23)); let grid = groundField(&_i4ret, function_plot_u_23, xLevels, zLevels); let xTicks = spatialTicks(pixel, _cse1, xLevels, 1.0, function_plot_u_23); let yTicks = spatialTicks(pixel, _cse2, yLevels, 1.0, function_plot_u_23); let origin = project_value(vec3<f32>(0.0), function_plot_u_23); let xDirection = _spec3_homogeneous_value(_cse1, function_plot_u_23); let zDirection = _spec3_homogeneous_value(_cse3, function_plot_u_23); let _cse5 = vec2<f32>(1e-12); let xTangent = normalize(((xDirection.xy - (origin * xDirection.z)) + _cse5)); let zTangent = normalize(((zDirection.xy - (origin * zDirection.z)) + _cse5)); let angle = abs(((xTangent.x * zTangent.y) - (xTangent.y * zTangent.x))); let zTicks = spatialTicks(pixel, _cse3, zLevels, smoothstep(0.08, 0.25, angle), function_plot_u_23); var labels: vec3<f32> = max(max(xTicks.yzw, yTicks.yzw), zTicks.yzw); let _cse6 = vec3<f32>(0.965, 0.973, 0.985); var color: vec3<f32> = mix(_cse6, vec3<f32>(0.8, 0.82, 0.85), (grid * 0.65)); color = mix(color, vec3<f32>(0.67, 0.28, 0.25), axisField(pixel, _cse1, &_i4ret, function_plot_u_23)); color = mix(color, vec3<f32>(0.23, 0.47, 0.3), axisField(pixel, _cse2, &_i4ret, function_plot_u_23)); color = mix(color, vec3<f32>(0.4, 0.35, 0.62), axisField(pixel, _cse3, &_i4ret, function_plot_u_23)); color = mix(color, vec3<f32>(0.25, 0.29, 0.35), max(max(xTicks.x, yTicks.x), zTicks.x)); if (((function_plot_u_23.decorations & 4u) != 0u)) { let _cse7 = vec2<f32>(18.0); for (var index: i32 = 0; (index < 3); index = (index + 1)) { let axis = select(select(_cse3, _cse2, (index == 1)), _cse1, (index == 0)); let edge = select(vec2<f32>((_cse0.x - 30.0), (_cse0.y * 0.5)), vec2<f32>((_cse0.x * 0.5), (_cse0.y - 30.0)), (index == 1)); let world = (axis * axisParameter(edge, axis, function_plot_u_23)); if (inFront_value(world, function_plot_u_23)) { let at = clamp((project_value(world, function_plot_u_23) + _licm0), _cse7, (_cse0 - _cse7)); labels = max(labels, (_flow10_fused(pixel, at, (120 + index), function_plot_u_23) * _licm1)); } } } (*_dst) = SpatialDecor(mix(_cse6, color, function_plot_u_23.sceneOpacity.x), (labels * function_plot_u_23.sceneOpacity.x)); } fn intervalChordDistance(pixel: vec2<f32>, a: vec2<f32>, b: vec2<f32>) -> f32 { let delta = (b - a); let along = _flow147_shared(pixel, a, delta); return length(((pixel - a) - (along * delta))); } fn parameterAt(q: f32, scale: f32, center: f32, function_plot_u_27: ptr<function, PlotUniforms>) -> f32 { let safe = clamp(q, -0.99999, 0.99999); if (((*function_plot_u_27).parameterMode == 3u)) { return (center + ((scale * safe) / (1.0 - abs(safe)))); } let positive = ((safe + 1.0) * 0.5); if (((*function_plot_u_27).parameterMode == 2u)) { return ((*function_plot_u_27).parameterBounds.x + ((scale * positive) / max((1.0 - positive), 0.00001))); } return ((*function_plot_u_27).parameterBounds.y - ((scale * (1.0 - positive)) / max(positive, 0.00001))); } @vertex fn fullscreen(@builtin(vertex_index) i: u32) -> VsOut { let x = select(-1.0, 3.0, (i == 1u)); let y = select(-1.0, 3.0, (i == 2u)); return VsOut(vec4<f32>(x, y, 0.0, 1.0), vec2<f32>(((x * 0.5) + 0.5), ((y * 0.5) + 0.5))); } fn sample(x: f32) -> f32 { if ((abs(x) > 1.0)) { return 100000000000000000000.0; } return acos(x); } fn Uniforms_as_PlotUniforms(value: Uniforms) -> PlotUniforms { return PlotUniforms(value.resolution, value.plotCenter, value.plotSpan, value.plotRotation, value.rotationBasis, value.plotPan, value.plotBlend, value.appearance, value.decorations, value.labelStyle, value.decorationOpacity, value.model, value.inverseModel, value.axesModel, value.inverseAxesModel, value.sceneOpacity, value.cameraLens, value.plotCenterZ, value.probe, value.parameterFocusSeed, value.view3d, value.parameterBounds, value.parameterMode, value.curveQuality, value.curvePattern, value.curveTiles, value.surfaceBounds, value.surfaceDomainMode, value.surfaceRange, value.surfaceHeight, value.surfaceDepth, value.surfaceRender, value.surfaceFlags); } fn parameterFocus_trajectory(function_plot_u_28: ptr<function, PlotUniforms>) -> vec2<f32> { let _licm0 = (*function_plot_u_28).parameterFocusSeed; let pixel = (max((*function_plot_u_28).resolution, vec2<f32>(1.0)) * 0.5); var center: f32 = _licm0; let initial = vec3<f32>(center, sample(center), 0.0); var _sel4: f32; let _cse0 = vec3<f32>(1000000000000000000.0); if ((all((abs(initial) < _cse0)) && inFront_function(initial, function_plot_u_28))) { let _lc0 = (project_function(initial, function_plot_u_28) - pixel); _sel4 = dot(_lc0, _lc0); } else { _sel4 = 1e+30; } var error: f32 = _sel4; for (var level: i32 = 0; (level < 8); level = (level + 1)) { let radius = pow(4.0, f32(level)); let _i6a0 = (_licm0 - radius); let a = vec3<f32>(_i6a0, sample(_i6a0), 0.0); let _i7a0 = (_licm0 + radius); let b = vec3<f32>(_i7a0, sample(_i7a0), 0.0); if ((all((abs(a) < _cse0)) && all((abs(b) < _cse0)))) { let middle = ((a + b) * 0.5); let direction = ((b - a) / (2.0 * radius)); let originH = _spec2_homogeneous_function(middle, function_plot_u_28); let directionH = _spec3_homogeneous_function(direction, function_plot_u_28); let slope = (directionH.xy - (pixel * directionH.z)); let norm = dot(slope, slope); if ((norm > 1e-20)) { let candidate = (_licm0 + (dot(((pixel * originH.z) - originH.xy), slope) / norm)); let point = vec3<f32>(candidate, sample(candidate), 0.0); if ((((abs(candidate) < 1000000000000000000.0) && all((abs(point) < _cse0))) && inFront_function(point, function_plot_u_28))) { let delta = (project_function(point, function_plot_u_28) - pixel); let nextError = dot(delta, delta); let _ifc0 = (nextError < error); center = select(center, candidate, _ifc0); error = select(error, nextError, _ifc0); } } } } var speed: f32 = 1.0; for (var i: i32 = 0; (i < 4); i = (i + 1)) { let h = max((abs(center) * 0.00001), 0.001); let at = vec3<f32>(center, sample(center), 0.0); let _i8a0 = (center - h); let left = vec3<f32>(_i8a0, sample(_i8a0), 0.0); let _i9a0 = (center + h); let right = vec3<f32>(_i9a0, sample(_i9a0), 0.0); let _gv0 = (2.0 * h); let normalized = cameraVector_function(((right - left) / _gv0), function_plot_u_28); speed = max(length(normalized), 1e-10); let tangent = ((project_function(right, function_plot_u_28) - project_function(left, function_plot_u_28)) / _gv0); let correction = clamp((dot((pixel - project_function(at, function_plot_u_28)), tangent) / max(dot(tangent, tangent), 1e-20)), (-32.0 / speed), (32.0 / speed)); var candidate_1: f32 = (center + correction); for (var backtrack: i32 = 0; (backtrack < 4); backtrack = (backtrack + 1)) { let point_1 = vec3<f32>(candidate_1, sample(candidate_1), 0.0); let delta_1 = (project_function(point_1, function_plot_u_28) - pixel); let nextError_1 = dot(delta_1, delta_1); if (((all((abs(point_1) < _cse0)) && inFront_function(point_1, function_plot_u_28)) && (nextError_1 <= error))) { center = candidate_1; error = nextError_1; break; } candidate_1 = ((candidate_1 + center) * 0.5); } } var scale: f32 = clamp((2.0 / speed), 0.00001, 10000000000.0); scale = select(scale, max(scale, abs((center - (*function_plot_u_28).parameterBounds.y))), ((*function_plot_u_28).parameterMode == 1u)); scale = select(scale, max(scale, abs((center - (*function_plot_u_28).parameterBounds.x))), ((*function_plot_u_28).parameterMode == 2u)); return vec2<f32>(center, scale); } fn refineTrajectoryHit_trajectory(pixel: vec2<f32>, candidate: vec4<f32>, function_plot_u_24: ptr<function, PlotUniforms>, jumps: bool) -> vec2<f32> { let _licm0 = ((*function_plot_u_24).appearance.z * 0.5); var t: f32 = candidate.y; let low = candidate.z; let high = candidate.w; let epsilon = max(max(((high - low) * 0.001), (abs(t) * 0.000001)), 1e-7); let _cse0 = (jumps == false); let _cse1 = vec3<f32>(1000000000000000000.0); let _cse2 = (1.0 / max(font.pixelRatio, 0.0001)); for (var iteration: i32 = 0; (iteration < 12); iteration = (iteration + 1)) { let before = max(low, (t - epsilon)); let after = min(high, (t + epsilon)); let a = project_function(vec3<f32>(before, sample(before), 0.0), function_plot_u_24); let b = project_function(vec3<f32>(after, sample(after), 0.0), function_plot_u_24); let tangent = ((b - a) / max((after - before), 1e-20)); let atWorld = vec3<f32>(t, sample(t), 0.0); let at = project_function(atWorld, function_plot_u_24); let _gv0 = (at - pixel); let delta = (dot(_gv0, tangent) / max(dot(tangent, tangent), 1e-20)); var next: f32 = clamp((t - delta), low, high); var world: vec3<f32> = vec3<f32>(next, sample(next), 0.0); var projected: vec2<f32> = project_function(world, function_plot_u_24); let error = dot(_gv0, _gv0); if ((((_cse0 && all((abs(atWorld) < _cse1))) && inFront_function(atWorld, function_plot_u_24)) && (error <= pow(max(0.0, (_licm0 - (_cse2 * 0.5))), 2.0)))) { return vec2<f32>(sqrt(error), t); } var _sc1: bool = (all((abs(world) < _cse1)) && inFront_function(world, function_plot_u_24)); if (_sc1) { let _lc2 = (projected - pixel); _sc1 = (dot(_lc2, _lc2) <= error); } if ((_sc1 == false)) { next = ((t + next) * 0.5); world = vec3<f32>(next, sample(next), 0.0); projected = project_function(world, function_plot_u_24); } var _sc3: bool = (all((abs(world) < _cse1)) && inFront_function(world, function_plot_u_24)); if (_sc3) { let _lc4 = (projected - pixel); _sc3 = (dot(_lc4, _lc4) <= error); } if (_sc3) { if ((next == t)) { break; } let movement = length((projected - at)); t = next; if ((movement < (_cse2 * 0.01))) { break; } } else { break; } } let world_1 = vec3<f32>(t, sample(t), 0.0); let _i10a0 = ((low + high) * 0.5); let middle = vec3<f32>(_i10a0, sample(_i10a0), 0.0); var _sc5: bool = _cse0; if ((_sc5 == false)) { let _lc6 = vec3<f32>(low, sample(low), 0.0); let _lc7 = vec3<f32>(high, sample(high), 0.0); _sc5 = (length((middle - ((_lc6 + _lc7) * 0.5))) <= max(0.000001, (length((_lc7 - _lc6)) * 0.2))); } let continuous = _sc5; var _sel5: f32; if (((all((abs(world_1) < _cse1)) && continuous) && inFront_function(world_1, function_plot_u_24))) { _sel5 = length((pixel - project_function(world_1, function_plot_u_24))); } else { _sel5 = 100000000000000000000.0; } return vec2<f32>(_sel5, t); } fn intervalHit_trajectory(pixel: vec2<f32>, low: f32, high: f32, function_plot_u_25: ptr<function, PlotUniforms>, jumps: bool) -> vec2<f32> { var start: f32 = low; var end: f32 = high; var a: vec3<f32> = vec3<f32>(start, sample(start), 0.0); var b: vec3<f32> = vec3<f32>(end, sample(end), 0.0); let frontA = inFront_function(a, function_plot_u_25); let frontB = inFront_function(b, function_plot_u_25); let _cse0 = vec3<f32>(1000000000000000000.0); if ((((all((abs(a) < _cse0)) && all((abs(b) < _cse0))) == false) || ((frontA == false) && (frontB == false)))) { return vec2<f32>(100000000000000000000.0, low); } if ((frontA != frontB)) { var left: f32 = start; var right: f32 = end; for (var i: i32 = 0; (i < 12); i = (i + 1)) { let middle = ((left + right) * 0.5); let _ifc0 = (inFront_function(vec3<f32>(middle, sample(middle), 0.0), function_plot_u_25) == frontA); left = select(left, middle, _ifc0); right = select(middle, right, _ifc0); } end = select(end, left, frontA); start = select(right, start, frontA); a = vec3<f32>(start, sample(start), 0.0); b = vec3<f32>(end, sample(end), 0.0); } let ha = _spec2_homogeneous_function(a, function_plot_u_25); let hb = _spec2_homogeneous_function(b, function_plot_u_25); let pa = (ha.xy / ha.z); let pb = (hb.xy / hb.z); let delta = (pb - pa); let screenFraction = _flow147_shared(pixel, pa, delta); let fraction = ((screenFraction * ha.z) / max(mix(hb.z, ha.z, screenFraction), 1e-20)); let seed = mix(start, end, fraction); let candidate = vec4<f32>(0.0, seed, start, end); var refined: vec2<f32> = refineTrajectoryHit_trajectory(pixel, candidate, function_plot_u_25, jumps); let _i11a0 = ((start + end) * 0.5); let middle_1 = vec3<f32>(_i11a0, sample(_i11a0), 0.0); let continuous = ((jumps == false) || (length((middle_1 - ((a + b) * 0.5))) <= max(0.000001, (length((b - a)) * 0.2)))); let first = length((pixel - pa)); let last = length((pixel - pb)); refined = select(refined, vec2<f32>(first, start), (first < refined.x)); refined = select(refined, vec2<f32>(last, end), (last < refined.x)); return select(vec2<f32>(100000000000000000000.0, start), refined, continuous); } @fragment fn main(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> { let flat = _flow79_fused(uv, &u); if ((u.plotBlend <= 0.0)) { return flat; } return mix(flat, _flow37_fused(uv, &u), clamp(u.plotBlend, 0.0, 1.0)); } fn _spec2_homogeneous_function(p: vec3<f32>, function_plot_u_13: ptr<function, PlotUniforms>) -> vec3<f32> { let size = max((*function_plot_u_13).resolution, vec2<f32>(1.0)); let _sel6 = cameraPoint_function(p, function_plot_u_13); let w = select((*function_plot_u_13).cameraLens.y, ((*function_plot_u_13).cameraLens.y - _sel6.z), ((*function_plot_u_13).view3d == 2u)); let focal = (1.0 / (*function_plot_u_13).cameraLens.x); return vec3<f32>((((vec2<f32>((_sel6.x / (size.x / size.y)), _sel6.y) * focal) + ((vec2<f32>(0.5) + (*function_plot_u_13).plotPan) * w)) * size), w); } fn _spec2_homogeneous_value(p: vec3<f32>, function_plot_u_13: PlotUniforms) -> vec3<f32> { let size = max(function_plot_u_13.resolution, vec2<f32>(1.0)); let _sel6 = cameraPoint_value(p, function_plot_u_13); let w = select(function_plot_u_13.cameraLens.y, (function_plot_u_13.cameraLens.y - _sel6.z), (function_plot_u_13.view3d == 2u)); let focal = (1.0 / function_plot_u_13.cameraLens.x); return vec3<f32>((((vec2<f32>((_sel6.x / (size.x / size.y)), _sel6.y) * focal) + ((vec2<f32>(0.5) + function_plot_u_13.plotPan) * w)) * size), w); } fn _spec3_homogeneous_function(p: vec3<f32>, function_plot_u_13: ptr<function, PlotUniforms>) -> vec3<f32> { let size = max((*function_plot_u_13).resolution, vec2<f32>(1.0)); let _sel7 = cameraVector_function(p, function_plot_u_13); let w = select(0.0, (-_sel7.z), ((*function_plot_u_13).view3d == 2u)); let focal = (1.0 / (*function_plot_u_13).cameraLens.x); return vec3<f32>((((vec2<f32>((_sel7.x / (size.x / size.y)), _sel7.y) * focal) + ((vec2<f32>(0.5) + (*function_plot_u_13).plotPan) * w)) * size), w); } fn _spec3_homogeneous_value(p: vec3<f32>, function_plot_u_13: PlotUniforms) -> vec3<f32> { let size = max(function_plot_u_13.resolution, vec2<f32>(1.0)); let _sel7 = cameraVector_value(p, function_plot_u_13); let w = select(0.0, (-_sel7.z), (function_plot_u_13.view3d == 2u)); let focal = (1.0 / function_plot_u_13.cameraLens.x); return vec3<f32>((((vec2<f32>((_sel7.x / (size.x / size.y)), _sel7.y) * focal) + ((vec2<f32>(0.5) + function_plot_u_13.plotPan) * w)) * size), w); } fn _spec7_trajectoryDistance_trajectory(pixel: vec2<f32>, function_plot_u_29: ptr<function, PlotUniforms>, bounds: vec2<f32>) -> f32 { let _licm0 = bounds.x; let _licm1 = bounds.y; let _licm2 = ((*function_plot_u_29).curvePattern.x != 0.0); let _licm3 = (*function_plot_u_29).curvePattern.y; let _licm4 = (*function_plot_u_29).curvePattern.z; let _licm5 = (*function_plot_u_29).curvePattern.w; let _licm6 = ((*function_plot_u_29).appearance.z * 0.5); let _licm7 = ((1.0 / max(font.pixelRatio, 0.0001)) * 2.0); let requested = f32((*function_plot_u_29).curveQuality.x); let range = (_licm1 - _licm0); let unbounded = ((*function_plot_u_29).parameterMode != 0u); var _sel8: vec2<f32>; if (unbounded) { _sel8 = parameterFocus_trajectory(function_plot_u_29); } else { _sel8 = vec2<f32>(0.0, 1.0); } let focus = _sel8; let count = i32(min(512.0, select(max(requested, ceil(((range / _licm3) * 4.0))), requested, (unbounded || ((*function_plot_u_29).curvePattern.x == 0.0))))); let _gv0 = f32(count); let stepSize = (range / _gv0); var distance: f32 = 100000000000000000000.0; let _cse0 = vec3<f32>(1000000000000000000.0); for (var i: i32 = 0; (i < count); i = (i + 1)) { let _gv1 = f32(i); var low: f32 = (_licm0 + (_gv1 * stepSize)); var high: f32 = min(_licm1, (low + stepSize)); if (unbounded) { low = parameterAt((-1.0 + ((2.0 * _gv1) / _gv0)), focus.y, focus.x, function_plot_u_29); high = parameterAt((-1.0 + ((2.0 * f32((i + 1))) / _gv0)), focus.y, focus.x, function_plot_u_29); } var t: f32 = ((low + high) * 0.5); if (_licm2) { let center = (((floor(((t + _licm4) / _licm3)) + 0.5) * _licm3) - _licm4); let _gv2 = ((_licm3 * _licm5) * 0.5); low = max(low, (center - _gv2)); high = min(high, (center + _gv2)); t = ((low + high) * 0.5); } if ((high >= low)) { let a = vec3<f32>(low, sample(low), 0.0); let middle = vec3<f32>(t, sample(t), 0.0); let b = vec3<f32>(high, sample(high), 0.0); let finite = ((all((abs(a) < _cse0)) && all((abs(middle) < _cse0))) && all((abs(b) < _cse0))); if (finite) { var possible: bool = true; if (((inFront_function(a, function_plot_u_29) && inFront_function(middle, function_plot_u_29)) && inFront_function(b, function_plot_u_29))) { let pa = project_function(a, function_plot_u_29); let pm = project_function(middle, function_plot_u_29); let pb = project_function(b, function_plot_u_29); let bending = intervalChordDistance(pm, pa, pb); let guard = (((bending * 4.0) + _licm6) + _licm7); possible = (min(intervalChordDistance(pixel, pa, pm), intervalChordDistance(pixel, pm, pb)) <= guard); } if (possible) { distance = min(distance, intervalHit_trajectory(pixel, low, t, function_plot_u_29, false).x); distance = min(distance, intervalHit_trajectory(pixel, t, high, function_plot_u_29, false).x); } } } } return distance; } fn _flow10_fused(_flow0_input: vec2<f32>, _flow1_input: vec2<f32>, _flow2_input: i32, _flow3_input: PlotUniforms) -> vec3<f32> { let _flow18_part = _flow3_input.appearance; let _flow20_part = _flow3_input.labelStyle; if (_flow139_shared(_flow0_input, _flow1_input, _flow18_part.w, font.pixelRatio)) { return vec3<f32>(0.0); } let _flow5_local = vec2<f32>((_flow0_input.x - _flow1_input.x), ((_flow1_input.y - _flow0_input.y) + (_flow18_part.w * 0.75))); return vec3<f32>(glyphLayers((_flow5_local + vec2<f32>((_flow18_part.w * 0.42), 0.0)), _flow2_input, _flow18_part.w, _flow20_part.y), (numberPlate(_flow5_local, 0.0, 1.0, 0.5, _flow18_part.w) * _flow20_part.z)); } fn _flow37_fused(_flow22_input: vec2<f32>, _flow23_input: ptr<uniform, Uniforms>) -> vec4<f32> { var _flow36_arg: PlotUniforms = PlotUniforms((*_flow23_input).resolution, (*_flow23_input).plotCenter, (*_flow23_input).plotSpan, (*_flow23_input).plotRotation, (*_flow23_input).rotationBasis, (*_flow23_input).plotPan, (*_flow23_input).plotBlend, (*_flow23_input).appearance, (*_flow23_input).decorations, (*_flow23_input).labelStyle, (*_flow23_input).decorationOpacity, (*_flow23_input).model, (*_flow23_input).inverseModel, (*_flow23_input).axesModel, (*_flow23_input).inverseAxesModel, (*_flow23_input).sceneOpacity, (*_flow23_input).cameraLens, (*_flow23_input).plotCenterZ, (*_flow23_input).probe, (*_flow23_input).parameterFocusSeed, (*_flow23_input).view3d, (*_flow23_input).parameterBounds, (*_flow23_input).parameterMode, (*_flow23_input).curveQuality, (*_flow23_input).curvePattern, (*_flow23_input).curveTiles, (*_flow23_input).surfaceBounds, (*_flow23_input).surfaceDomainMode, (*_flow23_input).surfaceRange, (*_flow23_input).surfaceHeight, (*_flow23_input).surfaceDepth, (*_flow23_input).surfaceRender, (*_flow23_input).surfaceFlags); let _cse0 = vec2<f32>(1.0); var _sel9: f32; if (((*_flow23_input).appearance.z > 0.0)) { _sel9 = _spec7_trajectoryDistance_trajectory((_flow22_input * max((*_flow23_input).resolution, _cse0)), &_flow36_arg, (*_flow23_input).parameterBounds); } else { _sel9 = 100000000000000000000.0; } let _flow25_local = _sel9; var _flow40_whole: SpatialDecor; spatialBackground_into(&_flow40_whole, _flow22_input, PlotUniforms((*_flow23_input).resolution, (*_flow23_input).plotCenter, (*_flow23_input).plotSpan, (*_flow23_input).plotRotation, (*_flow23_input).rotationBasis, (*_flow23_input).plotPan, (*_flow23_input).plotBlend, (*_flow23_input).appearance, (*_flow23_input).decorations, (*_flow23_input).labelStyle, (*_flow23_input).decorationOpacity, (*_flow23_input).axesModel, (*_flow23_input).inverseAxesModel, (*_flow23_input).axesModel, (*_flow23_input).inverseAxesModel, (*_flow23_input).sceneOpacity, (*_flow23_input).cameraLens, (*_flow23_input).plotCenterZ, (*_flow23_input).probe, (*_flow23_input).parameterFocusSeed, (*_flow23_input).view3d, (*_flow23_input).parameterBounds, (*_flow23_input).parameterMode, (*_flow23_input).curveQuality, (*_flow23_input).curvePattern, (*_flow23_input).curveTiles, (*_flow23_input).surfaceBounds, (*_flow23_input).surfaceDomainMode, (*_flow23_input).surfaceRange, (*_flow23_input).surfaceHeight, (*_flow23_input).surfaceDepth, (*_flow23_input).surfaceRender, (*_flow23_input).surfaceFlags)); let _flow38_part = _flow40_whole.color; let _flow39_part = _flow40_whole.labels; let _flow27_local = (*_flow23_input).probe; let _flow28_local = vec3<f32>(_flow27_local, sample(_flow27_local), 0.0); let _flow29_local = (((((((*_flow23_input).parameterMode & 1u) != 0u) || ((*_flow23_input).probe >= (*_flow23_input).parameterBounds.x)) && ((((*_flow23_input).parameterMode & 2u) != 0u) || ((*_flow23_input).probe <= (*_flow23_input).parameterBounds.y))) && all((abs(_flow28_local) < vec3<f32>(1000000000000000000.0)))) && inFront_function(_flow28_local, &_flow36_arg)); let _flow30_local = vec3<f32>(project_function(_flow28_local, &_flow36_arg), select(0.0, 1.0, _flow29_local)); let _flow32_local = (_flow22_input * max((*_flow23_input).resolution, _cse0)); var _flow33_local: vec3<f32> = mix(_flow38_part, vec3<f32>(0.09, 0.42, 0.92), distanceCoverage(_flow25_local, (*_flow23_input).appearance.z)); _flow33_local = labelColor(_flow33_local, _flow39_part); var _sel10: vec3<f32>; if ((_flow30_local.z > 0.0)) { _sel10 = pointColor(_flow33_local, _flow32_local, _flow30_local.xy); } else { _sel10 = _flow33_local; } let _flow34_local = vec4<f32>(mix(labelColor(_flow38_part, _flow39_part), _sel10, (*_flow23_input).sceneOpacity.y), 1.0); return _flow34_local; } fn _flow79_fused(_flow41_input: vec2<f32>, _flow42_input: ptr<uniform, Uniforms>) -> vec4<f32> { let _licm0 = ((*_flow42_input).curvePattern.x == 0.0); let _licm1 = (*_flow42_input).curvePattern.y; let _licm2 = (*_flow42_input).curvePattern.z; let _licm3 = ((*_flow42_input).curvePattern.w * 0.5); let _licm4 = (false == false); let _licm5 = (*_flow42_input).appearance.z; var _flow78_arg: PlotUniforms = PlotUniforms((*_flow42_input).resolution, (*_flow42_input).plotCenter, (*_flow42_input).plotSpan, (*_flow42_input).plotRotation, (*_flow42_input).rotationBasis, (*_flow42_input).plotPan, (*_flow42_input).plotBlend, (*_flow42_input).appearance, (*_flow42_input).decorations, (*_flow42_input).labelStyle, (*_flow42_input).decorationOpacity, (*_flow42_input).model, (*_flow42_input).inverseModel, (*_flow42_input).axesModel, (*_flow42_input).inverseAxesModel, (*_flow42_input).sceneOpacity, (*_flow42_input).cameraLens, (*_flow42_input).plotCenterZ, (*_flow42_input).probe, (*_flow42_input).parameterFocusSeed, (*_flow42_input).view3d, (*_flow42_input).parameterBounds, (*_flow42_input).parameterMode, (*_flow42_input).curveQuality, (*_flow42_input).curvePattern, (*_flow42_input).curveTiles, (*_flow42_input).surfaceBounds, (*_flow42_input).surfaceDomainMode, (*_flow42_input).surfaceRange, (*_flow42_input).surfaceHeight, (*_flow42_input).surfaceDepth, (*_flow42_input).surfaceRender, (*_flow42_input).surfaceFlags); let _flow44_local = max((*_flow42_input).resolution, vec2<f32>(1.0)); let _flow45_local = max((*_flow42_input).plotSpan, vec2<f32>(0.00001)); let _flow46_local = ((*_flow42_input).plotCenter + ((_flow41_input - 0.5) * _flow45_local)); let _flow47_local = dpdx(_flow46_local); let _flow48_local = dpdy(_flow46_local); var _flow49_local: f32 = 0.0; let _cse0 = (1.0 / max(font.pixelRatio, 0.0001)); let _licm6 = vec2<f32>(_flow47_local.x, _flow48_local.x); let _licm7 = vec2<f32>(_flow47_local.y, _flow48_local.y); let _licm8 = (length(_licm6) * 0.125); for (var _flow50_local: i32 = 0; (_flow50_local < 4); _flow50_local = (_flow50_local + 1)) { let _flow51_local = vec2<f32>(select(0.25, -0.25, ((_flow50_local & 1) == 0)), select(0.25, -0.25, ((_flow50_local & 2) == 0))); let _flow52_local = ((_flow46_local + (_flow47_local * _flow51_local.x)) + (_flow48_local * _flow51_local.y)); let _flow53_local = sample(_flow52_local.x); let _flow56_local = max(max(_licm8, (abs(_flow52_local.x) * 0.000001)), 1e-7); let _flow57_local = sample((_flow52_local.x - _flow56_local)); let _flow58_local = sample((_flow52_local.x + _flow56_local)); var _flow59_local: f32 = ((_flow58_local - _flow57_local) / (2.0 * _flow56_local)); _flow59_local = select(_flow59_local, ((_flow58_local - _flow53_local) / _flow56_local), ((abs(_flow57_local) < 1000000000000000000.0) == false)); _flow59_local = select(_flow59_local, ((_flow53_local - _flow57_local) / _flow56_local), ((abs(_flow58_local) < 1000000000000000000.0) == false)); let _flow60_local = (_licm7 - (_flow59_local * _licm6)); let _flow61_local = max(dot(_flow60_local, _flow60_local), 1e-30); let _flow62_local = (_flow52_local.y - _flow53_local); let _gv2 = sqrt(_flow61_local); let _flow63_local = ((abs(_flow62_local) / _gv2) * _cse0); let _flow64_local = (_flow52_local.x - ((_flow62_local * dot(_licm6, _flow60_local)) / _flow61_local)); let _flow65_local = (abs(((_flow47_local.x * _flow48_local.y) - (_flow48_local.x * _flow47_local.y))) / _gv2); var _flow66_local: f32; if (_licm0) { _flow66_local = 0.0; } else { let _flow68_local = fract(((_flow64_local + _licm2) / _licm1)); let _flow69_local = (max(0.0, (abs((_flow68_local - 0.5)) - _licm3)) * _licm1); _flow66_local = ((_flow69_local / max(_flow65_local, 1e-20)) * _cse0); } let _flow70_local = _flow66_local; let _flow71_local = (_licm4 || (abs((_flow53_local - ((_flow57_local + _flow58_local) * 0.5))) <= max((length(_licm7) * 2.0), (abs((_flow58_local - _flow57_local)) * 0.2)))); var _sel11: f32; if ((((abs(_flow53_local) < 1000000000000000000.0) && (abs(_flow59_local) < 1000000000000000000.0)) && _flow71_local)) { _sel11 = distanceCoverage(length(vec2<f32>(_flow63_local, _flow70_local)), _licm5); } else { _sel11 = 0.0; } let _flow72_local = _sel11; _flow49_local += (_flow72_local * 0.25); } let _flow73_local = (axes2D(_flow41_input, PlotUniforms_as_PlotViewport(&_flow78_arg), 121) * (*_flow42_input).sceneOpacity.x); let _cse1 = vec3<f32>(0.965, 0.973, 0.985); let _cse2 = vec3<f32>(0.39, 0.43, 0.49); let _gv0 = mix(_cse1, _cse2, _flow73_local.x); var _flow74_local: vec3<f32> = _gv0; _flow74_local = mix(_flow74_local, vec3<f32>(0.09, 0.42, 0.92), _flow49_local); _flow74_local = labelColor(_flow74_local, _flow73_local.yzw); let _gv1 = sample((*_flow42_input).probe); let _flow75_local = ((((vec2<f32>((*_flow42_input).probe, _gv1) - (*_flow42_input).plotCenter) / _flow45_local) + 0.5) * _flow44_local); let _flow76_local = labelColor(_gv0, _flow73_local.yzw); var _sel12: vec3<f32>; if ((abs(_gv1) < 1000000000000000000.0)) { _sel12 = pointColor(_flow74_local, (_flow41_input * _flow44_local), _flow75_local); } else { _sel12 = _flow74_local; } return vec4<f32>(mix(_flow76_local, _sel12, (*_flow42_input).sceneOpacity.y), 1.0); } fn _flow123_fused(_flow80_input: vec2<f32>, _flow81_input: PlotUniforms, _flow83_input: i32) -> vec4<f32> { let _licm0 = vec2<f32>(1.0, 0.0); let _licm1 = vec2<f32>(0.0, 1.0); let _flow124_part = _flow81_input.resolution; let _flow125_part = _flow81_input.plotCenter; let _flow126_part = _flow81_input.plotSpan; let _flow127_part = _flow81_input.plotRotation; let _flow128_part = _flow81_input.rotationBasis; let _flow129_part = _flow81_input.plotPan; let _flow130_part = _flow81_input.plotBlend; let _flow131_part = _flow81_input.appearance; let _flow132_part = _flow81_input.decorations; let _flow133_part = _flow81_input.labelStyle; let _flow134_part = _flow81_input.decorationOpacity; let _flow84_local = max(_flow124_part, vec2<f32>(1.0)); let _flow85_local = max(_flow126_part, vec2<f32>(0.00001)); let _flow86_local = (_flow125_part - (_flow85_local * 0.5)); let _flow87_local = (_flow86_local + (_flow80_input * _flow85_local)); let _flow88_local = (_flow80_input * _flow84_local); let _cse0 = vec2<f32>(14.0); let _flow89_local = clamp((((-_flow86_local) / _flow85_local) * _flow84_local), _cse0, (_flow84_local - _cse0)); let _gv0 = (_flow84_local.x - 12.0); var _flow90_local: f32 = max(stroke(_flow88_local, vec2<f32>(12.0, _flow89_local.y), vec2<f32>(_gv0, _flow89_local.y), _flow131_part.x), stroke(_flow88_local, vec2<f32>(_flow89_local.x, 12.0), vec2<f32>(_flow89_local.x, (_flow84_local.y - 12.0)), _flow131_part.x)); let _flow91_local = _flow125_part.x; let _flow92_local = _flow85_local.x; let _flow93_local = _flow84_local.x; let _flow94_local = _flow131_part.w; let _flow95_local = (((_flow92_local * _flow94_local) * 4.0) / max(_flow93_local, 1.0)); let _lc0 = (_flow92_local * 0.5); let _flow96_local = max(numberWidth((_flow91_local - _lc0), _flow95_local, _flow94_local), numberWidth((_flow91_local + _lc0), _flow95_local, _flow94_local)); let _flow97_local = max((_flow94_local * 3.5), (_flow96_local + (_flow94_local * 1.3))); let _flow98_local = tickLevels(((_flow92_local * _flow97_local) / max((_flow93_local * _flow133_part.x), 1.0))); let _flow101_local = _flow85_local.y; let _flow102_local = _flow84_local.y; let _flow103_local = _flow131_part.w; let _flow106_local = (_flow103_local * 2.6); let _flow107_local = tickLevels(((_flow101_local * _flow106_local) / max((_flow102_local * _flow133_part.x), 1.0))); var _flow109_local: vec3<f32> = vec3<f32>(0.0); var _flow110_local: f32 = 0.0; for (var _flow111_local: i32 = 0; (_flow111_local < 2); _flow111_local = (_flow111_local + 1)) { let _gv2 = (_flow111_local == 0); let _flow112_local = select(vec2<f32>(_flow98_local.y, _flow107_local.y), vec2<f32>(_flow98_local.x, _flow107_local.x), _gv2); let _flow113_local = (floor(((_flow87_local / _flow112_local) + 0.5)) * _flow112_local); var _sel13: vec2<f32>; if (_gv2) { _sel13 = vec2<f32>(tickOpacity(_flow113_local.x, _flow98_local), tickOpacity(_flow113_local.y, _flow107_local)); } else { _sel13 = vec2<f32>(coarseTickOpacity(_flow113_local.x, _flow98_local), coarseTickOpacity(_flow113_local.y, _flow107_local)); } let _flow114_local = _sel13; let _flow115_local = ((abs((_flow87_local - _flow113_local)) / _flow85_local) * _flow84_local); let _flow116_local = (((_flow113_local - _flow86_local) / _flow85_local) * _flow84_local); _flow90_local = max(_flow90_local, max((tickMark(_flow88_local, vec2<f32>(_flow116_local.x, _flow89_local.y), _licm0, 4.0, _flow131_part.x) * _flow114_local.x), (tickMark(_flow88_local, vec2<f32>(_flow89_local.x, _flow116_local.y), _licm1, 4.0, _flow131_part.x) * _flow114_local.y))); _flow110_local = max(_flow110_local, max((distanceCoverage(_flow115_local.x, _flow131_part.y) * _flow114_local.x), (distanceCoverage(_flow115_local.y, _flow131_part.y) * _flow114_local.y))); let _flow117_local = numberWidth(_flow113_local.x, _flow98_local.x, _flow131_part.w); let _flow118_local = smoothstep((_flow117_local + 6.0), (_flow117_local + 14.0), ((_flow112_local.x / _flow85_local.x) * _flow84_local.x)); let _flow119_local = smoothstep((_flow131_part.w * 1.6), (_flow131_part.w * 2.2), ((_flow112_local.y / _flow85_local.y) * _flow84_local.y)); let _gv3 = ((_flow132_part & 2u) != 0u); if (((_gv3 && (_flow116_local.x > ((_flow117_local * 0.5) + 6.0))) && (_flow116_local.x < ((_flow84_local.x - (_flow117_local * 0.5)) - 6.0)))) { _flow109_local = max(_flow109_local, ((numberAt(_flow88_local, vec2<f32>(_flow116_local.x, select((_flow89_local.y - (_flow131_part.w * 0.65)), (_flow89_local.y + (_flow131_part.w * 2.0)), (_flow89_local.y < (_flow131_part.w * 2.0)))), _flow113_local.x, _flow98_local.x, 0.5, _flow131_part.w, _flow133_part.y, _flow133_part.z) * _flow114_local.x) * _flow118_local)); } if ((((_gv3 && (_flow116_local.y > 25.0)) && (_flow116_local.y < (_flow84_local.y - 25.0))) && (abs(_flow113_local.y) > (_flow107_local.x * 0.001)))) { let _lc2 = (_flow89_local.x < (_flow131_part.w * 6.0)); _flow109_local = max(_flow109_local, ((numberAt(_flow88_local, vec2<f32>(select((_flow89_local.x - 8.0), (_flow89_local.x + 8.0), _lc2), (_flow116_local.y + (_flow131_part.w * 0.75))), _flow113_local.y, _flow107_local.x, select(1.0, 0.0, _lc2), _flow131_part.w, _flow133_part.y, _flow133_part.z) * _flow114_local.y) * _flow119_local)); } } _flow109_local *= _flow134_part.y; let _gv1 = ((_flow132_part & 4u) != 0u); if (_gv1) { _flow109_local = max(_flow109_local, (axisLabel(_flow88_local, vec2<f32>(_gv0, clamp((_flow89_local.y + 30.0), 40.0, (_flow84_local.y - 40.0))), 120, PlotViewport(_flow124_part, _flow125_part, _flow126_part, _flow127_part, _flow128_part, _flow129_part, _flow130_part, _flow131_part, _flow132_part, _flow133_part, _flow134_part)) * _flow134_part.z)); } if (_gv1) { _flow109_local = max(_flow109_local, (axisLabel(_flow88_local, _flow143_shared(_flow89_local.x, _flow84_local.x, _flow84_local.y), _flow83_input, PlotViewport(_flow124_part, _flow125_part, _flow126_part, _flow127_part, _flow128_part, _flow129_part, _flow130_part, _flow131_part, _flow132_part, _flow133_part, _flow134_part)) * _flow134_part.z)); } return vec4<f32>(max(_flow90_local, select(0.0, ((_flow110_local * 0.2) * _flow134_part.x), ((_flow132_part & 1u) != 0u))), _flow109_local); } fn _flow139_shared(_flow135_input: vec2<f32>, _flow136_input: vec2<f32>, _flow137_input: f32, _flow138_input: f32) -> bool { return any((abs((_flow135_input - _flow136_input)) > vec2<f32>((((_flow137_input * 1.5) + 4.0) + (1.0 / max(_flow138_input, 0.0001)))))); } fn _flow143_shared(_flow140_input: f32, _flow141_input: f32, _flow142_input: f32) -> vec2<f32> { return vec2<f32>(clamp((_flow140_input + 14.0), 28.0, (_flow141_input - 28.0)), (_flow142_input - 40.0)); } fn _flow147_shared(_flow144_input: vec2<f32>, _flow145_input: vec2<f32>, _flow146_input: vec2<f32>) -> f32 { return clamp((dot((_flow144_input - _flow145_input), _flow146_input) / max(dot(_flow146_input, _flow146_input), 1e-20)), 0.0, 1.0); } GLSL ES 3.00 버텍스…#version 300 es precision highp float; precision highp int; out vec2 uv; void main() { uint i = uint(gl_VertexID); float x = mix(-1.0, 3.0, (i == 1u)); float y = mix(-1.0, 3.0, (i == 2u)); gl_Position = vec4(x, y, 0.0, 1.0); uv = vec2(((x * 0.5) + 0.5), ((y * 0.5) + 0.5)); } GLSL ES 3.00 프래그먼트…#version 300 es precision highp float; precision highp int; struct NumberFormat { float value; bool negative; bool scientific; int decimals; int digits; int exponent; int length; }; struct PlotViewport { vec2 resolution; vec2 plotCenter; vec2 plotSpan; vec2 plotRotation; vec4 rotationBasis; vec2 plotPan; float plotBlend; vec4 appearance; uint decorations; vec4 labelStyle; vec3 decorationOpacity; }; struct PlotUniforms { vec2 resolution; vec2 plotCenter; vec2 plotSpan; vec2 plotRotation; vec4 rotationBasis; vec2 plotPan; float plotBlend; vec4 appearance; uint decorations; vec4 labelStyle; vec3 decorationOpacity; mat4 model; mat4 inverseModel; mat4 axesModel; mat4 inverseAxesModel; vec2 sceneOpacity; vec2 cameraLens; float plotCenterZ; float probe; float parameterFocusSeed; uint view3d; vec2 parameterBounds; uint parameterMode; uvec2 curveQuality; vec4 curvePattern; uvec4 curveTiles; vec4 surfaceBounds; uint surfaceDomainMode; vec2 surfaceRange; vec2 surfaceHeight; vec2 surfaceDepth; vec4 surfaceRender; uint surfaceFlags; }; struct ViewRay { vec3 origin; vec3 direction; }; struct SpatialDecor { vec3 color; vec3 labels; }; layout(std140) uniform Uniforms { vec2 resolution; vec2 plotCenter; vec2 plotSpan; vec2 plotRotation; vec4 rotationBasis; vec2 plotPan; float plotBlend; vec4 appearance; uint decorations; vec4 labelStyle; vec3 decorationOpacity; mat4 model; mat4 inverseModel; mat4 axesModel; mat4 inverseAxesModel; vec2 sceneOpacity; vec2 cameraLens; float plotCenterZ; float probe; float parameterFocusSeed; uint view3d; vec2 parameterBounds; uint parameterMode; uvec2 curveQuality; vec4 curvePattern; uvec4 curveTiles; vec4 surfaceBounds; uint surfaceDomainMode; vec2 surfaceRange; vec2 surfaceHeight; vec2 surfaceDepth; vec4 surfaceRender; uint surfaceFlags; } u; uniform sampler2D glyphAtlas; layout(std140) uniform FontUniforms { float pixelRatio; } font; int _irem(int a, int b) { int d = (b == 0 || (a == int(0x80000000u) && b == -1)) ? 1 : b; return a - (a / d) * d; } int _f2i(float x) { return int(mix(clamp(x, -2147483648.0, 2147483520.0), 0.0, isnan(x))); } ivec2 _f2i(vec2 x) { return ivec2(_f2i(x.x), _f2i(x.y)); } float tickMark(vec2 pixel, vec2 center, vec2 tangent, float halfLength, float width) { if (((width <= 0.0) || (halfLength <= 0.0))) { return 0.0; } vec2 delta = (pixel - center); vec2 normal = vec2((-tangent.y), tangent.x); vec2 q = (abs(vec2(dot(delta, tangent), dot(delta, normal))) - vec2((width * 0.5), halfLength)); float distance = (length(max(q, vec2(0.0))) + min(max(q.x, q.y), 0.0)); float aa = ((1.0 / max(font.pixelRatio, 0.0001)) * 0.5); return (1.0 - smoothstep((-aa), aa, distance)); } vec2 glyphLayers(vec2 p, int code, float fontSize, float halo) { int _i0ret = 0; bool _cse0 = (code >= 32); int _cse1 = (code - 32); if ((_cse0 && (code < 256))) { _i0ret = _cse1; } else { if (((code >= 880) && (code < 1024))) { _i0ret = ((224 + code) - 880); } else { if (((code >= 12592) && (code < 12688))) { _i0ret = ((368 + code) - 12592); } else { _i0ret = (((code >= 44032) && (code <= 55203)) ? ((464 + code) - 44032) : (((code >= 8192) && (code < 8960)) ? ((11636 + code) - 8192) : 12404)); } } } int index = _i0ret; float _cse2 = (fontSize * font.pixelRatio); float referenceSize = 24.0; vec2 cell = vec2(30.0, 36.0); ivec2 origin = ivec2((_irem(index, 132) * 30), ((index / 132) * 36)); if ((_cse0 && (code < 128))) { if ((_cse2 <= 14.0)) { referenceSize = 12.0; cell = vec2(15.0, 18.0); origin = ivec2((_cse1 * 15), 3384); } else if ((_cse2 > 28.0)) { referenceSize = 48.0; cell = vec2(60.0, 72.0); origin = ivec2((_irem(_cse1, 66) * 60), (3402 + ((_cse1 / 66) * 72))); } } vec2 q = ((p * (referenceSize / fontSize)) - vec2(0.5)); if (((((q.x < 0.0) || (q.y < 0.0)) || (q.x >= (cell.x - 1.0))) || (q.y >= (cell.y - 1.0)))) { return vec2(0.0); } ivec2 base = _f2i(floor(q)); vec2 t = fract(q); ivec2 _gv0 = (origin + base); float a = texelFetch(glyphAtlas, _gv0, int(0u)).r; float b = texelFetch(glyphAtlas, (_gv0 + ivec2(1, 0)), int(0u)).r; float c = texelFetch(glyphAtlas, (_gv0 + ivec2(0, 1)), int(0u)).r; float d = texelFetch(glyphAtlas, (_gv0 + ivec2(1, 1)), int(0u)).r; float distance = mix(mix(a, b, t.x), mix(c, d, t.x), t.y); float width = max((2.52 / max(_cse2, 1.0)), 0.00392156862745098); float fill = smoothstep((0.75 - width), (0.75 + width), distance); float outerEdge = (0.75 - ((min(halo, (fontSize * 0.1)) * 3.0) / fontSize)); return vec2(fill, smoothstep((outerEdge - width), (outerEdge + width), distance)); } NumberFormat numberFormat(float input_, float spacing) { float _cse2 = abs(spacing); float value = mix(input_, 0.0, (abs(input_) < (_cse2 * 0.0001))); float magnitude = abs(value); float _cse0 = log2(10.0); int exponent = _f2i(floor((log2(max(magnitude, 1e-30)) / _cse0))); bool scientific = ((magnitude > 0.0) && ((exponent >= 5) || (exponent < -3))); float _cse1 = log2(max(_cse2, 1e-30)); int decimals = _f2i(clamp(ceil(((-_cse1) / _cse0)), 0.0, 6.0)); int digits = 1; if (scientific) { float _gv0 = float(exponent); decimals = _f2i(clamp(ceil((_gv0 - (_cse1 / _cse0))), 0.0, 6.0)); float scale = pow(10.0, float(decimals)); magnitude = floor((((magnitude / pow(10.0, _gv0)) * scale) + 0.5)); bool _ifc0 = (magnitude >= (10.0 * scale)); magnitude = mix(magnitude, scale, _ifc0); exponent = (_ifc0 ? (exponent + 1) : exponent); } else { float _gv1 = pow(10.0, float(decimals)); magnitude = floor(((magnitude * _gv1) + 0.5)); digits = (_f2i(floor((log2(max(floor((magnitude / _gv1)), 1.0)) / _cse0))) + 1); } for (int i = 0; (i < 6); i = (i + 1)) { bool _ifc1 = ((decimals > 0) && (abs((magnitude - (floor((magnitude / 10.0)) * 10.0))) < 0.01)); magnitude = mix(magnitude, (magnitude / 10.0), _ifc1); decimals = (_ifc1 ? (decimals - 1) : decimals); } bool negative = (value < 0.0); int length = (scientific ? ((5 + ((decimals > 0) ? (1 + decimals) : 0)) + (negative ? 1 : 0)) : ((digits + ((decimals > 0) ? (1 + decimals) : 0)) + (negative ? 1 : 0))); return NumberFormat(magnitude, negative, scientific, decimals, digits, exponent, length); } vec2 tickNumberLayers(vec2 p, float value, float spacing, float align, float fontSize, float halo) { NumberFormat n = numberFormat(value, spacing); float advance = (fontSize * 0.625); vec2 offset = (p + vec2(((float(n.length) * advance) * align), 0.0)); vec2 _cse0 = vec2(0.0); if (((offset.y < 0.0) || (offset.y > (fontSize * 1.5)))) { return _cse0; } int column = _f2i(floor((offset.x / advance))); float atlasBearing = (fontSize * 0.125); vec2 coverage = _cse0; for (int neighbor = -1; (neighbor <= 1); neighbor = (neighbor + 1)) { int index = (column + neighbor); if (((index >= 0) && (index < n.length))) { vec2 local = vec2(((offset.x - (float(index) * advance)) + atlasBearing), offset.y); int _i1ret = 0; int _i1_i = index; if ((n.negative && (_i1_i == 0))) { _i1ret = 45; } else { _i1_i = (_i1_i - (n.negative ? 1 : 0)); if (n.scientific) { bool _gv0 = (n.decimals > 0); int _i1_mantissaLength = (1 + (_gv0 ? (1 + n.decimals) : 0)); if ((_i1_i < _i1_mantissaLength)) { if ((_gv0 && (_i1_i == 1))) { _i1ret = 46; } else { int _i1_digit = (_i1_i - ((_i1_i > 1) ? 1 : 0)); _i1ret = (48 + _irem(_f2i(floor((n.value / pow(10.0, float((n.decimals - _i1_digit)))))), 10)); } } else { int _i1_suffix = (_i1_i - _i1_mantissaLength); if ((_i1_suffix == 0)) { _i1ret = 101; } else { if ((_i1_suffix == 1)) { _i1ret = ((n.exponent < 0) ? 45 : 43); } else { _i1ret = ((_i1_suffix == 2) ? (48 + (abs(n.exponent) / 10)) : (48 + _irem(abs(n.exponent), 10))); } } } } else { if (((n.decimals > 0) && (_i1_i == n.digits))) { _i1ret = 46; } else { int _i1_digit_1 = (_i1_i - ((_i1_i > n.digits) ? 1 : 0)); _i1ret = (48 + _irem(_f2i(floor((n.value / pow(10.0, float((((n.digits + n.decimals) - _i1_digit_1) - 1)))))), 10)); } } } coverage = max(coverage, glyphLayers(local, _i1ret, fontSize, halo)); } } return coverage; } float numberWidth(float value, float spacing, float size) { return ((float(numberFormat(value, spacing).length) * size) * 0.625); } vec3 tickLevels(float raw) { float safe = max(raw, 1e-25); float unit = pow(10.0, floor((log2(safe) / log2(10.0)))); bool _gv0 = (safe < (unit * 2.0)); float fine = mix(mix((unit * 5.0), (unit * 2.0), (safe < (unit * 5.0))), unit, _gv0); float coarse = mix(mix((unit * 10.0), (unit * 5.0), (safe < (unit * 5.0))), (unit * 2.0), _gv0); float phase = (log2((safe / fine)) / log2((coarse / fine))); return vec3(fine, coarse, (1.0 - smoothstep(0.0, 1.0, phase))); } float tickOpacity(float value, vec3 levels) { float multiple = (value / levels.y); return mix(levels.z, 1.0, (abs((multiple - floor((multiple + 0.5)))) < 0.001)); } float numberPlate(vec2 p, float value, float spacing, float align, float size) { float width = numberWidth(value, spacing, size); vec2 center = vec2((width * (0.5 - align)), (size * 0.76)); vec2 half_ = vec2(((width * 0.5) + 3.5), ((size * 0.55) + 2.0)); vec2 q = ((abs((p - center)) - half_) + vec2(3.0)); float distance = ((length(max(q, vec2(0.0))) + min(max(q.x, q.y), 0.0)) - 3.0); float _cse0 = (1.0 / max(font.pixelRatio, 0.0001)); return (1.0 - smoothstep(((-_cse0) * 0.5), (_cse0 * 0.5), distance)); } float coarseTickOpacity(float value, vec3 levels) { float multiple = (value / levels.x); return mix((1.0 - levels.z), 1.0, (abs((multiple - floor((multiple + 0.5)))) < 0.001)); } bool _flow135_shared(vec2 _flow131_input, vec2 _flow132_input, float _flow133_input, float _flow134_input) { return any(greaterThan(abs((_flow131_input - _flow132_input)), vec2((((_flow133_input * 1.5) + 4.0) + (1.0 / max(_flow134_input, 0.0001)))))); } vec3 axisLabel(vec2 pixel, vec2 at, int code, PlotViewport function_plot_u_2) { if (_flow135_shared(pixel, at, function_plot_u_2.appearance.w, font.pixelRatio)) { return vec3(0.0); } vec2 local = vec2((pixel.x - at.x), ((at.y - pixel.y) + (function_plot_u_2.appearance.w * 0.75))); return vec3(glyphLayers((local + vec2((function_plot_u_2.appearance.w * 0.42), 0.0)), code, function_plot_u_2.appearance.w, function_plot_u_2.labelStyle.y), (numberPlate(local, 0.0, 1.0, 0.5, function_plot_u_2.appearance.w) * function_plot_u_2.labelStyle.z)); } float distanceCoverage(float distance, float width) { if ((width <= 0.0)) { return 0.0; } float aa = ((1.0 / max(font.pixelRatio, 0.0001)) * 0.5); float _cse0 = (width * 0.5); return (1.0 - smoothstep(max(0.0, (_cse0 - aa)), (_cse0 + aa), distance)); } float stroke(vec2 p, vec2 a, vec2 b, float width) { float radius = (width * 0.5); if ((((width <= 0.0) || any(lessThan(p, (min(a, b) - vec2((radius + 1.0)))))) || any(greaterThan(p, (max(a, b) + vec2((radius + 1.0))))))) { return 0.0; } vec2 ab = (b - a); vec2 _cse0 = (p - a); float t = clamp((dot(_cse0, ab) / max(dot(ab, ab), 0.0001)), 0.0, 1.0); return distanceCoverage(length((_cse0 - (ab * t))), width); } vec3 numberAt(vec2 pixel, vec2 anchor, float value, float spacing, float align, float size, float halo, float plate) { float _cse0 = (pixel.x - anchor.x); float _cse1 = (anchor.y - pixel.y); vec2 delta = vec2(_cse0, _cse1); if ((((_cse1 < 0.0) || (_cse1 > (size * 1.5))) || (abs(_cse0) > (size * 16.0)))) { return vec3(0.0); } return vec3(tickNumberLayers(delta, value, spacing, align, size, halo), (numberPlate(delta, value, spacing, align, size) * plate)); } vec3 labelColor(vec3 color, vec3 labels) { vec3 plated = mix(color, vec3(0.995), (labels.z * 0.94)); return mix(mix(plated, vec3(0.965, 0.973, 0.985), labels.y), vec3(0.25, 0.29, 0.35), labels.x); } vec3 pointColor(vec3 color, vec2 p, vec2 selected) { vec2 _cse0 = (p - selected); if (any(greaterThan(abs(_cse0), vec2(7.0)))) { return color; } float radius = length(_cse0); float halo = (1.0 - smoothstep(5.0, 7.0, radius)); float dot = (1.0 - smoothstep(3.0, 4.5, radius)); return mix(mix(color, vec3(1.0), halo), vec3(0.89, 0.29, 0.04), dot); } vec2 _flow139_shared(float _flow136_input, float _flow137_input, float _flow138_input) { return vec2(clamp((_flow136_input + 14.0), 28.0, (_flow137_input - 28.0)), (_flow138_input - 40.0)); } vec4 axes2D(vec2 uv, PlotViewport function_plot_u_4, int vertical) { vec2 _licm0 = vec2(1.0, 0.0); float _licm1 = function_plot_u_4.appearance.x; vec2 _licm2 = vec2(0.0, 1.0); float _licm3 = function_plot_u_4.appearance.y; float _licm4 = function_plot_u_4.appearance.w; float _licm5 = (function_plot_u_4.appearance.w * 1.6); float _licm6 = (function_plot_u_4.appearance.w * 2.2); float _licm7 = (function_plot_u_4.appearance.w * 0.65); float _licm8 = function_plot_u_4.labelStyle.y; float _licm9 = function_plot_u_4.labelStyle.z; float _licm10 = (function_plot_u_4.appearance.w * 0.75); vec2 size = max(function_plot_u_4.resolution, vec2(1.0)); vec2 span = max(function_plot_u_4.plotSpan, vec2(0.00001)); vec2 lo = (function_plot_u_4.plotCenter - (span * 0.5)); vec2 p = (lo + (uv * span)); vec2 pixel = (uv * size); vec2 _cse0 = vec2(14.0); vec2 origin = clamp((((-lo) / span) * size), _cse0, (size - _cse0)); float _gv0 = (size.x - 12.0); float axes = max(stroke(pixel, vec2(12.0, origin.y), vec2(_gv0, origin.y), _licm1), stroke(pixel, vec2(origin.x, 12.0), vec2(origin.x, (size.y - 12.0)), _licm1)); float _i14a0 = function_plot_u_4.plotCenter.x; float _i14a1 = span.x; float _i14a2 = size.x; float _i14_rough = (((_i14a1 * _licm4) * 4.0) / max(_i14a2, 1.0)); float _lc0 = (_i14a1 * 0.5); float _i14_width = max(numberWidth((_i14a0 - _lc0), _i14_rough, _licm4), numberWidth((_i14a0 + _lc0), _i14_rough, _licm4)); float _i14_gap = max((_licm4 * 3.5), (_i14_width + (_licm4 * 1.3))); vec3 _i14ret = tickLevels(((_i14a1 * _i14_gap) / max((_i14a2 * function_plot_u_4.labelStyle.x), 1.0))); float _i15a1 = span.y; float _i15a2 = size.y; float _i15_gap = (_licm4 * 2.6); vec3 _i15ret = tickLevels(((_i15a1 * _i15_gap) / max((_i15a2 * function_plot_u_4.labelStyle.x), 1.0))); vec3 labels = vec3(0.0); float backgroundGrid = 0.0; bool _cse1 = ((function_plot_u_4.decorations & 2u) != 0u); float _cse2 = (_licm4 * 2.0); float _cse3 = (_licm4 * 6.0); for (int level = 0; (level < 2); level = (level + 1)) { bool _gv1 = (level == 0); vec2 tickStep = mix(vec2(_i14ret.y, _i15ret.y), vec2(_i14ret.x, _i15ret.x), bvec2(_gv1)); vec2 nearest = (floor(((p / tickStep) + 0.5)) * tickStep); vec2 _sel0; if (_gv1) { _sel0 = vec2(tickOpacity(nearest.x, _i14ret), tickOpacity(nearest.y, _i15ret)); } else { _sel0 = vec2(coarseTickOpacity(nearest.x, _i14ret), coarseTickOpacity(nearest.y, _i15ret)); } vec2 weights = _sel0; vec2 grid = ((abs((p - nearest)) / span) * size); vec2 at = (((nearest - lo) / span) * size); axes = max(axes, max((tickMark(pixel, vec2(at.x, origin.y), _licm0, 4.0, _licm1) * weights.x), (tickMark(pixel, vec2(origin.x, at.y), _licm2, 4.0, _licm1) * weights.y))); backgroundGrid = max(backgroundGrid, max((distanceCoverage(grid.x, _licm3) * weights.x), (distanceCoverage(grid.y, _licm3) * weights.y))); float width = numberWidth(nearest.x, _i14ret.x, _licm4); float xFit = smoothstep((width + 6.0), (width + 14.0), ((tickStep.x / span.x) * size.x)); float yFit = smoothstep(_licm5, _licm6, ((tickStep.y / span.y) * size.y)); if (((_cse1 && (at.x > ((width * 0.5) + 6.0))) && (at.x < ((size.x - (width * 0.5)) - 6.0)))) { labels = max(labels, ((numberAt(pixel, vec2(at.x, mix((origin.y - _licm7), (origin.y + _cse2), (origin.y < _cse2))), nearest.x, _i14ret.x, 0.5, _licm4, _licm8, _licm9) * weights.x) * xFit)); } if ((((_cse1 && (at.y > 25.0)) && (at.y < (size.y - 25.0))) && (abs(nearest.y) > (_i15ret.x * 0.001)))) { bool _lc2 = (origin.x < _cse3); labels = max(labels, ((numberAt(pixel, vec2(mix((origin.x - 8.0), (origin.x + 8.0), _lc2), (at.y + _licm10)), nearest.y, _i15ret.x, mix(1.0, 0.0, _lc2), _licm4, _licm8, _licm9) * weights.y) * yFit)); } } labels *= function_plot_u_4.decorationOpacity.y; bool _cse4 = ((function_plot_u_4.decorations & 4u) != 0u); if (_cse4) { labels = max(labels, (axisLabel(pixel, vec2(_gv0, clamp((origin.y + 30.0), 40.0, (size.y - 40.0))), 120, function_plot_u_4) * function_plot_u_4.decorationOpacity.z)); } if (_cse4) { labels = max(labels, (axisLabel(pixel, _flow139_shared(origin.x, size.x, size.y), vertical, function_plot_u_4) * function_plot_u_4.decorationOpacity.z)); } return vec4(max(axes, mix(0.0, ((backgroundGrid * 0.2) * function_plot_u_4.decorationOpacity.x), ((function_plot_u_4.decorations & 1u) != 0u))), labels); } vec3 basisVector(vec3 p, PlotUniforms function_plot_u_8) { vec2 span = max(function_plot_u_8.plotSpan, vec2(0.00001)); vec3 q = (p / vec3(span, max(span.x, span.y))); vec4 basis = function_plot_u_8.rotationBasis; float horizontal = ((q.x * basis.y) + (q.z * basis.x)); float depth = (((-q.x) * basis.x) + (q.z * basis.y)); return vec3(horizontal, ((q.y * basis.w) - (depth * basis.z)), ((q.y * basis.z) + (depth * basis.w))); } vec3 cameraPoint(vec3 p, PlotUniforms function_plot_u_9) { return basisVector(((function_plot_u_9.model * vec4(p, 1.0)).xyz - vec3(function_plot_u_9.plotCenter, function_plot_u_9.plotCenterZ)), function_plot_u_9); } vec3 cameraVector(vec3 p, PlotUniforms function_plot_u_10) { return basisVector((function_plot_u_10.model * vec4(p, 0.0)).xyz, function_plot_u_10); } vec3 inverseCamera(vec3 p, PlotUniforms function_plot_u_12) { vec4 basis = function_plot_u_12.rotationBasis; float y = ((p.y * basis.w) + (p.z * basis.z)); float depth = (((-p.y) * basis.z) + (p.z * basis.w)); vec3 q = vec3(((p.x * basis.y) - (depth * basis.x)), y, ((p.x * basis.x) + (depth * basis.y))); return (function_plot_u_12.inverseModel * vec4((q * vec3(function_plot_u_12.plotSpan, max(function_plot_u_12.plotSpan.x, function_plot_u_12.plotSpan.y))), 0.0)).xyz; } vec3 _spec2_homogeneous(vec3 p, PlotUniforms function_plot_u_13) { vec2 size = max(function_plot_u_13.resolution, vec2(1.0)); vec3 _sel6 = cameraPoint(p, function_plot_u_13); float w = mix(function_plot_u_13.cameraLens.y, (function_plot_u_13.cameraLens.y - _sel6.z), (function_plot_u_13.view3d == 2u)); float focal = (1.0 / function_plot_u_13.cameraLens.x); return vec3((((vec2((_sel6.x / (size.x / size.y)), _sel6.y) * focal) + ((vec2(0.5) + function_plot_u_13.plotPan) * w)) * size), w); } vec2 project(vec3 p, PlotUniforms function_plot_u_14) { vec3 h = _spec2_homogeneous(p, function_plot_u_14); return (h.xy / max(h.z, 0.101)); } bool inFront(vec3 p, PlotUniforms function_plot_u_16) { return ((function_plot_u_16.view3d != 2u) || ((function_plot_u_16.cameraLens.y - cameraPoint(p, function_plot_u_16).z) >= 0.101)); } vec3 _spec3_homogeneous(vec3 p, PlotUniforms function_plot_u_13) { vec2 size = max(function_plot_u_13.resolution, vec2(1.0)); vec3 _sel7 = cameraVector(p, function_plot_u_13); float w = mix(0.0, (-_sel7.z), (function_plot_u_13.view3d == 2u)); float focal = (1.0 / function_plot_u_13.cameraLens.x); return vec3((((vec2((_sel7.x / (size.x / size.y)), _sel7.y) * focal) + ((vec2(0.5) + function_plot_u_13.plotPan) * w)) * size), w); } float axisField(vec2 pixel, vec3 axis, ViewRay ray, PlotUniforms function_plot_u_18) { vec3 _cse0 = vec3(0.0); vec3 origin = _spec2_homogeneous(_cse0, function_plot_u_18); vec3 direction = _spec3_homogeneous(axis, function_plot_u_18); vec3 coefficients = cross(origin, direction); float magnitude = length(coefficients.xy); float distance = length((pixel - project(_cse0, function_plot_u_18))); distance = mix(distance, (abs(dot(coefficients, vec3(pixel, 1.0))) / magnitude), (magnitude > 1e-12)); vec3 transverse = (vec3(1.0) - axis); vec3 a = (ray.origin * transverse); vec3 b = (ray.direction * transverse); float depth = ((-dot(a, b)) / max(dot(b, b), 1e-20)); float _sel1; if (((function_plot_u_18.view3d != 2u) || (depth >= 0.101))) { _sel1 = distanceCoverage(distance, function_plot_u_18.appearance.x); } else { _sel1 = 0.0; } return _sel1; } float groundField(ViewRay ray, PlotUniforms function_plot_u_19, vec3 xLevels, vec3 zLevels) { vec2 _licm0 = vec2(xLevels.x, zLevels.x); vec2 _licm1 = vec2(xLevels.y, zLevels.y); float _licm2 = clamp(function_plot_u_19.labelStyle.x, 0.5, 2.0); float _licm3 = function_plot_u_19.appearance.y; float _cse0 = abs(ray.direction.y); float denominator = mix(ray.direction.y, mix(1e-8, -1e-8, (ray.direction.y < 0.0)), (_cse0 < 1e-8)); float depth = ((-ray.origin.y) / denominator); vec2 ground = (ray.origin + (ray.direction * depth)).xz; vec2 gradient = max(vec2(length(vec2(dFdx(ground.x), dFdy(ground.x))), length(vec2(dFdx(ground.y), dFdy(ground.y)))), vec2(1e-20)); float field = 0.0; float _cse1 = (1.0 / max(font.pixelRatio, 0.0001)); vec2 _licm4 = vec2((12.0 / _licm2)); vec2 _licm5 = vec2((28.0 / _licm2)); for (int level = 0; (level < 2); level = (level + 1)) { bool _gv0 = (level == 0); vec2 spacing = mix(_licm1, _licm0, bvec2(_gv0)); vec2 _gv1 = ((ground / spacing) + 0.5); vec2 distance = (((abs((fract(_gv1) - 0.5)) * spacing) / gradient) * _cse1); vec2 separation = ((spacing / gradient) * _cse1); vec2 fade = smoothstep(_licm4, _licm5, separation); vec2 nearest = (floor(_gv1) * spacing); vec2 _sel2; if (_gv0) { _sel2 = vec2(tickOpacity(nearest.x, xLevels), tickOpacity(nearest.y, zLevels)); } else { _sel2 = vec2(coarseTickOpacity(nearest.x, xLevels), coarseTickOpacity(nearest.y, zLevels)); } vec2 weights = _sel2; field = max(field, max(((distanceCoverage(distance.x, _licm3) * fade.x) * weights.x), ((distanceCoverage(distance.y, _licm3) * fade.y) * weights.y))); } return mix(0.0, (field * function_plot_u_19.decorationOpacity.x), ((((function_plot_u_19.view3d != 2u) || (depth >= 0.101)) && (_cse0 >= 1e-8)) && ((function_plot_u_19.decorations & 1u) != 0u))); } float axisParameter(vec2 pixel, vec3 axis, PlotUniforms function_plot_u_20) { vec3 origin = _spec2_homogeneous(vec3(0.0), function_plot_u_20); vec3 direction = _spec3_homogeneous(axis, function_plot_u_20); vec3 line = cross(origin, direction); vec2 foot = (pixel - ((line.xy * dot(line, vec3(pixel, 1.0))) / max(dot(line.xy, line.xy), 1e-20))); vec2 slope = (direction.xy - (foot * direction.z)); return (dot(((foot * origin.z) - origin.xy), slope) / max(dot(slope, slope), 1e-20)); } PlotViewport PlotUniforms_as_PlotViewport(PlotUniforms value) { return PlotViewport(value.resolution, value.plotCenter, value.plotSpan, value.plotRotation, value.rotationBasis, value.plotPan, value.plotBlend, value.appearance, value.decorations, value.labelStyle, value.decorationOpacity); } vec3 spatialLevels(vec3 axis, PlotUniforms function_plot_u_21) { float center = axisParameter((max(function_plot_u_21.resolution, vec2(1.0)) * 0.5), axis, function_plot_u_21); float span = max(function_plot_u_21.plotSpan.x, function_plot_u_21.plotSpan.y); float h = (span * 0.001); vec2 tangent = ((project((axis * (center + h)), function_plot_u_21) - project((axis * (center - h)), function_plot_u_21)) / (2.0 * h)); float pixels = max((length(tangent) * span), 1.0); bool horizontal = (abs(tangent.x) >= (abs(tangent.y) * 0.7)); PlotViewport _i2a4 = PlotUniforms_as_PlotViewport(function_plot_u_21); float _i2_size = _i2a4.appearance.w; float _i2_rough = (((span * _i2_size) * 4.0) / max(pixels, 1.0)); float _lc0 = (span * 0.5); float _i2_width = max(numberWidth((center - _lc0), _i2_rough, _i2_size), numberWidth((center + _lc0), _i2_rough, _i2_size)); float _i2_gap = mix((_i2_size * 2.6), max((_i2_size * 3.5), (_i2_width + (_i2_size * 1.3))), horizontal); vec3 _i2ret = tickLevels(((span * _i2_gap) / max((pixels * _i2a4.labelStyle.x), 1.0))); return _i2ret; } vec4 spatialTicks(vec2 pixel, vec3 axis, vec3 levels, float priority, PlotUniforms function_plot_u_22) { float _licm0 = levels.x; float _licm1 = levels.y; bool _licm2 = (function_plot_u_22.appearance.x > 0.0); vec2 _licm3 = vec2((((function_plot_u_22.appearance.x * 0.5) + 4.0) + (1.0 / max(font.pixelRatio, 0.0001)))); float _licm4 = function_plot_u_22.appearance.x; float _licm5 = (levels.x * 0.001); float _licm6 = mix(0.0, 1.0, (axis.x > 0.0)); float _licm7 = function_plot_u_22.labelStyle.y; float _licm8 = function_plot_u_22.labelStyle.z; float _licm9 = function_plot_u_22.decorationOpacity.y; vec2 size = max(function_plot_u_22.resolution, vec2(1.0)); float fontSize = function_plot_u_22.appearance.w; vec3 _cse0 = vec3(0.0); vec3 originH = _spec2_homogeneous(_cse0, function_plot_u_22); vec3 directionH = _spec3_homogeneous(axis, function_plot_u_22); vec3 axisLine = cross(originH, directionH); float magnitude = length(axisLine.xy); if (((magnitude <= 1e-12) || ((abs(dot(axisLine, vec3(pixel, 1.0))) / magnitude) > ((fontSize * 6.0) + 12.0)))) { return vec4(0.0); } vec2 normal = (axisLine.xy / magnitude); vec2 tangent = vec2(normal.y, (-normal.x)); float sign = mix(mix(1.0, -1.0, (normal.y > 0.0)), mix(1.0, -1.0, (normal.x > 0.0)), (axis.y > 0.0)); vec2 outward = (normal * sign); float value = axisParameter(pixel, axis, function_plot_u_22); vec3 labels = _cse0; float ticks = 0.0; bool _cse1 = ((function_plot_u_22.decorations & 2u) != 0u); for (int index = 0; (index < 6); index = (index + 1)) { bool _gv0 = (index < 3); float stride = mix(_licm1, _licm0, _gv0); float nearest = (floor(((value / stride) + 0.5)) * stride); float t = (nearest + (float((_irem(index, 3) - 1)) * stride)); vec3 world = (axis * t); if (inFront(world, function_plot_u_22)) { vec2 at = project(world, function_plot_u_22); vec2 anchor = ((at + (outward * ((fontSize * 0.95) + 6.0))) + vec2(0.0, (fontSize * 0.65))); vec2 delta = (pixel - anchor); bool nearLabel = (((_cse1 && (abs(delta.x) <= (fontSize * 9.0))) && (delta.y >= (((-fontSize) * 1.5) - 3.0))) && (delta.y <= 3.0)); bool nearTick = (_licm2 && all(lessThanEqual(abs((pixel - at)), _licm3))); if (((nearLabel == false) && (nearTick == false))) { continue; } vec2 before = project((axis * (t - stride)), function_plot_u_22); vec2 after = project((axis * (t + stride)), function_plot_u_22); float width = numberWidth(t, _licm0, fontSize); float _lc0 = (width * 0.5); float room = min(min(((anchor.x - _lc0) - 3.0), (((size.x - anchor.x) - _lc0) - 3.0)), min((anchor.y - (fontSize * 1.5)), (size.y - anchor.y))); vec2 separation = min(abs((at - before)), abs((after - at))); float _gv1 = (width + fontSize); float _gv2 = ((fontSize * 1.8) + 6.0); float fit = smoothstep(0.85, 1.15, max((separation.x / _gv1), (separation.y / _gv2))); float _sel3; if (_gv0) { _sel3 = tickOpacity(t, levels); } else { _sel3 = coarseTickOpacity(t, levels); } float visibility = (_sel3 * fit); ticks = max(ticks, (tickMark(pixel, at, tangent, 3.0, _licm4) * visibility)); bool zero = (abs(t) <= _licm5); float originDistance = length((at - project(_cse0, function_plot_u_22))); float crossing = mix(smoothstep((fontSize * 2.0), (fontSize * 4.0), originDistance), _licm6, zero); if (_cse1) { labels = max(labels, (((((numberAt(pixel, anchor, t, _licm0, 0.5, fontSize, _licm7, _licm8) * _licm9) * visibility) * smoothstep(0.0, 6.0, room)) * crossing) * priority)); } } } return vec4(ticks, labels); } vec3 _flow10_fused(vec2 _flow0_input, vec2 _flow1_input, int _flow2_input, PlotUniforms _flow3_input) { vec4 _flow18_part = _flow3_input.appearance; vec4 _flow20_part = _flow3_input.labelStyle; if (_flow135_shared(_flow0_input, _flow1_input, _flow18_part.w, font.pixelRatio)) { return vec3(0.0); } vec2 _flow5_local = vec2((_flow0_input.x - _flow1_input.x), ((_flow1_input.y - _flow0_input.y) + (_flow18_part.w * 0.75))); return vec3(glyphLayers((_flow5_local + vec2((_flow18_part.w * 0.42), 0.0)), _flow2_input, _flow18_part.w, _flow20_part.y), (numberPlate(_flow5_local, 0.0, 1.0, 0.5, _flow18_part.w) * _flow20_part.z)); } SpatialDecor spatialBackground(vec2 uv, PlotUniforms function_plot_u_23) { vec2 _licm0 = vec2(10.0, 18.0); float _licm1 = function_plot_u_23.decorationOpacity.z; vec2 _cse0 = max(function_plot_u_23.resolution, vec2(1.0)); vec2 pixel = (uv * _cse0); vec3 _cse1 = vec3(1.0, 0.0, 0.0); vec3 xLevels = spatialLevels(_cse1, function_plot_u_23); vec3 _cse2 = vec3(0.0, 1.0, 0.0); vec3 yLevels = spatialLevels(_cse2, function_plot_u_23); vec3 _cse3 = vec3(0.0, 0.0, 1.0); vec3 zLevels = spatialLevels(_cse3, function_plot_u_23); vec2 _i4_screen = ((uv - vec2(0.5)) - function_plot_u_23.plotPan); vec2 _i4_cameraXY = (vec2((_i4_screen.x * (_cse0.x / _cse0.y)), _i4_screen.y) * function_plot_u_23.cameraLens.x); bool _cse4 = (function_plot_u_23.view3d == 2u); vec3 _i4_origin = mix(vec3((_i4_cameraXY * function_plot_u_23.cameraLens.y), function_plot_u_23.cameraLens.y), vec3(0.0, 0.0, function_plot_u_23.cameraLens.y), bvec3(_cse4)); vec3 _i4_direction = mix(vec3(0.0, 0.0, -1.0), vec3(_i4_cameraXY, -1.0), bvec3(_cse4)); ViewRay _i4ret = ViewRay((inverseCamera(_i4_origin, function_plot_u_23) + (function_plot_u_23.inverseModel * vec4(function_plot_u_23.plotCenter, function_plot_u_23.plotCenterZ, 1.0)).xyz), inverseCamera(_i4_direction, function_plot_u_23)); float grid = groundField(_i4ret, function_plot_u_23, xLevels, zLevels); vec4 xTicks = spatialTicks(pixel, _cse1, xLevels, 1.0, function_plot_u_23); vec4 yTicks = spatialTicks(pixel, _cse2, yLevels, 1.0, function_plot_u_23); vec2 origin = project(vec3(0.0), function_plot_u_23); vec3 xDirection = _spec3_homogeneous(_cse1, function_plot_u_23); vec3 zDirection = _spec3_homogeneous(_cse3, function_plot_u_23); vec2 _cse5 = vec2(1e-12); vec2 xTangent = normalize(((xDirection.xy - (origin * xDirection.z)) + _cse5)); vec2 zTangent = normalize(((zDirection.xy - (origin * zDirection.z)) + _cse5)); float angle = abs(((xTangent.x * zTangent.y) - (xTangent.y * zTangent.x))); vec4 zTicks = spatialTicks(pixel, _cse3, zLevels, smoothstep(0.08, 0.25, angle), function_plot_u_23); vec3 labels = max(max(xTicks.yzw, yTicks.yzw), zTicks.yzw); vec3 _cse6 = vec3(0.965, 0.973, 0.985); vec3 color = mix(_cse6, vec3(0.8, 0.82, 0.85), (grid * 0.65)); color = mix(color, vec3(0.67, 0.28, 0.25), axisField(pixel, _cse1, _i4ret, function_plot_u_23)); color = mix(color, vec3(0.23, 0.47, 0.3), axisField(pixel, _cse2, _i4ret, function_plot_u_23)); color = mix(color, vec3(0.4, 0.35, 0.62), axisField(pixel, _cse3, _i4ret, function_plot_u_23)); color = mix(color, vec3(0.25, 0.29, 0.35), max(max(xTicks.x, yTicks.x), zTicks.x)); if (((function_plot_u_23.decorations & 4u) != 0u)) { vec2 _cse7 = vec2(18.0); for (int index = 0; (index < 3); index = (index + 1)) { vec3 axis = mix(mix(_cse3, _cse2, bvec3((index == 1))), _cse1, bvec3((index == 0))); vec2 edge = mix(vec2((_cse0.x - 30.0), (_cse0.y * 0.5)), vec2((_cse0.x * 0.5), (_cse0.y - 30.0)), bvec2((index == 1))); vec3 world = (axis * axisParameter(edge, axis, function_plot_u_23)); if (inFront(world, function_plot_u_23)) { vec2 at = clamp((project(world, function_plot_u_23) + _licm0), _cse7, (_cse0 - _cse7)); labels = max(labels, (_flow10_fused(pixel, at, (120 + index), function_plot_u_23) * _licm1)); } } } return SpatialDecor(mix(_cse6, color, function_plot_u_23.sceneOpacity.x), (labels * function_plot_u_23.sceneOpacity.x)); } float _flow143_shared(vec2 _flow140_input, vec2 _flow141_input, vec2 _flow142_input) { return clamp((dot((_flow140_input - _flow141_input), _flow142_input) / max(dot(_flow142_input, _flow142_input), 1e-20)), 0.0, 1.0); } float intervalChordDistance(vec2 pixel, vec2 a, vec2 b) { vec2 delta = (b - a); float along = _flow143_shared(pixel, a, delta); return length(((pixel - a) - (along * delta))); } float parameterAt(float q, float scale, float center, PlotUniforms function_plot_u_27) { float safe = clamp(q, -0.99999, 0.99999); if ((function_plot_u_27.parameterMode == 3u)) { return (center + ((scale * safe) / (1.0 - abs(safe)))); } float positive = ((safe + 1.0) * 0.5); if ((function_plot_u_27.parameterMode == 2u)) { return (function_plot_u_27.parameterBounds.x + ((scale * positive) / max((1.0 - positive), 0.00001))); } return (function_plot_u_27.parameterBounds.y - ((scale * (1.0 - positive)) / max(positive, 0.00001))); } float sample_(float x) { if ((abs(x) > 1.0)) { return 100000000000000000000.0; } return acos(x); } vec2 parameterFocus_trajectory(PlotUniforms function_plot_u_28) { float _licm0 = function_plot_u_28.parameterFocusSeed; vec2 pixel = (max(function_plot_u_28.resolution, vec2(1.0)) * 0.5); float center = _licm0; vec3 initial = vec3(center, sample_(center), 0.0); float _sel4 = 0.0; vec3 _cse0 = vec3(1000000000000000000.0); if ((all(lessThan(abs(initial), _cse0)) && inFront(initial, function_plot_u_28))) { vec2 _lc0 = (project(initial, function_plot_u_28) - pixel); _sel4 = dot(_lc0, _lc0); } else { _sel4 = 1e+30; } float error = _sel4; for (int level = 0; (level < 8); level = (level + 1)) { float radius = pow(4.0, float(level)); float _i6a0 = (_licm0 - radius); vec3 a = vec3(_i6a0, sample_(_i6a0), 0.0); float _i7a0 = (_licm0 + radius); vec3 b = vec3(_i7a0, sample_(_i7a0), 0.0); if ((all(lessThan(abs(a), _cse0)) && all(lessThan(abs(b), _cse0)))) { vec3 middle = ((a + b) * 0.5); vec3 direction = ((b - a) / (2.0 * radius)); vec3 originH = _spec2_homogeneous(middle, function_plot_u_28); vec3 directionH = _spec3_homogeneous(direction, function_plot_u_28); vec2 slope = (directionH.xy - (pixel * directionH.z)); float norm = dot(slope, slope); if ((norm > 1e-20)) { float candidate = (_licm0 + (dot(((pixel * originH.z) - originH.xy), slope) / norm)); vec3 point = vec3(candidate, sample_(candidate), 0.0); if ((((abs(candidate) < 1000000000000000000.0) && all(lessThan(abs(point), _cse0))) && inFront(point, function_plot_u_28))) { vec2 delta = (project(point, function_plot_u_28) - pixel); float nextError = dot(delta, delta); bool _ifc0 = (nextError < error); center = mix(center, candidate, _ifc0); error = mix(error, nextError, _ifc0); } } } } float speed = 1.0; for (int i = 0; (i < 4); i = (i + 1)) { float h = max((abs(center) * 0.00001), 0.001); vec3 at = vec3(center, sample_(center), 0.0); float _i8a0 = (center - h); vec3 left = vec3(_i8a0, sample_(_i8a0), 0.0); float _i9a0 = (center + h); vec3 right = vec3(_i9a0, sample_(_i9a0), 0.0); float _gv0 = (2.0 * h); vec3 normalized = cameraVector(((right - left) / _gv0), function_plot_u_28); speed = max(length(normalized), 1e-10); vec2 tangent = ((project(right, function_plot_u_28) - project(left, function_plot_u_28)) / _gv0); float correction = clamp((dot((pixel - project(at, function_plot_u_28)), tangent) / max(dot(tangent, tangent), 1e-20)), (-32.0 / speed), (32.0 / speed)); float candidate_1 = (center + correction); for (int backtrack = 0; (backtrack < 4); backtrack = (backtrack + 1)) { vec3 point_1 = vec3(candidate_1, sample_(candidate_1), 0.0); vec2 delta_1 = (project(point_1, function_plot_u_28) - pixel); float nextError_1 = dot(delta_1, delta_1); if (((all(lessThan(abs(point_1), _cse0)) && inFront(point_1, function_plot_u_28)) && (nextError_1 <= error))) { center = candidate_1; error = nextError_1; break; } candidate_1 = ((candidate_1 + center) * 0.5); } } float scale = clamp((2.0 / speed), 0.00001, 10000000000.0); scale = mix(scale, max(scale, abs((center - function_plot_u_28.parameterBounds.y))), (function_plot_u_28.parameterMode == 1u)); scale = mix(scale, max(scale, abs((center - function_plot_u_28.parameterBounds.x))), (function_plot_u_28.parameterMode == 2u)); return vec2(center, scale); } vec2 refineTrajectoryHit_trajectory(vec2 pixel, vec4 candidate, PlotUniforms function_plot_u_24, bool jumps) { float _licm0 = (function_plot_u_24.appearance.z * 0.5); float t = candidate.y; float low = candidate.z; float high = candidate.w; float epsilon = max(max(((high - low) * 0.001), (abs(t) * 0.000001)), 1e-7); bool _cse0 = (jumps == false); vec3 _cse1 = vec3(1000000000000000000.0); float _cse2 = (1.0 / max(font.pixelRatio, 0.0001)); for (int iteration = 0; (iteration < 12); iteration = (iteration + 1)) { float before = max(low, (t - epsilon)); float after = min(high, (t + epsilon)); vec2 a = project(vec3(before, sample_(before), 0.0), function_plot_u_24); vec2 b = project(vec3(after, sample_(after), 0.0), function_plot_u_24); vec2 tangent = ((b - a) / max((after - before), 1e-20)); vec3 atWorld = vec3(t, sample_(t), 0.0); vec2 at = project(atWorld, function_plot_u_24); vec2 _gv0 = (at - pixel); float delta = (dot(_gv0, tangent) / max(dot(tangent, tangent), 1e-20)); float next = clamp((t - delta), low, high); vec3 world = vec3(next, sample_(next), 0.0); vec2 projected = project(world, function_plot_u_24); float error = dot(_gv0, _gv0); if ((((_cse0 && all(lessThan(abs(atWorld), _cse1))) && inFront(atWorld, function_plot_u_24)) && (error <= pow(max(0.0, (_licm0 - (_cse2 * 0.5))), 2.0)))) { return vec2(sqrt(error), t); } bool _sc1 = (all(lessThan(abs(world), _cse1)) && inFront(world, function_plot_u_24)); if (_sc1) { vec2 _lc2 = (projected - pixel); _sc1 = (dot(_lc2, _lc2) <= error); } if ((_sc1 == false)) { next = ((t + next) * 0.5); world = vec3(next, sample_(next), 0.0); projected = project(world, function_plot_u_24); } bool _sc3 = (all(lessThan(abs(world), _cse1)) && inFront(world, function_plot_u_24)); if (_sc3) { vec2 _lc4 = (projected - pixel); _sc3 = (dot(_lc4, _lc4) <= error); } if (_sc3) { if ((next == t)) { break; } float movement = length((projected - at)); t = next; if ((movement < (_cse2 * 0.01))) { break; } } else { break; } } vec3 world_1 = vec3(t, sample_(t), 0.0); float _i10a0 = ((low + high) * 0.5); vec3 middle = vec3(_i10a0, sample_(_i10a0), 0.0); bool _sc5 = _cse0; if ((_sc5 == false)) { vec3 _lc6 = vec3(low, sample_(low), 0.0); vec3 _lc7 = vec3(high, sample_(high), 0.0); _sc5 = (length((middle - ((_lc6 + _lc7) * 0.5))) <= max(0.000001, (length((_lc7 - _lc6)) * 0.2))); } bool continuous = _sc5; float _sel5; if (((all(lessThan(abs(world_1), _cse1)) && continuous) && inFront(world_1, function_plot_u_24))) { _sel5 = length((pixel - project(world_1, function_plot_u_24))); } else { _sel5 = 100000000000000000000.0; } return vec2(_sel5, t); } vec2 intervalHit_trajectory(vec2 pixel, float low, float high, PlotUniforms function_plot_u_25, bool jumps) { float start = low; float end = high; vec3 a = vec3(start, sample_(start), 0.0); vec3 b = vec3(end, sample_(end), 0.0); bool frontA = inFront(a, function_plot_u_25); bool frontB = inFront(b, function_plot_u_25); vec3 _cse0 = vec3(1000000000000000000.0); if ((((all(lessThan(abs(a), _cse0)) && all(lessThan(abs(b), _cse0))) == false) || ((frontA == false) && (frontB == false)))) { return vec2(100000000000000000000.0, low); } if ((frontA != frontB)) { float left = start; float right = end; for (int i = 0; (i < 12); i = (i + 1)) { float middle = ((left + right) * 0.5); bool _ifc0 = (inFront(vec3(middle, sample_(middle), 0.0), function_plot_u_25) == frontA); left = mix(left, middle, _ifc0); right = mix(middle, right, _ifc0); } end = mix(end, left, frontA); start = mix(right, start, frontA); a = vec3(start, sample_(start), 0.0); b = vec3(end, sample_(end), 0.0); } vec3 ha = _spec2_homogeneous(a, function_plot_u_25); vec3 hb = _spec2_homogeneous(b, function_plot_u_25); vec2 pa = (ha.xy / ha.z); vec2 pb = (hb.xy / hb.z); vec2 delta = (pb - pa); float screenFraction = _flow143_shared(pixel, pa, delta); float fraction = ((screenFraction * ha.z) / max(mix(hb.z, ha.z, screenFraction), 1e-20)); float seed = mix(start, end, fraction); vec4 candidate = vec4(0.0, seed, start, end); vec2 refined = refineTrajectoryHit_trajectory(pixel, candidate, function_plot_u_25, jumps); float _i11a0 = ((start + end) * 0.5); vec3 middle_1 = vec3(_i11a0, sample_(_i11a0), 0.0); bool continuous = ((jumps == false) || (length((middle_1 - ((a + b) * 0.5))) <= max(0.000001, (length((b - a)) * 0.2)))); float first = length((pixel - pa)); float last = length((pixel - pb)); refined = mix(refined, vec2(first, start), bvec2((first < refined.x))); refined = mix(refined, vec2(last, end), bvec2((last < refined.x))); return mix(vec2(100000000000000000000.0, start), refined, bvec2(continuous)); } float _spec7_trajectoryDistance_trajectory(vec2 pixel, PlotUniforms function_plot_u_29, vec2 bounds) { float _licm0 = bounds.x; float _licm1 = bounds.y; bool _licm2 = (function_plot_u_29.curvePattern.x != 0.0); float _licm3 = function_plot_u_29.curvePattern.y; float _licm4 = function_plot_u_29.curvePattern.z; float _licm5 = function_plot_u_29.curvePattern.w; float _licm6 = (function_plot_u_29.appearance.z * 0.5); float _licm7 = ((1.0 / max(font.pixelRatio, 0.0001)) * 2.0); float requested = float(function_plot_u_29.curveQuality.x); float range = (_licm1 - _licm0); bool unbounded = (function_plot_u_29.parameterMode != 0u); vec2 _sel8; if (unbounded) { _sel8 = parameterFocus_trajectory(function_plot_u_29); } else { _sel8 = vec2(0.0, 1.0); } vec2 focus = _sel8; int count = _f2i(min(512.0, mix(max(requested, ceil(((range / _licm3) * 4.0))), requested, (unbounded || (function_plot_u_29.curvePattern.x == 0.0))))); float _gv0 = float(count); float stepSize = (range / _gv0); float distance = 100000000000000000000.0; vec3 _cse0 = vec3(1000000000000000000.0); for (int i = 0; (i < count); i = (i + 1)) { float _gv1 = float(i); float low = (_licm0 + (_gv1 * stepSize)); float high = min(_licm1, (low + stepSize)); if (unbounded) { low = parameterAt((-1.0 + ((2.0 * _gv1) / _gv0)), focus.y, focus.x, function_plot_u_29); high = parameterAt((-1.0 + ((2.0 * float((i + 1))) / _gv0)), focus.y, focus.x, function_plot_u_29); } float t = ((low + high) * 0.5); if (_licm2) { float center = (((floor(((t + _licm4) / _licm3)) + 0.5) * _licm3) - _licm4); float _gv2 = ((_licm3 * _licm5) * 0.5); low = max(low, (center - _gv2)); high = min(high, (center + _gv2)); t = ((low + high) * 0.5); } if ((high >= low)) { vec3 a = vec3(low, sample_(low), 0.0); vec3 middle = vec3(t, sample_(t), 0.0); vec3 b = vec3(high, sample_(high), 0.0); bool finite = ((all(lessThan(abs(a), _cse0)) && all(lessThan(abs(middle), _cse0))) && all(lessThan(abs(b), _cse0))); if (finite) { bool possible = true; if (((inFront(a, function_plot_u_29) && inFront(middle, function_plot_u_29)) && inFront(b, function_plot_u_29))) { vec2 pa = project(a, function_plot_u_29); vec2 pm = project(middle, function_plot_u_29); vec2 pb = project(b, function_plot_u_29); float bending = intervalChordDistance(pm, pa, pb); float guard = (((bending * 4.0) + _licm6) + _licm7); possible = (min(intervalChordDistance(pixel, pa, pm), intervalChordDistance(pixel, pm, pb)) <= guard); } if (possible) { distance = min(distance, intervalHit_trajectory(pixel, low, t, function_plot_u_29, false).x); distance = min(distance, intervalHit_trajectory(pixel, t, high, function_plot_u_29, false).x); } } } } return distance; } vec4 _flow35_fused(vec2 _flow22_input) { PlotUniforms _flow34_arg = PlotUniforms(u.resolution, u.plotCenter, u.plotSpan, u.plotRotation, u.rotationBasis, u.plotPan, u.plotBlend, u.appearance, u.decorations, u.labelStyle, u.decorationOpacity, u.model, u.inverseModel, u.axesModel, u.inverseAxesModel, u.sceneOpacity, u.cameraLens, u.plotCenterZ, u.probe, u.parameterFocusSeed, u.view3d, u.parameterBounds, u.parameterMode, u.curveQuality, u.curvePattern, u.curveTiles, u.surfaceBounds, u.surfaceDomainMode, u.surfaceRange, u.surfaceHeight, u.surfaceDepth, u.surfaceRender, u.surfaceFlags); vec2 _cse0 = vec2(1.0); float _sel9; if ((u.appearance.z > 0.0)) { _sel9 = _spec7_trajectoryDistance_trajectory((_flow22_input * max(u.resolution, _cse0)), _flow34_arg, u.parameterBounds); } else { _sel9 = 100000000000000000000.0; } float _flow23_local = _sel9; SpatialDecor _flow38_whole = spatialBackground(_flow22_input, PlotUniforms(u.resolution, u.plotCenter, u.plotSpan, u.plotRotation, u.rotationBasis, u.plotPan, u.plotBlend, u.appearance, u.decorations, u.labelStyle, u.decorationOpacity, u.axesModel, u.inverseAxesModel, u.axesModel, u.inverseAxesModel, u.sceneOpacity, u.cameraLens, u.plotCenterZ, u.probe, u.parameterFocusSeed, u.view3d, u.parameterBounds, u.parameterMode, u.curveQuality, u.curvePattern, u.curveTiles, u.surfaceBounds, u.surfaceDomainMode, u.surfaceRange, u.surfaceHeight, u.surfaceDepth, u.surfaceRender, u.surfaceFlags)); vec3 _flow36_part = _flow38_whole.color; vec3 _flow37_part = _flow38_whole.labels; float _flow25_local = u.probe; vec3 _flow26_local = vec3(_flow25_local, sample_(_flow25_local), 0.0); bool _flow27_local = ((((((u.parameterMode & 1u) != 0u) || (u.probe >= u.parameterBounds.x)) && (((u.parameterMode & 2u) != 0u) || (u.probe <= u.parameterBounds.y))) && all(lessThan(abs(_flow26_local), vec3(1000000000000000000.0)))) && inFront(_flow26_local, _flow34_arg)); vec3 _flow28_local = vec3(project(_flow26_local, _flow34_arg), mix(0.0, 1.0, _flow27_local)); vec2 _flow30_local = (_flow22_input * max(u.resolution, _cse0)); vec3 _flow31_local = mix(_flow36_part, vec3(0.09, 0.42, 0.92), distanceCoverage(_flow23_local, u.appearance.z)); _flow31_local = labelColor(_flow31_local, _flow37_part); vec3 _sel10; if ((_flow28_local.z > 0.0)) { _sel10 = pointColor(_flow31_local, _flow30_local, _flow28_local.xy); } else { _sel10 = _flow31_local; } vec4 _flow32_local = vec4(mix(labelColor(_flow36_part, _flow37_part), _sel10, u.sceneOpacity.y), 1.0); return _flow32_local; } vec4 _flow75_fused(vec2 _flow39_input) { bool _licm0 = (u.curvePattern.x == 0.0); float _licm1 = u.curvePattern.y; float _licm2 = u.curvePattern.z; float _licm3 = (u.curvePattern.w * 0.5); bool _licm4 = (false == false); float _licm5 = u.appearance.z; PlotUniforms _flow74_arg = PlotUniforms(u.resolution, u.plotCenter, u.plotSpan, u.plotRotation, u.rotationBasis, u.plotPan, u.plotBlend, u.appearance, u.decorations, u.labelStyle, u.decorationOpacity, u.model, u.inverseModel, u.axesModel, u.inverseAxesModel, u.sceneOpacity, u.cameraLens, u.plotCenterZ, u.probe, u.parameterFocusSeed, u.view3d, u.parameterBounds, u.parameterMode, u.curveQuality, u.curvePattern, u.curveTiles, u.surfaceBounds, u.surfaceDomainMode, u.surfaceRange, u.surfaceHeight, u.surfaceDepth, u.surfaceRender, u.surfaceFlags); vec2 _flow40_local = max(u.resolution, vec2(1.0)); vec2 _flow41_local = max(u.plotSpan, vec2(0.00001)); vec2 _flow42_local = (u.plotCenter + ((_flow39_input - 0.5) * _flow41_local)); vec2 _flow43_local = dFdx(_flow42_local); vec2 _flow44_local = dFdy(_flow42_local); float _flow45_local = 0.0; float _cse0 = (1.0 / max(font.pixelRatio, 0.0001)); vec2 _licm6 = vec2(_flow43_local.x, _flow44_local.x); vec2 _licm7 = vec2(_flow43_local.y, _flow44_local.y); float _licm8 = (length(_licm6) * 0.125); for (int _flow46_local = 0; (_flow46_local < 4); _flow46_local = (_flow46_local + 1)) { vec2 _flow47_local = vec2(mix(0.25, -0.25, ((_flow46_local & 1) == 0)), mix(0.25, -0.25, ((_flow46_local & 2) == 0))); vec2 _flow48_local = ((_flow42_local + (_flow43_local * _flow47_local.x)) + (_flow44_local * _flow47_local.y)); float _flow49_local = sample_(_flow48_local.x); float _flow52_local = max(max(_licm8, (abs(_flow48_local.x) * 0.000001)), 1e-7); float _flow53_local = sample_((_flow48_local.x - _flow52_local)); float _flow54_local = sample_((_flow48_local.x + _flow52_local)); float _flow55_local = ((_flow54_local - _flow53_local) / (2.0 * _flow52_local)); _flow55_local = mix(_flow55_local, ((_flow54_local - _flow49_local) / _flow52_local), ((abs(_flow53_local) < 1000000000000000000.0) == false)); _flow55_local = mix(_flow55_local, ((_flow49_local - _flow53_local) / _flow52_local), ((abs(_flow54_local) < 1000000000000000000.0) == false)); vec2 _flow56_local = (_licm7 - (_flow55_local * _licm6)); float _flow57_local = max(dot(_flow56_local, _flow56_local), 1e-30); float _flow58_local = (_flow48_local.y - _flow49_local); float _gv2 = sqrt(_flow57_local); float _flow59_local = ((abs(_flow58_local) / _gv2) * _cse0); float _flow60_local = (_flow48_local.x - ((_flow58_local * dot(_licm6, _flow56_local)) / _flow57_local)); float _flow61_local = (abs(((_flow43_local.x * _flow44_local.y) - (_flow44_local.x * _flow43_local.y))) / _gv2); float _flow62_local; if (_licm0) { _flow62_local = 0.0; } else { float _flow64_local = fract(((_flow60_local + _licm2) / _licm1)); float _flow65_local = (max(0.0, (abs((_flow64_local - 0.5)) - _licm3)) * _licm1); _flow62_local = ((_flow65_local / max(_flow61_local, 1e-20)) * _cse0); } float _flow66_local = _flow62_local; bool _flow67_local = (_licm4 || (abs((_flow49_local - ((_flow53_local + _flow54_local) * 0.5))) <= max((length(_licm7) * 2.0), (abs((_flow54_local - _flow53_local)) * 0.2)))); float _sel11; if ((((abs(_flow49_local) < 1000000000000000000.0) && (abs(_flow55_local) < 1000000000000000000.0)) && _flow67_local)) { _sel11 = distanceCoverage(length(vec2(_flow59_local, _flow66_local)), _licm5); } else { _sel11 = 0.0; } float _flow68_local = _sel11; _flow45_local += (_flow68_local * 0.25); } vec4 _flow69_local = (axes2D(_flow39_input, PlotUniforms_as_PlotViewport(_flow74_arg), 121) * u.sceneOpacity.x); vec3 _cse1 = vec3(0.965, 0.973, 0.985); vec3 _cse2 = vec3(0.39, 0.43, 0.49); vec3 _gv0 = mix(_cse1, _cse2, _flow69_local.x); vec3 _flow70_local = _gv0; _flow70_local = mix(_flow70_local, vec3(0.09, 0.42, 0.92), _flow45_local); _flow70_local = labelColor(_flow70_local, _flow69_local.yzw); float _gv1 = sample_(u.probe); vec2 _flow71_local = ((((vec2(u.probe, _gv1) - u.plotCenter) / _flow41_local) + 0.5) * _flow40_local); vec3 _flow72_local = labelColor(_gv0, _flow69_local.yzw); vec3 _sel12; if ((abs(_gv1) < 1000000000000000000.0)) { _sel12 = pointColor(_flow70_local, (_flow39_input * _flow40_local), _flow71_local); } else { _sel12 = _flow70_local; } return vec4(mix(_flow72_local, _sel12, u.sceneOpacity.y), 1.0); } in vec2 uv; layout(location = 0) out vec4 _ret; vec4 main_impl(vec2 uv) { vec4 flat_ = _flow75_fused(uv); if ((u.plotBlend <= 0.0)) { return flat_; } return mix(flat_, _flow35_fused(uv), clamp(u.plotBlend, 0.0, 1.0)); } void main() { _ret = main_impl(uv); } 유니폼 블록 필드타입오프셋 resolutionvec2<f32>0plotCentervec2<f32>8plotSpanvec2<f32>16plotRotationvec2<f32>24rotationBasisvec4<f32>32plotPanvec2<f32>48plotBlendf3256appearancevec4<f32>64decorationsu3280labelStylevec4<f32>96decorationOpacityvec3<f32>112modelmat4x4<f32>128inverseModelmat4x4<f32>192axesModelmat4x4<f32>256inverseAxesModelmat4x4<f32>320sceneOpacityvec2<f32>384cameraLensvec2<f32>392plotCenterZf32400probef32404parameterFocusSeedf32408view3du32412parameterBoundsvec2<f32>416parameterModeu32424curveQualityvec2<u32>432curvePatternvec4<f32>448curveTilesvec4<u32>464surfaceBoundsvec4<f32>480surfaceDomainModeu32496surfaceRangevec2<f32>504surfaceHeightvec2<f32>512surfaceDepthvec2<f32>520surfaceRendervec4<f32>528surfaceFlagsu32544 활용단위 벡터의 내적을 유효 범위로 제한한 뒤 두 벡터 사이의 각도를 구하는 데 사용합니다.계산 예제: acos(0.5) ≈ 1.0472참고 계산의 결과는 읽기 쉽게 반올림했습니다. 실제 셰이더 출력은 대상 언어의 정밀도 규칙을 따릅니다.입력 범위와 주의사항이 예제의 입력 조건: −1≤x≤1내적을 입력으로 사용할 때는 부동소수점 오차로 유효 범위를 조금 벗어난 값도 범위 안으로 제한해야 합니다.셰이더의 입력 규칙과 정밀도는 WGSL과 GLSL ES 3.00에서 규정합니다.관련 함수sincostanasin WGSL acos(a) GLSL ES 3.00 acos(a) 시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 af54ddad5의 컴파일러가 쓴 영어 원문입니다. Returns the arccosine of x (in radians), componentwise over vectors. 구문 declare function acos<V extends vec2 | vec3 | vec4>(a0: V): Vdeclare function acos<P0 extends number>(a0: P0): ScalarOf<P0>declare function acos<T extends Numeric>(a0: T): T 매개변수나 반환 위치에 쓰인 number는 스칼라가 들어갈 자리입니다. 앰비언트 파일은 GPU 스칼라를 브랜드가 붙은 number로 선언하고 그 브랜드는 선택이라서, 리터럴도 브랜드가 붙은 스칼라도 이 자리에 들어갑니다. type f32 = number & { readonly [f32Tag]?: true }타입으로 쓴 number는 쓰이는 곳을 보고 추론하며, f32, i32, u32는 너비를 고정합니다. 그 행과 컴파일러가 낸 결과는 TypeScript에서 페이지에 있습니다. 시그니처에는 앰비언트 파일이 스스로 쓰려고 선언한 타입이 나올 수 있습니다. 아래가 그 선언입니다. ScalarOf type ScalarOf<A, B = unknown, C = unknown> = unknown extends A ? number : [A] extends [boolean] ? bool : typeof f32Tag extends keyof A ? f32 : typeof i32Tag extends keyof A ? i32 : typeof u32Tag extends keyof A ? u32 : typeof f64Tag extends keyof A ? f64 : ScalarOf<B, C> Numeric type Numeric = number | vec2 | vec3 | vec4 | vec2i | vec3i | vec4i | vec2u | vec3u | vec4u 매개변수 a0, a1처럼 자리로만 붙은 매개변수 이름은 앰비언트 파일이 만들어 낸 것입니다. 호출은 인자를 순서대로 넘기고 이름은 쓰지 않습니다. a0 VP0T 반환값 VScalarOf<P0>T 설명 The domain is [-1, 1]. Outside it the GPU result is undefined, and the CPU oracle returns NaN. CPU 오라클이 f64로 직접 계산합니다. 대상별 출력 WGSL acos(a) GLSL ES 3.00 acos(a) 예제 gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts 함께 보기 함수내장 함수 표Math.acostypeshade/core/ir의 acos() 이 페이지 편집 문제 보고 이전asin 다음atan