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.
Tim
source share