Voxelers / mcthings

A Python framework for creating 3D scenes in Minecraft and Minetest
Apache License 2.0
59 stars 11 forks source link

Research Ray Tracing #127

Open acs opened 4 years ago

acs commented 4 years ago

OpenGL is for rastering, so, what about ray tracing? AMD implement it using shaders (GLSL?)

For voxels, ray tracing is the way to go to render with solid internals reflected?

https://github.com/dannyfritz/awesome-ray-tracing

APIs: https://github.com/dannyfritz/awesome-ray-tracing#apis

http://www.realtimerendering.com/ Several books about Ray Tracing. I will take a look to find the most interesting one for leaning.

Hardware implementing it:

acs commented 4 years ago

http://raytracey.blogspot.com/2008/08/voxel-ray-tracing-vs-polygon-ray.html (2008): Voxels and ray tracing vs polys

acs commented 4 years ago

http://www.realtimerendering.com/raytracinggems/ Advanced Ray Tracing, but with introductory chapters, slides, videos ... and pretty recent, from 2019. Let's take a look. https://developer.nvidia.com/video/GDC-19/RAYTRACINGGEMS Too much advanced yet I have read now all slides and I can understand now a good portion of the contents. Advancing!

acs commented 4 years ago

I would love to follow this one, but I need to recover my C++ skills and I need a full weekend: https://github.com/RayTracing/raytracing.github.io Right now, I want to understand the key elements in Ray Tracing.

acs commented 4 years ago

Let's try this one: http://www.realtimerendering.com/raytracing/An-Introduction-to-Ray-Tracing-The-Morgan-Kaufmann-Series-in-Computer-Graphics-.pdf

It is the original one from 1989. But it has been updated in 2019 to the 1.3 version. And it is CC-by.

«This book is a revised and edited version of reference material prepared for an intensive one-day course on ray tracing» So probably it is whay I am looking for now!

I am reading this book and at least, the introduction chapter, it is what I was searching for.

acs commented 4 years ago

Some links to check:

acs commented 4 years ago

A python ray tracer engine: https://gist.github.com/rossant/6046463 evolved in https://excamera.com/sphinx/article-ray.html to a speedier one: https://github.com/jamesbowman/raytrace

https://github.com/martinchristen/pyRT for learning ray tracing with Python

javiercuervo commented 4 years ago

Some links to check:

A podcast episode https://blog.siggraph.org/2020/06/siggraph-spotlight-episode-35-real-time-ray-tracing-realism.html/

acs commented 4 years ago

Ok, let's focus in https://excamera.com/sphinx/article-ray.html to test the ray tracer and maybe, create our own version.

Forked at: https://github.com/acs/raytrace

Let's start with the slower and simpler version: https://gist.github.com/rossant/6046463 Which in the repository is https://github.com/acs/raytrace/blob/master/raytracing.py

acs commented 4 years ago

In order to understand ray tracing and to implement it, it is key to understand the different types of lights that exist:

https://www.iu.edu.jo/files/FacultyIT/slides_it/ComputerGraphics/lecture%207.pdf

In the ray tracer sample, the last three are used. The objects don't emit light in this scene (and in general).

It seems that in the example, the https://en.wikipedia.org/wiki/Phong_reflection_model is used to describe how light is reflected in the objects. So how the objects appears in the scene.

The key logic is how the color of each pixel is defined:

    # Start computing the color.
    col_ray = ambient
    # Lambert shading (diffuse).
    col_ray += obj.get('diffuse_c', diffuse_c) * max(np.dot(N, toL), 0) * color
    # Blinn-Phong shading (specular).
    col_ray += obj.get('specular_c', specular_c) * max(np.dot(N, normalize(toL + toO)), 0) ** specular_k * color_light

And it is pretty natural: the color of each pixels is the sum of ambient light, diffuse light and specular light. Ambient is the same for all visible voxels of the scene. But diffuse and specular are computed using two algorithms.

So for each ray hitting a voxel we compute its color using this method.

acs commented 4 years ago

A pretty cool introduction, with a good balance between introducing basic concepts and explaining the whole thing: https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-ray-tracing/adding-reflection-and-refraction (at least for my current vision of ray tracing).

And https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection describe a minimal ray tracer!

acs commented 4 years ago

Visual Ray Tracing algorithm: https://developer.download.nvidia.com/video/GDC-19/RAYTRACINGGEMS_Haines.pdf

Screenshot from 2020-08-02 10-24-29