JayC
JayC

Reputation: 169

opengl ray tracing and mesh

I was able to get a starter code for a ray tracer online and the starter code has two "Geometries":

class sphere

class triangle

I understand the triangle since the code creates a mesh using triangles and gets the intersection between triangles and ray from each pixel. But how does sphere come into play?

So I've done some online researching and a lot of them discuss about triangle intersection and sphere intersection. but how do we use sphere in mesh?

Upvotes: 1

Views: 1043

Answers (1)

Good Luck
Good Luck

Reputation: 1102

A mesh is a collection of triangles and to render that object using ray tracing, you have to solve lots of ray tracing equations with all the triangles. However, a sphere has a closed form implicit function for which solving the ray intersection is very easy. These two sample object are coming from the fact that we have two ways of representing objects in computer graphics, implicit objects for which we have a closed form implicit functions and polygonal mesh representation for which we have a collection of triangles. Usually, in ray tracing, we have objects such as sphere, cylinder, plane (triangle), and torus for which we have a closed form function and we can find their intersection with rays. For complicated objects like bunny, ray is casted and intersected with a collection of planes (triangles).

Upvotes: 1

Related Questions