/** * Line Vertex Shader * * Transforms 2D points from data space to clip space using uniforms. * This allows zoom/pan without recreating vertex buffers. */ export declare const lineVertexShader = "\nprecision highp float;\n\n// Attributes (per-vertex data)\nattribute vec2 position;\n\n// Uniforms (constant across all vertices)\nuniform vec2 uScale; // Zoom factor [scaleX, scaleY]\nuniform vec2 uTranslate; // Pan offset [translateX, translateY]\nuniform vec2 uResolution; // Canvas size in pixels\n\n// Varying (passed to fragment shader)\nvarying float vAlpha;\n\nvoid main() {\n // Transform position: apply scale and translate\n vec2 pos = position * uScale + uTranslate;\n\n // pos is now in normalized device coordinates (-1 to 1)\n gl_Position = vec4(pos, 0.0, 1.0);\n\n // Pass alpha for potential fading effects\n vAlpha = 1.0;\n}\n"; /** * Line Fragment Shader * * Simple solid color output with configurable opacity. */ export declare const lineFragmentShader = "\nprecision highp float;\n\n// Uniforms\nuniform vec4 uColor; // RGBA color\n\n// Varying from vertex shader\nvarying float vAlpha;\n\nvoid main() {\n gl_FragColor = vec4(uColor.rgb, uColor.a * vAlpha);\n}\n"; /** * Antialiased Line Vertex Shader * * For thick lines with proper antialiasing, we need to expand * lines into quads and compute distance from line center. */ export declare const lineAAVertexShader = "\nprecision highp float;\n\nattribute vec2 position;\nattribute vec2 normal; // Perpendicular to line direction\nattribute float miter; // Miter length for joins\n\nuniform vec2 uScale;\nuniform vec2 uTranslate;\nuniform vec2 uResolution;\nuniform float uLineWidth;\n\nvarying vec2 vNormal;\nvarying float vLineWidth;\n\nvoid main() {\n // Transform position\n vec2 pos = position * uScale + uTranslate;\n\n // Convert to screen space for line width calculation\n vec2 screenPos = (pos * 0.5 + 0.5) * uResolution;\n\n // Offset by line width in screen space\n float halfWidth = uLineWidth * 0.5;\n screenPos += normal * halfWidth * miter;\n\n // Convert back to clip space\n pos = (screenPos / uResolution) * 2.0 - 1.0;\n\n gl_Position = vec4(pos, 0.0, 1.0);\n\n vNormal = normal;\n vLineWidth = uLineWidth;\n}\n"; /** * Antialiased Line Fragment Shader * * Uses distance-based antialiasing for smooth edges. */ export declare const lineAAFragmentShader = "\nprecision highp float;\n\nuniform vec4 uColor;\nuniform float uLineWidth;\n\nvarying vec2 vNormal;\nvarying float vLineWidth;\n\nvoid main() {\n // Distance from line center (0 at center, 1 at edge)\n float dist = length(vNormal);\n\n // Smooth step for antialiasing\n float aa = 1.0 / uLineWidth;\n float alpha = 1.0 - smoothstep(1.0 - aa, 1.0, dist);\n\n gl_FragColor = vec4(uColor.rgb, uColor.a * alpha);\n}\n"; /** * Point/Scatter Vertex Shader * * Renders data points as squares/circles. */ export declare const pointVertexShader = "\nprecision highp float;\n\nattribute vec2 position;\n\nuniform vec2 uScale;\nuniform vec2 uTranslate;\nuniform float uPointSize;\n\nvoid main() {\n vec2 pos = position * uScale + uTranslate;\n gl_Position = vec4(pos, 0.0, 1.0);\n gl_PointSize = uPointSize;\n}\n"; /** * Point/Scatter Fragment Shader * * Renders circular points with smooth edges. */ export declare const pointFragmentShader = "\nprecision highp float;\n\nuniform vec4 uColor;\n\nvoid main() {\n // Distance from point center\n vec2 coord = gl_PointCoord - vec2(0.5);\n float dist = length(coord);\n\n // Discard outside circle\n if (dist > 0.5) discard;\n\n // Smooth edge\n float alpha = 1.0 - smoothstep(0.4, 0.5, dist);\n\n gl_FragColor = vec4(uColor.rgb, uColor.a * alpha);\n}\n"; /** * Heatmap Vertex Shader (for future density plots) */ export declare const heatmapVertexShader = "\nprecision highp float;\n\nattribute vec2 position;\nattribute float value;\n\nuniform vec2 uScale;\nuniform vec2 uTranslate;\n\nvarying float vValue;\n\nvoid main() {\n vec2 pos = position * uScale + uTranslate;\n gl_Position = vec4(pos, 0.0, 1.0);\n vValue = value;\n}\n"; /** * Heatmap Fragment Shader * * Maps values to colors using a colormap. */ export declare const heatmapFragmentShader = "\nprecision highp float;\n\nuniform float uMinValue;\nuniform float uMaxValue;\nuniform sampler2D uColormap;\n\nvarying float vValue;\n\nvoid main() {\n float normalized = (vValue - uMinValue) / (uMaxValue - uMinValue);\n normalized = clamp(normalized, 0.0, 1.0);\n\n vec4 color = texture2D(uColormap, vec2(normalized, 0.5));\n gl_FragColor = color;\n}\n"; /** * Bar Chart Vertex Shader * * Renders rectangular bars using quad primitives. */ export declare const barVertexShader = "\nprecision highp float;\n\n// Attributes\nattribute vec2 position; // Corner position of bar quad [x, y]\nattribute vec2 barData; // [barX, barY] - center and height of bar\n\n// Uniforms\nuniform vec2 uScale;\nuniform vec2 uTranslate;\nuniform float uBarWidth; // Width of bars in data units\n\nvoid main() {\n // Calculate bar corner in data space\n float halfWidth = uBarWidth * 0.5;\n vec2 dataPos = vec2(\n barData.x + position.x * halfWidth, // X: center \u00B1 halfWidth\n position.y * barData.y // Y: 0 to barY\n );\n \n // Transform to clip space\n vec2 clipPos = dataPos * uScale + uTranslate;\n gl_Position = vec4(clipPos, 0.0, 1.0);\n}\n"; export declare const barFragmentShader = "\nprecision highp float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n"; export declare const Shaders: { line: { vertex: string; fragment: string; }; lineAA: { vertex: string; fragment: string; }; point: { vertex: string; fragment: string; }; bar: { vertex: string; fragment: string; }; heatmap: { vertex: string; fragment: string; }; };