Picking up on the long neglected rewrite of my graphics library, and I know I'd kind of left it in a very unfinished state, but I'd forgotten how much had been left out. Today I updated the ray tracing implementation. Next up are boolean operations
Got booleans working again and cranked up the rays. Looks like we're got a few escaping containment and a few missing from the emitters.
The cool part about everything being a vector is I can open it up and inspect all the layers and elements to see exactly what's going on
Something very strange is going on with my Angle type. While looking into the missing rays I changed the underlying value used for math on angles from degrees to radians, which caused my boolean operation to invert?

I figured out the reason some rays are missing, and it's not related to the angles like I'd been thinking. A quirk of how I implemented the rays is they don't draw if they don't "project" onto an object, and it looks like the some raysfail to find an intersection with the bounding box.

This explains both the missing rays and the rays that project past the box onto the circle outside.

However I don't know why the intersection math fails sometimes.

Figured it out, sort of. When testing whether a ray intersects with a rectangle I'm checking the four edges, which is technically checking whether the ray intersects with a place defined by the line and I'm discarding it if the point isn't on the line. Seems like sometimes I get a false negative and the point is being rejected

Ok, we're getting there. Instead of checking if an intersection is on the line I'm running a distance check that returns nil if they don't intersect. The good news is I'm not getting false negatives anymore. The downside is I think I figured out why the check was failing. Sometimes the intersection function returns a point in the right direction, but thousands of pixels outside the rectangle.

The rectangle seems to work, but going through the fresnel is causing problems

One other weird thing, that probably isn't helping, is that while the distance function is correctly filtering rays, it always returns 0 or -0, rather than you know, an actual distance
If you take the cross product of the a vector and itself you always get zero, so that's been fixed. I also replaced the intersection calculation by using correctly calculated distance to project the vector onto the surface which appears to be working perfectly.
Some of this is a little silly, because I had previously implemented all of this before, though I now suspect some of the math was a little wonky then, too. The only obvious difference is the little rectangle: it's rotated, something the old version didn't support.
@emorydunn
Is any of this code available? I’m trying to achieve something similar but would love to see how you generate these awesome looking images!

@jippoe The library is available on GitHub. All of these were made with the SwiftGraphics2 branch, though it’s a bit of a work in progress and I expect a lot to change. Happy to help you get it up and running

https://github.com/emorydunn/SwiftGraphics

GitHub - emorydunn/SwiftGraphics: SwiftGraphics is a library for creative coding and generative art tailored towards rendering SVGs meant for pen plotting.

SwiftGraphics is a library for creative coding and generative art tailored towards rendering SVGs meant for pen plotting. - emorydunn/SwiftGraphics

GitHub
@emorydunn following because obviously. What’re you writing this in?
@everyplace Haha, I'm here to entertain. I'm writing it all in Swift. My own little vector graphics library, originally for pen plotting

@emorydunn have you watched Sebastian Lague’s amazingly well presented ray tracing videos?

https://youtube.com/playlist?list=PLFt_AvWsXl0dlgwe4JQ0oZuleqOTjmox3&si=M2jcw_f3WwcJAuA5

Ray Tracing

Shooting some rays and trying to render all sorts of things

YouTube
@Hexagonal The thumbnail looks really familiar, so I think I've come across it, but I'm not sure I've actually watched it. I'll add that to my queue