Game Development Reference
In-Depth Information
Radial distortion can be corrected using the radial distortion correction from Brown's dis-
tortion model, of which we are only interested in the radial distortion, and can ignore the
tangential distortion component.
Where r is the radius of the distortion effect (from the center of the image), and k 0..n are
the radial distortion coefficients, which will be positive for barrel distortion and negative
for pincushion distortion.
The resulting radius r' is used to calculate the sample location in the render surface gener-
ated during rendering, this will result in pixels being pulled towards the center of the lens;
the amount of displacement will increase with the radius.
The distortion correction can be applied on the GPU using a pixel on the final image. This
means that to support the Rift, the game must be rendered into a render target which we
will then use to draw a quad onto the frame buffer using a pixel shader that performs the
distortion correction.
Thefollowingpseudocodeexplainstherenderingflownecessaryforarenderingagameon
the Rift.
SetRenderTarget(RT)
// Left eye
SetViewport(0, 0, HorizontalResolution / 2, VerticalResolution)
SetProjectionMatrix(LeftEyeProjection)
Render(RT)
// Right eye
SetViewport(HorizontalResolution / 2, 0, HorizontalResolution, VerticalResolution)
SetProjectionMatrix(RightEyeProjection)
Render(RT)
// Render screen quad using distortion correction pixel shader to frame buffer
T = SetTexture(RT)
SetPixelShader(DistortionCorrection)
DrawFullScreenQuad(T, fullscreen);
// Finished rendering, present the frame buffer
Present
Search WWH ::




Custom Search