Ogre Version: ogre-next 3.0
Operating System: Windows
Render System: D3D11
Does anybody know how to calculate pixel position of the vertex outside the frustum? Let's say I have a line rendered with perspective camera and I would like to calculate its length in pixels. If both vertices are visible, then simple multiplication with projection matrix + applying the RT resolution yield the desired values (example as in HLSL):
Code: Select all
float4 p0proj = mul(p0, worldViewProjMatrix);
float4 p1proj = mul(p1, worldViewProjMatrix);
float2 p0screen = (p0proj.xy / p0proj.w + float2(1, 1)) * 0.5 * float2(screenWidth, screenHeight);
float2 p1screen = (p1proj.xy / p1proj.w + float2(1, 1)) * 0.5 * float2(screenWidth, screenHeight);
float lineLength = length(p1screen - p0screen);
But the code above gives incorrect results if one of the vertices is clipped by near plane.
As one solution, it is possible to clip the line manually and calculate only the length of visible line segment, but I would like to avoid this manual clipping and rather calculate size of the whole line and let the interpolation on GPU. Is there any trick with projection matrix?