如何在不切割网格几何体的情况下渲染横截面? [英] How to Render Cross Section without Slicing the Mesh Geometry?

查看:103
本文介绍了如何在不切割网格几何体的情况下渲染横截面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定世界上的一个切片平面,我希望看到三角形是否位于该平面的正侧,以及那些 与平面相交的部分被分割,也可以看到正平面上的部分.

Given a slice plane in the world, I want triangles to be seen if they were on the positive side of the plane, and those who intersect with the plane are split and the part on positive plane can be seen too.

如果每次更改平面时都对三角形网格进行切片,那么当有大量三角形时,它可能会非常慢,并且纹理坐标也会重新生成.

If I slice the triangles meshes every time when plane is changed, it may be very slow when there are tons of triangles, and texture coordinate will be re-generated too.

如果我仔细设置摄像机(视图)和投影,它可能会产生类似的结果,但是该结果取决于视图.

If I set the camera(view) and projection carefully, it may generate similar result, but this result is view dependent.

那么,是否有渲染技术可以利用GPU的裁剪结果来渲染独立于视图的横截面?

So, is there render techniques which can utilize clipping result from GPU to render the view independent cross section?

像这样的横截面:

推荐答案

使用着色器非常简单.在 Opengl/GLSL 中,您只需向片段着色器添加if语句即可确定片段是否位于飞机的正确侧面上,如果不是,则为discard.

using shaders is this really easy. In Opengl/GLSL you just add an if statement to fragment shader determining if your fragment is on the correct side of your plane and if not discard it.

这将根据您的情况切割您的对象,以便获得轮廓.但是,您仍然必须以某种方式在第二遍中从深度缓冲区或使用模板缓冲区来处理填充,但这两者都只是覆盖整个屏幕的单个GL_QUAD.

That will cut your object by your condition so you will get the contours. However you still have to handle the filling somehow possibly from depth buffer in second pass or by using stencil buffer but both are just single GL_QUAD covering whole screen.

执行此操作的数学运算很简单,您需要定义半角空格.我能想到的最简单的事情是:

The math to do this is simple you need to define your half space. The simplest thing I can think of is:


p0=(x0,y0,z0)-属于切割平面的3D点
n0=(nx,ny,nz)-垂直于切割平面,指向观察面的一面


p0=(x0,y0,z0) - 3D point belonging to cutting plane
n0=(nx,ny,nz) - normal to cutting plane pointing to wards viewed side

因此,如果,任何片段p=(x,y,z)都是可见的

dot_product(p-p0,n0) >= 0.0

如此

if (nx*(x-x0)+ny*(y-y0)+nz*(z-z0)<0.0f) discard;

不要忘记禁用GL_CULL_FACE并使用双面材料/照明.同样,所有坐标必须在同一坐标系中!!!

Do not forget to disable GL_CULL_FACE and using double sided matherials/lighting. Also all the coordinates must be in the same coordinate system !!!

这篇关于如何在不切割网格几何体的情况下渲染横截面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆