简体   繁体   English

opengl射线追踪和网格

[英]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? 但是如何在网格中使用球体?

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). 对于像兔子这样的复杂物体,射线被投射并与一组平面(三角形)相交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM