Dotted trailing edges of the object.

In my Android app, I need to display a 3D object (this is not a problem), but the leading edges should be solid and the trailing edges should be dashed. I need something like this in the picture. How can I achieve this with OpenGL ES 1 or 2?

I tried Tim's idea (using depth buffer). It works, but there are some artifacts, as in the pictures, the dashed (purple) lines overlap the solid (red) lines:

enter image description hereenter image description here

This is because the dashed lines (purple (GL_GREATER)) are drawn AFTER the red lines (GL_LEQUAL). Are there any ideas on how to prevent this?

Thank you all for your help. Now it looks great !! enter image description here

+8
android opengl-es
source share
1 answer

Here is a rough outline of what I will do. You will need one grid for the object itself and another GL_LINES grid for the "boundary lines" that you want to draw.

  • Draw a solid grid into the depth buffer.
  • Draw your β€œedge grid” with the standard shader so you get solid lines, but set the depth to GL_LEQUAL (just draw objects closer than the depth value).
  • Draw your edge mesh a second time using the GL_GREATER depth test. In this passage, use a shader shader to get a dashed line effect (explained below).

This can have problems depending on what other objects are in the scene, as you can get dashed lines drawn when the cube is obscured by something else, but maybe this is not a problem for you, or you can somehow discard the mesh if it is shaded.

For a shader shader, you can set the texcoord of one vertex of the line to zero, and the other endpoint of the line to one. Then, in your shader, you can use a step function similar to the one suggested by tencent to drop fragments to create a template template.

You can also skip messing with the depth buffer if you want to calculate which lines are behind the object, although this can be a lot of work with something larger than a cube.

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

+2
source share

All Articles