对象的后边缘 [英] Dotted back edges of object

查看:50
本文介绍了对象的后边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android 应用程序中,我需要显示一个 3D 对象(没问题),但前边缘应该是实心的,后边缘应该是虚线.我需要在图片上有类似的东西.如何使用 OpenGL ES 1 或 2 实现它?

In my Android app I need to display a 3D object (that's no problem), but the front edges should be solid and the back edges should be dotted. I need to have something like on the picture. How can I achieve it using OpenGL ES 1 or 2?

我尝试了 Tim 的想法(使用深度缓冲区).它有效,但有一些人工制品,例如图片,虚线(紫色)线与实线(红色)线重叠:

I have tried the Tim's idea(using Depth buffer). It works but there are some artefacts like on the pictures, dotted(purple) lines overlap solid(red) lines:

这是因为虚线(紫色(GL_GREATER))是在红线(GL_LEQUAL)之后绘制的.有什么办法可以预防吗?

It happens because dotted lines(purple colour(GL_GREATER)) are drawn AFTER red lines(GL_LEQUAL). It there any ideas how to prevent it?

谢谢大家的帮助.现在看起来很棒!!

Thank you everyone for helping. Now it looks great!!

推荐答案

这是我将要做的事情的粗略概述.您需要一个用于对象本身的网格,以及另一个用于要绘制的边缘线"的 GL_LINES 网格.

Here's a rough outline of what I would do. You'll need one mesh for the object itself, and another mesh of GL_LINES for the 'edge lines' that you want to draw.

  1. 将实体网格绘制到深度缓冲区中.
  2. 使用标准着色器绘制边缘网格",以获得实线,但将深度测试设置为 GL_LEQUAL(仅绘制比深度值更近的对象.
  3. 使用 GL_GREATER 的深度测试再次绘制边缘网格.在此过程中,使用点画着色器来获得虚线效果(在下面进一步解释).

这可能会出现问题,具体取决于场景中的其他对象,因为在立方体被其他物体遮挡的情况下,您可能会绘制虚线,但也许这对您来说不是问题,或者您可以以某种方式剔除网格(如果被遮挡).

This might have problems depending on what other objects are in the scene, as you might get dotted lines drawn in the case where the cube is obscured by something else, but maybe that's not a problem for you or you can somehow cull the mesh if it is obscured.

对于点画着色器,您可以将线的一个顶点的 texcoord 设置为零,将线的另一个端点的 texcoord 设置为 1.然后在您的着色器中,您可以使用类似于 tencent 建议的步进函数来拒绝片段以创建点画图案.

For the stipple shader, you can set a texcoord of one vertex of the line to be zero, and another endpoint of the line to be one. Then in your shader you can use a step function similar to suggested by tencent, to reject fragments to create a stipple pattern.

如果您想自己计算对象后面的线,您也可以跳过深度缓冲区的混乱,尽管这可能需要大量工作,而不仅仅是一个立方体.

You can also skip the messing with the depth buffer if you want to calculate yourself which lines are behind the object, though it could be a lot of work with anything more than a cube.

如果您想使用 OpenGLES 1 而不是 OpenGLES 2,请将点画着色器替换为点画图案的 1D 纹理,并使用该纹理对背线进行纹理处理.但是,我不能 100% 确定您可以在 OpenGL 中对线条进行纹理化,所以这可能行不通.

If you want to use OpenGLES 1 instead of OpenGLES 2, replace the stipple shader with a 1D texture of a stipple pattern, and texture the back lines with that. However I'm not 100% sure you can texture a line in OpenGL, so maybe this won't work.

这篇关于对象的后边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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