Snap Camera/Projection to Pixel Increments ?

Started by
3 comments, last by Endemoniada 8 years, 10 months ago

Hi guys,

I'm trying to snap my camera to one pixel increments. I sort of understand it except how to calculate fCascadeBound (see below), I don't know what that is.

I have an ortho projection matrix (XMMatrixOrthographicOffCenterLH) and a view matrix (XMMatrixLookAtLH).

Does anyone know how to do this ?

// The vWorldUnitsPerTexel value is calculated by taking a bound of the view frustum, and dividing by the buffer size.

FLOAT fWorldUnitsPerTexel = fCascadeBound / (float)m_CopyOfCascadeConfig.m_iBufferSize;
vWorldUnitsPerTexel = XMVectorSet(fWorldUnitsPerTexel, fWorldUnitsPerTexel, 0.0f, 0.0f);

// snap the camera to 1 pixel increments

vCameraOrthographicMin /= vWorldUnitsPerTexel;
vCameraOrthographicMin = XMVectorFloor(vCameraOrthographicMin);
vCameraOrthographicMin *= vWorldUnitsPerTexel;

vCameraOrthographicMax /= vWorldUnitsPerTexel;
vCameraOrthographicMax = XMVectorFloor(vCameraOrthographicMax);
vCameraOrthographicMax *= vWorldUnitsPerTexel;
 
D3DXMatrixOrthoOffCenterLH( &m_matShadowProj[ iCascadeIndex ],
 XMVectorGetX( vLightCameraOrthographicMin ),
 XMVectorGetX( vLightCameraOrthographicMax ),
 XMVectorGetY( vLightCameraOrthographicMin ),
 XMVectorGetY( vLightCameraOrthographicMax ),
 fNearPlane, fFarPlane );
 

Thanks.
Advertisement
fCascadeBound is the size of the projection in world units. If it is not a square projection then you need fCascadeBound.x and fCascadeBound.y to calculate vWorldUnitsPerTexel.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Hi L.,

Will you please be a little more specific. When you say "the size of the projection" do you mean the size of the frustum ? I'm sure I can learn how to get the eight points of the frustum (and convert them to world space) if I need to, do I then use those points to compute the size ? Any more info would be appreciated.

Thanks a lot.

You are using an orthographic projection. The size in world space is the size of the projection, which you have to know in order to create it.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Hey, I actually got it to work. Thanks a lot man.

This topic is closed to new replies.

Advertisement