I’m currently working on rendering a mesh with a wireframe drawing. This is done by setting barycentric coordinates to the geometry’s vertices attributes and use them in the fragment shader. That works pretty well.
You can see it there
ForgeJS Media Grid
The problem I face is the wireframe appears brighter when zooming out, as the lines get nearer. So my idea is to get the depth of the vertices to decrease brightness depending on this parameter.
I’ve spend some time to play with the depthBuffer of a render target, especially with https://threejs.org/examples/#webgl_depth_texture. There are 2 draw passes. The first to render the objects, the second to display the depth from the depth texture in a quad/ortho camera.
I need to access depth in the same pass as I draw the geometry, in my fragment shader. Anyone knows I can achieve that?