I'm having difficulties rendering just a single pixel which is on the defined coords of viewport. I'm using D3DXMatrixPerspectiveOffCenter function, but the result is not what I expected.

Here is how I calculate the parameters for the function:

// pCamera is the actual camera used to render full screen picture

// what is the width and height of camera near plane in Camera Space
double dHeight = 2 * pCamera->m_dNear * (tan(pCamera->m_dFOVy/2.0)); 
double dWidth  = dHeight * pCamera->m_dRatioXY;

// what is the pixel size in Camera space
double dHeightReduced = (dHeight / pCamera->m_dViewportHeight) * CAMERA_1x1px_SIZE;
double dWidthReduced = (dWidth / pCamera->m_dViewportWidth) * CAMERA_1x1px_SIZE;

// mouse pixel position in Camera space
double dCamSpaceX = -0.5*dWidth  + double(uiMousePosX) / pCamera->m_dViewportWidth    * dWidth;
double dCamSpaceY = -0.5*dHeight + double(uiMousePosY) / pCamera->m_dViewportHeight   * dHeight;

// create matrix
D3DXMatrixPerspectiveOffCenterRH( &m_mProjection,
         (float)m_dFar );

(I set CAMERA_1x1px_SIZE = 100 to see a part of the scene, but I see the scene distorted and it's definitely NOT just the cut-off of the original)

How do I need to calc the params to make it work?



I am more into openGL, but I think its simpler to use Scissor test to clip part of the Framebuffer/render target plus I don't see any benefits from modifying the projection matrix (unless its a requirement to modify the projection matrix).

Keep in mind that scissor test and projection+viewport work on a different part of the pipeline, scissor test for instance is a fragment operation while projection+viewport matrix is not. You can also use stencil test which can be used if the area you want to mask is not rectangular. Performance wise I don't think the two methods are equivalent but you need to measure and decide.

  • 1
    \$\begingroup\$ +1 Use a scissor, or a viewport, this is a screen space operation. D3DXMatrixPerspectiveOffCenterRH is to create non-symmetric projections, it has nothing to do with limiting the output to a certain rectangle. \$\endgroup\$ – Laurent Couvidou Apr 18 '13 at 9:51
  • \$\begingroup\$ I've found some older code, that produces hi-res images via render target tiling. I though my problem is similar in some way. I've tried to adjust the older code to serve my purpose. So there must be a solution. \$\endgroup\$ – GPUquant Apr 18 '13 at 12:09
  • 3
    \$\begingroup\$ Using an off center projection matrix combined with a smaller viewport is a valid way to achive what you want and may result in a higher peformance as non-visible geometry gets clipped before the fragment shader is executed but scissor rects are far simpler to use. \$\endgroup\$ – Archy Apr 18 '13 at 13:56
  • \$\begingroup\$ Would somebody be so kind and explain the usage and setting of off center projection matrix in combination with viewport to me? \$\endgroup\$ – GPUquant May 3 '13 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.