Repository navigation
feat: add Ray Tracing simulation - #395
Merged
mattqdev merged 1 commit intoSep 25, 2026
Merged
Conversation
Add an interactive Whitted-style ray tracer that follows one ray of light from the camera into a 3D scene (sphere, ground plane, point light): - simulations/RayTracing.jsx: ray-traced image and a draggable side/top diagram side by side, with the followed ray's normal, shadow ray and reflected ray, plus live equations with the numbers substituted. The image is cached and re-traced progressively (quick preview, then an anti-aliased pass) only when the scene changes. Every input is guarded so typed values outside the slider ranges stay stable. - configs/RayTracing.js: camera/sphere/light/material controls and the sim-info readout. - chapters.js entry (undergraduate, also upper secondary), thumbnail, simulationOverviews entry, and a "ray-tracing" concept in curriculumTopics.js for the simulation and its article. - New article "How does ray tracing work?" linked as relatedBlogSlug. - createSimulation: expose setInput(name, value) in the hook context so dragging on the canvas can move sliders; documented in CLAUDE.md and the new-simulation skill. - Regenerated sitemap, routes, feed and llms files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@charlenenicer is attempting to deploy a commit to the PhysicsHub's projects Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
|
Hey @charlenenicer Thank you so much for this simulation! Really appreciate this |
Owner
|
🎉 This PR is included in version 3.35.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new Ray Tracing simulation (optics, University level) plus a theory article.
A real Whitted-style ray tracer renders a sphere on a checkered floor lit by a point light. The learner follows one ray at a time: click any pixel and every step the renderer took to colour it is shown with its live numbers:
The ray-traced image and a side/top diagram of the scene sit side by side. The camera, sphere and light can be dragged in the diagram (the sliders follow), and the diagram draws the followed ray with its normal, shadow ray (red when blocked) and reflected ray. Below the image, the equations are written out with the numbers substituted. Each line glows briefly when its value changes, so it's easy to see, for example, that moving the light leaves the ray, the intersection and the reflection angle untouched.
Files
simulations/RayTracing.jsxTrigonometricCircleit draws in pixel space fromdraw. The image is cached and re-traced progressively, only when the scene changes: a 1/4-resolution preview right away, then a 2×2 anti-aliased pass spread over a few frames once the scene has been still for 150 ms. This keeps dragging smooth. Every input is guarded insceneFrom, since slider bounds no longer limit typed values.app/(core)/data/configs/RayTracing.jsSimInfoMapperreadout.app/(core)/data/chapters.jslevel: "undergraduate",alsoFor: ["upperSecondary"],difficulty: "core", tags Optics / Vectors / Interactive.app/(core)/data/simulationOverviews.jsapp/(core)/data/articles/how-does-ray-tracing-work.jsnew-articlehouse style (key fact, takeaways, FAQ, "Keep exploring"). It is the sim'srelatedBlogSlug, so it shows first under "Recommended reading", with the sim thumbnail as its card image.app/(core)/data/curriculumTopics.jsray-tracingconcept, placed at undergraduate level in all six curricula with the senior-physics stage asalso(same pattern asthree-body/pi-collisions), plussim:RayTracingandblog:how-does-ray-tracing-workrows.public/thumbnails/ray-tracing.webpapp/(core)/engine/runtime/createSimulation.jsxCLAUDE.md,.claude/skills/new-simulation/SKILL.mdsetInputand the new precedent, as required for engine changes.routes.js,public/sitemap.xml,public/feed.xml,public/llms*.txtnpm run build.Engine change:
setInput(name, value)Dragging an object in the diagram is a parameter change, so the sliders must follow. The runtime had no way for a sketch to write an input back, so
createSimulationnow exposessetInput(name, value)in thebuildcontext and every hook context. It updatesinputsRefsynchronously, so the next frame already reads the new value throughinputs, then goes through the samehandleInputChangepath as the sliders. The change is additive, and no existing simulation is affected. The skill documents that it's for canvas gestures that are parameter changes, not for storing simulation state.✅ Checklist
npm run dev,npm run build: 56/56 pages generated, rebased on the latestmain)npx eslint .clean;prettier --checkis clean on every file this PR touches, see notes)CLAUDE.md,new-simulationskill, derivations in comments)🎨 Visual Changes (if UI-related)
ray-tracing-demo.mp4
Clip (20 s): the light is dragged behind the sphere and a floor pixel inside the shadow is followed (shadow ray turns red,$I_d = 0$ ). Then the sphere is moved, and the diagram switches to the top view while the camera swings around.
📂 Type of Change
Additional Notes for Reviewers
fov=180&shininess=-5&radius=0&reflectivity=3&intensity=-10&camY=-2: no NaN/Infinity in any readout and no errors.main.package-lock.jsononmainis currently out of sync withpackage.json(the@supabase/*packages andsemantic-releaseare missing, sonpm cifails). I installed with--no-package-lockand did not touch the lockfile.prettier --check .flags.claude/skills/new-article/SKILL.md,app/(core)/lib/community.tsandrelease.config.jsonmainitself; I left those alone to keep the PR focused.