# Showcase WIP advanced Raytracing library

Most of it is written in JS, boosting the performance by a lot.
I will make it public after rewriting more of it and creating a render function to render an entire scene.

Current state
Need to add support for materials and shadows by allowing people to get which object it hit.
Has light functions now though!

Amazing job! I wish I could make stuff like this!

Now with rotation matrices!

Also source code... lel

If you want to toy around with it, here is the release! Keep in mind that I will always change things and update them all the time. The way that shapes work is that they use something called Signed Distance Fields to calculate the minimum radius between the point and the object (the largest radius before intersection happens).

Take a look at the sphere or cube functions if you want an example on how to translate the functions from the page into Snap! code or JavaScript.
Also, make very sure to use the [Initialize Datatypes] block (preferably at the beginning of the script). It will create new global types like Vector3 and RotationMatrix that can be used both in JavaScript and allow its use in Snap! blocks.
After the block runs, things like (vector x: (0) y: (0) z: (0)) should now work and so should something like
(call (JavaScript function [] (return new Vector3(0,0,0)) ) )

This library will be fairly slow, use the quality level to change the Resolution Scale. Higher quality values result in more pixels being drawn on screen. The raycast mode doesn't make too much of a difference in speed, however. If you have any questions about the library or its functions, feel free to ask me as well.

Project:

Perhaps someone with any raymarching knowledge will be able to help me with a problem I have been having with the shadows mode though? I have this weird effect where shadows casted on the object themselves look a bit iffy and also have this aura around them. I based my equations on existing shaders and some online documentation.

This should be persistent with the current version of the project I have uploaded.

Wow, that is just amazing. Keep up the good work!

Thanks @legoman3.14 and if any of you use this to make some cool shapes and renders, feel free to share results in here as well!

Pro tip: you can actually add any reporter block to the map, but it needs to be ringified and accept a vector for the current position. You can use JavaScript for it too using vec1.add(vec2) for example in place of vec1 + vec2. Check the sphere and Initialize Datatypes blocks for a good reference.

There is a huge list of functions here in case you are interested and want to make some whacky shapes or just see how my shapes function. (This is a good explanation and guide, they work by returning the largest distance from the current position before it collides / intersects the shape)
An infinite plane for example would just be pos.y - offset as the results will be close to 0 as the y value approaches the offset.

As far as how lights go, currently, you return a list with ringified solution to the color the object will receive and the direction of the light. More lights can multiply the time it takes to render though!