Interactive 2D WebGL 2 Optical Bench, Astronomical Telescope Simulator & Physics Engine.
Language: EN | TR • ✦ Live Simulation (GitHub Pages) · optical.hfatih.com · Overview · Telescope Suite · Physics Engine · How It Works · Controls
Optical Bench (Işık Masası) is a real-time, browser-native 2D optical physics simulation and telescope laboratory built with pure WebGL 2 and Vanilla JavaScript (zero external dependencies).
It pairs high-speed GPU accelerated ray tracing with physically rigorous 2D optics:
-
Snell-Descartes Refraction & Cauchy Dispersion: Prisms split white light into continuous rainbow spectra with wavelength-dependent refractive indices (
$380\text{ nm} - 750\text{ nm}$ ). - Total Internal Reflection & Fresnel Splitting: Glass blocks, D-blocks, and multifaceted brilliant-cut diamonds exhibit realistic critical-angle reflection and internal ray bouncing.
- Full Astronomical Telescope Suite: Real-time simulation of 8 telescope designs (Kepler, Galileo, Newton, Cassegrain with primary central baffle holes, Maksutov-Cassegrain, Schmidt-Cassegrain, Gregorian, and Beam Expanders) with live HUD telemetry.
- Thin-Film Interference: Soap bubbles calculate optical path phase differences to render iridescent rainbow surface colors.
-
Scale-Invariant Camera: Smooth pan and zoom (
$15% - 350%$ ). Physical optical metrics and refraction angles remain strictly invariant down to$10^{-7}\text{ rad}$ regardless of zoom depth. - Starlit Cosmic Dark UI: Crafted in the signature Starlit aesthetic (#150a14 cosmic obsidian plum, #f0abc5 celestial rose, translucent glass cards, and 4-point sparkle stars ✦).
The simulator includes a dedicated astronomical optics engine with a real-time HUD telemetry card displaying angular magnification (
| Telescope Type | Optical Architecture | Key Formulation | Optical Characteristics |
|---|---|---|---|
| Kepler Refractor | Convex Objective + Convex Eyepiece | Inverted real intermediate image; wide field of view; chromatic dispersion present. | |
| Galileo Refractor | Convex Objective + Concave Eyepiece | Upright direct image; ultra-compact tube; narrower apparent field of view. | |
| Newtonian Reflector | Parabolic Concave Primary + |
100% achromatic (zero chromatic aberration); |
|
| Classical Cassegrain | Perforated Concave Primary (Aperture Hole) + Convex Secondary | Light passes back through primary mirror's central baffle hole; folded compact optical train. | |
| Maksutov-Cassegrain (Mak) | Deep Spherical Meniscus Corrector + Silvered Spot Secondary | Corrects spherical aberration via all-spherical surfaces | Highly sealed tube; rugged thermal stability; razor-sharp planetary contrast. |
| Schmidt-Cassegrain (SCT) | Thin Aspheric Schmidt Plate + |
Large focal length in an ultra-short chassis | Folded |
| Gregorian Reflector | Concave Primary + Concave Secondary past Primary Focus | Naturally upright image without erecting prisms; historical astronomical design. | |
| Beam Expander | Reversed Keplerian / Galilean Collimator | Magnification |
Expands laser beam diameter and decreases beam divergence. |
[ Incident Ray ]
│
▼
────────────────── Boundary ───────────────────
│ │
[ Reflected Ray (Fresnel) ] [ Refracted Ray (Snell) ]
R = Fresnel(θ, n₁, n₂) n₁ sin θ₁ = n₂ sin θ₂
│
▼
[ Cauchy Dispersion ]
n(λ) = n₀ + B / λ²
For every boundary interface between media of refractive indices
Refractive materials (Crown glass, Flint glass, Diamond, Water) apply Cauchy's dispersion formula:
Unpolarized light splits at optical boundaries based on the Fresnel equations:
For soap bubbles and optical coatings of thickness
Unlike naive canvas implementations that scale ray calculations with screen pixels, this physics engine separates world coordinates from camera viewport transforms. Intrinsic optical properties (
flowchart TD
subgraph UI["User Interface & Canvas"]
EV["Mouse & Touch Events<br/>Pan, Zoom, Drag, Rotate"]
HUD["Telescope HUD & Inspector<br/>Real-time Optical Telemetry"]
PAL["Starlit Component Dock<br/>Light, Glass, Mirrors, Sensors"]
end
subgraph Core["Simulation Core (js/scene.js, js/trace.js)"]
STATE["Scene Graph<br/>Lenses, Mirrors, Prisms, Sources"]
CAM["Viewport Transform<br/>Scale-Invariant World Matrix"]
BVH["Bounding & Geometry Tests<br/>Arcs, Segments, Apertures"]
RAY["Recursive Ray Tracing<br/>Snell, Fresnel, TIR, Dispersion"]
end
subgraph Render["Render Pipeline (WebGL 2 & 2D Overlay)"]
GL["WebGL 2 Shaders<br/>Additive Spectral Bloom & Glow"]
OVR["2D Canvas Overlay<br/>Normals, Angles, Focal Points"]
end
EV --> CAM
PAL --> STATE
STATE --> BVH
CAM --> BVH
BVH --> RAY
RAY --> GL
RAY --> OVR
RAY --> HUD
| Action | Control | Description |
|---|---|---|
| Pan Canvas |
Left Click + Drag on empty space |
Move the entire optical bench seamlessly |
| Zoom View |
Mouse Wheel on empty space |
Smooth zoom from |
| Center Scene |
Double Click or ✦ Center button |
Center and frame all components into view |
| Move Component |
Left Click + Drag component |
Reposition any optical element on the table |
| Rotate Component |
Shift + Mouse Wheel or Drag Rotate Handle |
Rotate selected element with degree snapping |
| Duplicate Component |
Ctrl + D or Alt + Drag
|
Clone component with all optical parameters preserved |
| Delete Component |
Delete or Backspace
|
Remove selected component from the bench |
| Toggle HUD / Telemetry | Click telescope preset button | Displays live focal analysis and optical formulas |
| Toggle Normals | Top-Right Normal Line button |
Shows surface normal vectors and angles ( |
| Toggle Focal Points | Top-Right Focal (F) button |
Highlights theoretical focal points ( |
| Snapshot | Top-Right Camera button |
Captures high-resolution PNG image of the setup |
-
Single Laser: Monochromatic coherent beam with tunable wavelength (
$380\text{ nm} - 750\text{ nm}$ ) and power. - Multibeam (Ray Box): 5 parallel equidistant rays for demonstrating lens refraction and mirror focal points.
- White Beam: Broad collimated white light beam for prism dispersion experiments.
- Point Source: Omnidirectional or fan-shaped divergent point emitter.
-
Equilateral Prism:
$60^\circ$ dispersive prism for rainbow splitting. -
Right-Angle (Porro) Prism:
$45^\circ-90^\circ-45^\circ$ prism for$90^\circ$ and$180^\circ$ Total Internal Reflection. - Biconvex / Biconcave Lens: Adjustable focal length, aperture radius, and glass substrate (Crown / Flint).
- Plano-Convex Lens: Asymmetric spherical lens element.
- Glass Block: Rectangular optical slab demonstrating parallel lateral beam displacement.
-
D-Block (Semi-Circular): Classic bench tool for verifying Snell's Law and measuring critical angle
$\theta_c$ . -
Diamond: Multi-faceted brilliant cut diamond showcasing high refractive index (
$n=2.42$ ) and sparkling internal bounces. - Soap Bubble: Thin-film spherical membrane exhibiting interference fringes.
-
Flat Mirror:
$100%$ specular reflection line segment. -
Concave Mirror: Spherical/parabolic focusing mirror (
$f = R / 2$ ). - Convex Mirror: Diverging reflective mirror.
-
Beam Splitter:
$50/50$ semitransparent dielectric coating.
- Observation Screen: Opaque detector plate showing incident beam spots and spectral distributions.
- Slit Aperture: Variable width barrier for controlling beam width.
- Optical Sensor: Real-time photometer measuring incident spectral power.
- 360° Protractor: Overlay angular measurement tool.
- Metric Ruler: Calibrated scale for measuring focal distances.
The project requires no build step, no npm install, and no external dependencies. Run it with any standard HTTP server or open directly in a modern WebGL 2 capable browser.
# Clone the repository
git clone https://github.com/Hfatih/optical-bench.git
cd optical-bench
# Start local server (Python 3)
python -m http.server 8080Open http://localhost:8080 in your browser.
npx serve .Right-click index.html and select "Open with Live Server".
The project includes an automated, zero-dependency Node.js verification test bench (test-bench.js) verifying all 11 core optical physics and navigation invariants:
node test-bench.js-
Material Indices & Wavelengths: Cauchy coefficients for Crown (
$n_d = 1.517$ ) and Flint ($n_d = 1.620$ ) glass; spectrum labeling ($532\text{ nm}$ Green,$633\text{ nm}$ Red). - Preset Verification: All 18 optical presets (including all 8 telescopes) spawn valid geometry and generate active ray segments.
- Single-Spawn Click Guard: Prevents duplicate component generation on a single click.
- Camera Navigation: World coordinate transformation and scene centering invariants.
-
Zoom Boundaries: Deep zoom validation down to
$15% - 20%$ zoom levels. -
Component Duplication: Deep cloning with exact geometric parameter preservation (
mlen,refl, etc.). - Pick Tolerance: Graceful selection tolerance for thin mirrors and delicate optical surfaces.
- Item Lifecycle: Clean deletion and dynamic state subscriber firing.
- Preset Cleanliness: Verifies absence of redundant observation screens in telescope and refraction experiments.
-
Refraction & Zoom Scale Invariance: Snell's law refraction angles remain invariant across zooms (
$15%$ to$350%$ ) with error$< 10^{-7}\text{ rad}$ . - Cassegrain Central Hole Ray Tracing: Perforated primary mirror geometry verification and optical throughput through the central baffle hole.
optical-bench/
├── index.html # Main application structure, HUD telemetry & dock
├── style.css # Starlit design system, glass cards & CSS layout
├── test-bench.js # Zero-dependency automated test suite (11/11 tests)
├── docs/
│ └── images/
│ └── logo.svg # Starlit vector brand logo
├── js/
│ ├── spectrum.js # Wavelength to RGB conversion & Cauchy dispersion
│ ├── scene.js # Scene state graph, optical geometries & telescope setups
│ ├── trace.js # 2D optical ray tracing engine (Snell, TIR, Fresnel)
│ ├── glass.js # Refractive polygons & arc boundary intersections
│ ├── gl.js # WebGL 2 shader pipeline & additive glow effects
│ ├── ui.js # Canvas interactions, HUD telemetry, dock & camera
│ └── main.js # Application bootstrap & animation loop
└── LICENSE # GNU GPL v3.0
Released under the GNU GPL v3.0.
Developed with ✦ by Fatih Han.
Project-owned code and original material in this revision are licensed under GNU GPL v3.0 (GPL-3.0-only). Third-party code, fonts, imagery, data, and brand assets retain their own terms and attributions. Previous license and copyright notice.