after my original post was flagged as "too broad" by other stack overflow users. I will rephrase my question in less lines. I have implemented a ray marcher in shadertoy, and i understood all the math about the ray-object intersection. And i want to make the next step to ray trace with meshes. I found out that doing so needs to be done with deferred rendering and framebuffers(2 pass rendering, one for the geometry and the other for the lighting calculations, the ray tracing) and the intersections will happen with ray-triangle intersection.
Of course i will post some code in the next weeks as i will start implementing this. and i will need some specific help but till then i would appreciate the help in order to now waste time searching the web. This is why i posted here..
original post as it was flagged "too broad"
this is my first ever post to stack overflow. My goal is to write a ray tracer with mesh objects.
So far the only thing i have accomplished is make a ray tracer with spheres and planes. This is done with forward rendering, and while creating all the geometry in the fragment shader(which is easy to produce the spheres and the plane).
After all the research that i have made i finally found the solution. This is accomplished with deferred shading technique where you create the geometry and pass it to the G-buffer as a texture and then with the second pass you start the calculations for the lighting and the ray tracing.
I am seeking guidance cause i have spent many days/months(3-4) in order to come to this conclusion since i was not familiar with neither shaders nor the graphics libraries. My questions are the following:
1) Is this approach the correct one? 2) And second can someone guide me to the triangle intersections? By the term triangle intersections i don't mean the math and the procedure of ray-triangle intersection; i know about that. What i don't know is after the first intersection, how to check for the next collision, how to test the next triangle. In what way do i need to pass the vertexes in the G-buffer in order to traverse through them and check for intersections(some sample glsl code would be nice to understand)?
here are the links that i have read in order to come to that conclution
- https://www.opengl.org/discussion_boards/showthread.php/200487-Ray-intersection-with-GLSL
- https://www.imgtec.com/blog/five-steps-to-adding-ray-tracing-to-an-opengl-es-based-deferred-lighting-system/
- https://learnopengl.com/Advanced-Lighting/Deferred-Shading
- GPU PRO 6 book, page 351-368
If i missed any link in the stack overflow community please post them here.
I would appreciate any answer relative to the answer. Thank you in advance.
I'm also self thought, had a hard time starting. But it is very easy.
You need to pack your mesh data into an RGB(A) texture and then uppack it inside the fragment shader
some really good pfds on this technique, here is one example: http://www.cs.harvard.edu/~sjg/papers/gim.pdf
exampel of texture layout:
using RGB ( Alpha Channel can be used for meterial index )
CPU side:
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB32F, dataLenght/channels, 1, 0, gl.RGB, gl.FLOAT, meshVerts);
texImage2D reference
GPU side:
texelFetch(uMeshData, ivec2(vertIndex, 0), 0);
texelFetch reference
Some Resources/LINKS:
Written in C++ but actually the conversation is not that far away to an #version 300 es glsl shader:
scratchapixel
OpenGL Development Cookbook has some expampels reading obj to image to fragment
the source on github
i personaly think this is the best pathtracer on the web:
with me little knowledge i can see that this guy read the Physically Based Rendering book to the very end
here is really good tutorial to understand the concept of computer graphics
UPDATE/EDIT: Peter Shirleys Raytracing in a Weekend is free for download
my own little attempt