Hi, probably the question should go to another board, but it is too technical, so I put it here within the dev forum.
I trying to convert a solid geometry to wireframe, filtering the edges and applying some thickness to them in geometry shader:
It seems to work as expected, however if I come with the camera closer to the thick lines, some of the triangles are clipped completely:
(notice the missing 2 triangles from the violet thick lines)
It is surely related to the generated z-values of the triangles, but with the camera seeing all the boxes, the z-buffer works correctly (resolving the visibility as expected). In the geometry shader I compute the positions of vertices for the thick line with following code snippet:
Code: Select all
// take projected positions
const float4 p0 = input[i0].position;
const float4 p1 = input[i1].position;
// uv axis of the edge after projecting the vertices - u is along the edge, v is perpendicular to the edge
const float4 u = float4(normalize(p1.xy / p1.w - p0.xy / p0.w), 0, 0);
const float4 v = float4(-u.y, u.x, 0, 0);
// main line segment body
emitVertexData(output, p0 + v * r0, float4(d0, halfw, d0, d1), drawId);
emitVertexData(output, p0 - v * r0, float4(d0, -halfw, d0, d1), drawId);
emitVertexData(output, p1 + v * r1, float4(d1, halfw, d0, d1), drawId);
emitVertexData(output, p1 - v * r1, float4(d1, -halfw, d0, d1), drawId);
output.RestartStrip();
The emitVertexData outputs the second parameter as position of the vertex. The p0 and p1 are actually the transformed positions of the vertices with model-view-projection matrix and as you can see, the v vector has both z and w values set to 0.0 so the output z and w values are the same for the whole triangle as for the particular line. I expect that the triangles should be clipped per pixel basis and not as whole.
Is there any setting in Ogre to influence the clipping? Note that I copied the code from my othe OpenGL application (which doesn't use Ogre) and there I don't see such strange clipping. The same behavior is actually with both Ogre renderers - GL3Plus and D3D11.
Just for completeness, here is the screenshot from another app which shows the expected clipping by near clip plane. but still showing both triangles of a thick edge of the box: