ovr_sdk

view LibOVR/Src/OVR_Stereo.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line source
1 /************************************************************************************
3 Filename : OVR_Stereo.h
4 Content : Stereo rendering functions
5 Created : November 30, 2013
6 Authors : Tom Fosyth
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 You may obtain a copy of the License at
17 http://www.oculusvr.com/licenses/LICENSE-3.2
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
25 *************************************************************************************/
27 #ifndef OVR_Stereo_h
28 #define OVR_Stereo_h
30 #include "Sensors/OVR_DeviceConstants.h"
31 #include "Displays/OVR_Display.h"
32 #include "OVR_Profile.h"
34 // CAPI Forward declaration.
35 typedef struct ovrFovPort_ ovrFovPort;
36 typedef struct ovrRecti_ ovrRecti;
38 namespace OVR {
40 class SensorDevice; // Opaque forward declaration
43 //-----------------------------------------------------------------------------------
44 // ***** Stereo Enumerations
46 // StereoEye specifies which eye we are rendering for; it is used to
47 // retrieve StereoEyeParams.
48 enum StereoEye
49 {
50 StereoEye_Center,
51 StereoEye_Left,
52 StereoEye_Right
53 };
56 //-----------------------------------------------------------------------------------
57 // ***** FovPort
59 // FovPort describes Field Of View (FOV) of a viewport.
60 // This class has values for up, down, left and right, stored in
61 // tangent of the angle units to simplify calculations.
62 //
63 // As an example, for a standard 90 degree vertical FOV, we would
64 // have: { UpTan = tan(90 degrees / 2), DownTan = tan(90 degrees / 2) }.
65 //
66 // CreateFromRadians/Degrees helper functions can be used to
67 // access FOV in different units.
69 struct FovPort
70 {
71 float UpTan;
72 float DownTan;
73 float LeftTan;
74 float RightTan;
76 FovPort ( float sideTan = 0.0f ) :
77 UpTan(sideTan), DownTan(sideTan), LeftTan(sideTan), RightTan(sideTan) { }
78 FovPort ( float u, float d, float l, float r ) :
79 UpTan(u), DownTan(d), LeftTan(l), RightTan(r) { }
81 // C-interop support: FovPort <-> ovrFovPort (implementation in OVR_CAPI.cpp).
82 FovPort(const ovrFovPort& src);
83 operator ovrFovPort () const;
85 static FovPort CreateFromRadians(float horizontalFov, float verticalFov)
86 {
87 FovPort result;
88 result.UpTan = tanf ( verticalFov * 0.5f );
89 result.DownTan = tanf ( verticalFov * 0.5f );
90 result.LeftTan = tanf ( horizontalFov * 0.5f );
91 result.RightTan = tanf ( horizontalFov * 0.5f );
92 return result;
93 }
95 static FovPort CreateFromDegrees(float horizontalFovDegrees,
96 float verticalFovDegrees)
97 {
98 return CreateFromRadians(DegreeToRad(horizontalFovDegrees),
99 DegreeToRad(verticalFovDegrees));
100 }
102 // Get Horizontal/Vertical components of Fov in radians.
103 float GetVerticalFovRadians() const { return atanf(UpTan) + atanf(DownTan); }
104 float GetHorizontalFovRadians() const { return atanf(LeftTan) + atanf(RightTan); }
105 // Get Horizontal/Vertical components of Fov in degrees.
106 float GetVerticalFovDegrees() const { return RadToDegree(GetVerticalFovRadians()); }
107 float GetHorizontalFovDegrees() const { return RadToDegree(GetHorizontalFovRadians()); }
109 // Compute maximum tangent value among all four sides.
110 float GetMaxSideTan() const
111 {
112 return Alg::Max(Alg::Max(UpTan, DownTan), Alg::Max(LeftTan, RightTan));
113 }
115 // Converts Fov Tan angle units to [-1,1] render target NDC space
116 Vector2f TanAngleToRendertargetNDC(Vector2f const &tanEyeAngle);
119 // Compute per-channel minimum and maximum of Fov.
120 static FovPort Min(const FovPort& a, const FovPort& b)
121 {
122 FovPort fov( Alg::Min( a.UpTan , b.UpTan ),
123 Alg::Min( a.DownTan , b.DownTan ),
124 Alg::Min( a.LeftTan , b.LeftTan ),
125 Alg::Min( a.RightTan, b.RightTan ) );
126 return fov;
127 }
129 static FovPort Max(const FovPort& a, const FovPort& b)
130 {
131 FovPort fov( Alg::Max( a.UpTan , b.UpTan ),
132 Alg::Max( a.DownTan , b.DownTan ),
133 Alg::Max( a.LeftTan , b.LeftTan ),
134 Alg::Max( a.RightTan, b.RightTan ) );
135 return fov;
136 }
137 };
140 //-----------------------------------------------------------------------------------
141 // ***** ScaleAndOffset
143 struct ScaleAndOffset2D
144 {
145 Vector2f Scale;
146 Vector2f Offset;
148 ScaleAndOffset2D(float sx = 0.0f, float sy = 0.0f, float ox = 0.0f, float oy = 0.0f)
149 : Scale(sx, sy), Offset(ox, oy)
150 { }
151 };
154 //-----------------------------------------------------------------------------------
155 // ***** Misc. utility functions.
157 // Inputs are 4 points (pFitX[0],pFitY[0]) through (pFitX[3],pFitY[3])
158 // Result is four coefficients in pResults[0] through pResults[3] such that
159 // y = pResult[0] + x * ( pResult[1] + x * ( pResult[2] + x * ( pResult[3] ) ) );
160 // passes through all four input points.
161 // Return is true if it succeeded, false if it failed (because two control points
162 // have the same pFitX value).
163 bool FitCubicPolynomial ( float *pResult, const float *pFitX, const float *pFitY );
165 //-----------------------------------------------------------------------------------
166 // ***** LensConfig
168 // LensConfig describes the configuration of a single lens in an HMD.
169 // - Eqn and K[] describe a distortion function.
170 // - MetersPerTanAngleAtCenter is the relationship between distance on a
171 // screen (at the center of the lens), and the angle variance of the light after it
172 // has passed through the lens.
173 // - ChromaticAberration is an array of parameters for controlling
174 // additional Red and Blue scaling in order to reduce chromatic aberration
175 // caused by the Rift lenses.
176 struct LensConfig
177 {
178 LensConfig()
179 : Eqn(Distortion_CatmullRom10)
180 //K()
181 , MaxR(0.0f)
182 , MetersPerTanAngleAtCenter(0.0f)
183 //ChromaticAberration()
184 //InvK()
185 , MaxInvR(0.0f)
186 {
187 memset(&K, 0, sizeof(K));
188 memset(&ChromaticAberration, 0, sizeof(ChromaticAberration));
189 memset(&InvK, 0, sizeof(InvK));
190 }
192 // The result is a scaling applied to the distance from the center of the lens.
193 float DistortionFnScaleRadiusSquared (float rsq) const;
194 // x,y,z components map to r,g,b scales.
195 Vector3f DistortionFnScaleRadiusSquaredChroma (float rsq) const;
197 // DistortionFn applies distortion to the argument.
198 // Input: the distance in TanAngle/NIC space from the optical center to the input pixel.
199 // Output: the resulting distance after distortion.
200 float DistortionFn(float r) const
201 {
202 return r * DistortionFnScaleRadiusSquared ( r * r );
203 }
205 // DistortionFnInverse computes the inverse of the distortion function on an argument.
206 float DistortionFnInverse(float r) const;
208 // Also computes the inverse, but using a polynomial approximation. Warning - it's just an approximation!
209 float DistortionFnInverseApprox(float r) const;
210 // Sets up InvK[].
211 void SetUpInverseApprox();
213 // Sets a bunch of sensible defaults.
214 void SetToIdentity();
218 enum { NumCoefficients = 11 };
220 DistortionEqnType Eqn;
221 float K[NumCoefficients];
222 float MaxR; // The highest R you're going to query for - the curve is unpredictable beyond it.
224 float MetersPerTanAngleAtCenter;
226 // Additional per-channel scaling is applied after distortion:
227 // Index [0] - Red channel constant coefficient.
228 // Index [1] - Red channel r^2 coefficient.
229 // Index [2] - Blue channel constant coefficient.
230 // Index [3] - Blue channel r^2 coefficient.
231 float ChromaticAberration[4];
233 float InvK[NumCoefficients];
234 float MaxInvR;
235 };
238 // For internal use - storing and loading lens config data
240 // Returns true on success.
241 bool LoadLensConfig ( LensConfig *presult, uint8_t const *pbuffer, int bufferSizeInBytes );
243 // Returns number of bytes needed.
244 int SaveLensConfigSizeInBytes ( LensConfig const &config );
245 // Returns true on success.
246 bool SaveLensConfig ( uint8_t *pbuffer, int bufferSizeInBytes, LensConfig const &config );
249 //-----------------------------------------------------------------------------------
250 // ***** DistortionRenderDesc
252 // This describes distortion for a single eye in an HMD with a display, not just the lens by itself.
253 struct DistortionRenderDesc
254 {
255 // The raw lens values.
256 LensConfig Lens;
258 // These map from [-1,1] across the eye being rendered into TanEyeAngle space (but still distorted)
259 Vector2f LensCenter;
260 Vector2f TanEyeAngleScale;
261 // Computed from device characteristics, IPD and eye-relief.
262 // (not directly used for rendering, but very useful)
263 Vector2f PixelsPerTanAngleAtCenter;
264 };
267 //-------------------------------------------------------------------------------------
268 // ***** HMDInfo
270 // This structure describes various aspects of the HMD allowing us to configure rendering.
271 //
272 // Currently included data:
273 // - Physical screen dimensions, resolution, and eye distances.
274 // (some of these will be configurable with a tool in the future).
275 // These arguments allow us to properly setup projection across HMDs.
276 // - DisplayDeviceName for identifying HMD screen; system-specific interpretation.
277 //
278 // TBD:
279 // - Power on/ off?
280 // - Sensor rates and capabilities
281 // - Distortion radius/variables
282 // - Screen update frequency
283 // - Distortion needed flag
284 // - Update modes:
285 // Set update mode: Stereo (both sides together), mono (same in both eyes),
286 // Alternating, Alternating scan-lines.
288 // Win32 Oculus VR Display Driver Shim Information
289 struct Win32ShimInfo
290 {
291 int DeviceNumber;
292 int NativeWidth;
293 int NativeHeight;
294 int Rotation;
295 int UseMirroring;
297 Win32ShimInfo() :
298 DeviceNumber(-1),
299 NativeWidth(-1),
300 NativeHeight(-1),
301 Rotation(-1),
302 UseMirroring(1)
303 {
304 }
305 };
307 class HMDInfo
308 {
309 public:
310 // Name string describing the product: "Oculus Rift DK1", etc.
311 String ProductName;
312 String Manufacturer;
314 unsigned Version;
316 // Characteristics of the HMD screen and enclosure
317 HmdTypeEnum HmdType;
318 Size<int> ResolutionInPixels;
319 Size<float> ScreenSizeInMeters;
320 float ScreenGapSizeInMeters;
321 float CenterFromTopInMeters;
322 float LensSeparationInMeters;
323 Vector2f PelOffsetR; // Offsets from the green pel in pixels (i.e. usual values are 0.5 or 0.333)
324 Vector2f PelOffsetB;
327 // Timing & shutter data. All values in seconds.
328 struct ShutterInfo
329 {
330 HmdShutterTypeEnum Type;
331 float VsyncToNextVsync; // 1/framerate
332 float VsyncToFirstScanline; // for global shutter, vsync->shutter open.
333 float FirstScanlineToLastScanline; // for global shutter, will be zero.
334 float PixelSettleTime; // estimated.
335 float PixelPersistence; // Full persistence = 1/framerate.
336 } Shutter;
338 // Desktop coordinate position of the screen (can be negative; may not be present on all platforms)
339 int DesktopX;
340 int DesktopY;
342 // Windows:
343 // "\\\\.\\DISPLAY3", etc. Can be used in EnumDisplaySettings/CreateDC.
344 String DisplayDeviceName;
345 Win32ShimInfo ShimInfo;
347 // MacOS:
348 int DisplayId;
350 bool InCompatibilityMode;
352 // Printed serial number for the HMD; should match external sticker
353 String PrintedSerial;
355 // Tracker descriptor information:
356 int VendorId;
357 int ProductId;
358 int FirmwareMajor;
359 int FirmwareMinor;
361 float CameraFrustumHFovInRadians;
362 float CameraFrustumVFovInRadians;
363 float CameraFrustumNearZInMeters;
364 float CameraFrustumFarZInMeters;
366 // Constructor initializes all values to 0s.
367 // To create a "virtualized" HMDInfo, use CreateDebugHMDInfo instead.
368 HMDInfo() :
369 ProductName(),
370 Manufacturer(),
371 Version(0),
372 HmdType(HmdType_None),
373 ResolutionInPixels(0),
374 ScreenSizeInMeters(0.0f),
375 ScreenGapSizeInMeters(0.0f),
376 CenterFromTopInMeters(0),
377 LensSeparationInMeters(0),
378 PelOffsetR(0.0f,0.0f),
379 PelOffsetB(0.0f,0.0f),
380 //Shutter (initialized below)
381 DesktopX(0),
382 DesktopY(0),
383 DisplayDeviceName(),
384 ShimInfo(),
385 DisplayId(-1),
386 InCompatibilityMode(false),
387 PrintedSerial(),
388 VendorId(-1),
389 ProductId(-1),
390 FirmwareMajor(-1),
391 FirmwareMinor(-1),
392 CameraFrustumHFovInRadians(0.0f),
393 CameraFrustumVFovInRadians(0.0f),
394 CameraFrustumNearZInMeters(0.0f),
395 CameraFrustumFarZInMeters(0.0f)
396 {
397 Shutter.Type = HmdShutter_LAST;
398 Shutter.VsyncToNextVsync = 0.0f;
399 Shutter.VsyncToFirstScanline = 0.0f;
400 Shutter.FirstScanlineToLastScanline = 0.0f;
401 Shutter.PixelSettleTime = 0.0f;
402 Shutter.PixelPersistence = 0.0f;
403 }
405 // Operator = copies local fields only (base class must be correct already)
406 void operator=(const HMDInfo& src)
407 {
408 ProductName = src.ProductName;
409 Manufacturer = src.Manufacturer;
410 Version = src.Version;
411 HmdType = src.HmdType;
412 ResolutionInPixels = src.ResolutionInPixels;
413 ScreenSizeInMeters = src.ScreenSizeInMeters;
414 ScreenGapSizeInMeters = src.ScreenGapSizeInMeters;
415 CenterFromTopInMeters = src.CenterFromTopInMeters;
416 LensSeparationInMeters = src.LensSeparationInMeters;
417 PelOffsetR = src.PelOffsetR;
418 PelOffsetB = src.PelOffsetB;
419 DesktopX = src.DesktopX;
420 DesktopY = src.DesktopY;
421 Shutter = src.Shutter;
422 DisplayDeviceName = src.DisplayDeviceName;
423 ShimInfo = src.ShimInfo;
424 DisplayId = src.DisplayId;
425 InCompatibilityMode = src.InCompatibilityMode;
426 VendorId = src.VendorId;
427 ProductId = src.ProductId;
428 FirmwareMajor = src.FirmwareMajor;
429 FirmwareMinor = src.FirmwareMinor;
430 PrintedSerial = src.PrintedSerial;
431 CameraFrustumHFovInRadians = src.CameraFrustumHFovInRadians;
432 CameraFrustumVFovInRadians = src.CameraFrustumVFovInRadians;
433 CameraFrustumNearZInMeters = src.CameraFrustumNearZInMeters;
434 CameraFrustumFarZInMeters = src.CameraFrustumFarZInMeters;
435 }
437 void SetScreenParameters(int hres, int vres,
438 float hsize, float vsize,
439 float vCenterFromTopInMeters, float lensSeparationInMeters,
440 bool compatibilityMode)
441 {
442 ResolutionInPixels = Sizei(hres, vres);
443 ScreenSizeInMeters = Sizef(hsize, vsize);
444 CenterFromTopInMeters = vCenterFromTopInMeters;
445 LensSeparationInMeters = lensSeparationInMeters;
446 InCompatibilityMode = compatibilityMode;
447 }
449 bool IsSameDisplay(const HMDInfo& o) const
450 {
451 return DisplayId == o.DisplayId &&
452 DisplayDeviceName.CompareNoCase(o.DisplayDeviceName) == 0;
453 }
455 static bool CreateFromSensorAndDisplay(SensorDevice* sensor, Display* display, HMDInfo* hmdi);
456 };
459 //-----------------------------------------------------------------------------------
460 // ***** HmdRenderInfo
462 // All the parts of the HMD info that are needed to set up the rendering system.
464 struct HmdRenderInfo
465 {
466 // The start of this structure is intentionally very similar to HMDInfo in OVER_Device.h
467 // However to reduce interdependencies, one does not simply #include the other.
469 HmdTypeEnum HmdType;
471 // Size of the entire screen
472 Size<int> ResolutionInPixels;
473 Size<float> ScreenSizeInMeters;
474 float ScreenGapSizeInMeters;
475 Vector2f PelOffsetR; // Offsets from the green pel in pixels (i.e. usual values are 0.5 or 0.333)
476 Vector2f PelOffsetB;
478 // Characteristics of the lenses.
479 float CenterFromTopInMeters;
480 float LensSeparationInMeters;
481 float LensDiameterInMeters;
482 float LensSurfaceToMidplateInMeters;
483 EyeCupType EyeCups;
485 // Timing & shutter data. All values in seconds.
486 struct ShutterInfo
487 {
488 HmdShutterTypeEnum Type;
489 float VsyncToNextVsync; // 1/framerate
490 float VsyncToFirstScanline; // for global shutter, vsync->shutter open.
491 float FirstScanlineToLastScanline; // for global shutter, will be zero.
492 float PixelSettleTime; // estimated.
493 float PixelPersistence; // Full persistence = 1/framerate.
494 } Shutter;
497 // These are all set from the user's profile.
498 struct EyeConfig
499 {
500 // Distance from center of eyeball to front plane of lens.
501 float ReliefInMeters;
502 // Distance from nose (technically, center of Rift) to the middle of the eye.
503 float NoseToPupilInMeters;
505 LensConfig Distortion;
506 } EyeLeft, EyeRight;
509 HmdRenderInfo()
510 {
511 HmdType = HmdType_None;
512 ResolutionInPixels.w = 0;
513 ResolutionInPixels.h = 0;
514 ScreenSizeInMeters.w = 0.0f;
515 ScreenSizeInMeters.h = 0.0f;
516 ScreenGapSizeInMeters = 0.0f;
517 CenterFromTopInMeters = 0.0f;
518 LensSeparationInMeters = 0.0f;
519 LensDiameterInMeters = 0.0f;
520 LensSurfaceToMidplateInMeters = 0.0f;
521 PelOffsetR = Vector2f ( 0.0f, 0.0f );
522 PelOffsetB = Vector2f ( 0.0f, 0.0f );
523 Shutter.Type = HmdShutter_LAST;
524 Shutter.VsyncToNextVsync = 0.0f;
525 Shutter.VsyncToFirstScanline = 0.0f;
526 Shutter.FirstScanlineToLastScanline = 0.0f;
527 Shutter.PixelSettleTime = 0.0f;
528 Shutter.PixelPersistence = 0.0f;
529 EyeCups = EyeCup_DK1A;
530 EyeLeft.ReliefInMeters = 0.0f;
531 EyeLeft.NoseToPupilInMeters = 0.0f;
532 EyeLeft.Distortion.SetToIdentity();
533 EyeRight = EyeLeft;
534 }
536 // The "center eye" is the position the HMD tracking returns,
537 // and games will also usually use it for audio, aiming reticles, some line-of-sight tests, etc.
538 EyeConfig GetEyeCenter() const
539 {
540 EyeConfig result;
541 result.ReliefInMeters = 0.5f * ( EyeLeft.ReliefInMeters + EyeRight.ReliefInMeters );
542 result.NoseToPupilInMeters = 0.0f;
543 result.Distortion.SetToIdentity();
544 return result;
545 }
547 };
550 //-----------------------------------------------------------------------------------
552 // Stateless computation functions, in somewhat recommended execution order.
553 // For examples on how to use many of them, see the StereoConfig::UpdateComputedState function.
555 const float OVR_DEFAULT_EXTRA_EYE_ROTATION = 30.0f * MATH_FLOAT_DEGREETORADFACTOR;
557 // Creates a dummy debug HMDInfo matching a particular HMD model.
558 // Useful for development without an actual HMD attached.
559 HMDInfo CreateDebugHMDInfo(HmdTypeEnum hmdType);
562 // profile may be NULL, in which case it uses the hard-coded defaults.
563 // distortionType should be left at the default unless you require something specific for your distortion shaders.
564 // eyeCupOverride can be EyeCup_LAST, in which case it uses the one in the profile.
565 HmdRenderInfo GenerateHmdRenderInfoFromHmdInfo ( HMDInfo const &hmdInfo,
566 Profile const *profile = NULL,
567 DistortionEqnType distortionType = Distortion_CatmullRom10,
568 EyeCupType eyeCupOverride = EyeCup_LAST );
570 LensConfig GenerateLensConfigFromEyeRelief ( float eyeReliefInMeters, HmdRenderInfo const &hmd,
571 DistortionEqnType distortionType = Distortion_CatmullRom10 );
573 DistortionRenderDesc CalculateDistortionRenderDesc ( StereoEye eyeType, HmdRenderInfo const &hmd,
574 LensConfig const *pLensOverride = NULL );
576 FovPort CalculateFovFromEyePosition ( float eyeReliefInMeters,
577 float offsetToRightInMeters,
578 float offsetDownwardsInMeters,
579 float lensDiameterInMeters,
580 float extraEyeRotationInRadians = OVR_DEFAULT_EXTRA_EYE_ROTATION);
582 FovPort CalculateFovFromHmdInfo ( StereoEye eyeType,
583 DistortionRenderDesc const &distortion,
584 HmdRenderInfo const &hmd,
585 float extraEyeRotationInRadians = OVR_DEFAULT_EXTRA_EYE_ROTATION );
587 FovPort GetPhysicalScreenFov ( StereoEye eyeType, DistortionRenderDesc const &distortion );
589 FovPort ClampToPhysicalScreenFov ( StereoEye eyeType, DistortionRenderDesc const &distortion,
590 FovPort inputFovPort );
592 Sizei CalculateIdealPixelSize ( StereoEye eyeType, DistortionRenderDesc const &distortion,
593 FovPort fov, float pixelsPerDisplayPixel );
595 Recti GetFramebufferViewport ( StereoEye eyeType, HmdRenderInfo const &hmd );
597 Matrix4f CreateProjection ( bool rightHanded, FovPort fov,
598 float zNear = 0.01f, float zFar = 10000.0f );
600 Matrix4f CreateOrthoSubProjection ( bool rightHanded, StereoEye eyeType,
601 float tanHalfFovX, float tanHalfFovY,
602 float unitsX, float unitsY, float distanceFromCamera,
603 float interpupillaryDistance, Matrix4f const &projection,
604 float zNear = 0.0f, float zFar = 0.0f );
606 ScaleAndOffset2D CreateNDCScaleAndOffsetFromFov ( FovPort fov );
608 ScaleAndOffset2D CreateUVScaleAndOffsetfromNDCScaleandOffset ( ScaleAndOffset2D scaleAndOffsetNDC,
609 Recti renderedViewport,
610 Sizei renderTargetSize );
613 //-----------------------------------------------------------------------------------
614 // ***** StereoEyeParams
616 // StereoEyeParams describes RenderDevice configuration needed to render
617 // the scene for one eye.
618 struct StereoEyeParams
619 {
620 StereoEye Eye;
621 Matrix4f HmdToEyeViewOffset; // Translation to be applied to view matrix.
623 // Distortion and the VP on the physical display - the thing to run the distortion shader on.
624 DistortionRenderDesc Distortion;
625 Recti DistortionViewport;
627 // Projection and VP of a particular view (you could have multiple of these).
628 Recti RenderedViewport; // Viewport that we render the standard scene to.
629 FovPort Fov; // The FOVs of this scene.
630 Matrix4f RenderedProjection; // Projection matrix used with this eye.
631 ScaleAndOffset2D EyeToSourceNDC; // Mapping from TanEyeAngle space to [-1,+1] on the rendered image.
632 ScaleAndOffset2D EyeToSourceUV; // Mapping from TanEyeAngle space to actual texture UV coords.
633 };
636 //-----------------------------------------------------------------------------------
637 // A set of "forward-mapping" functions, mapping from framebuffer space to real-world and/or texture space.
638 Vector2f TransformScreenNDCToTanFovSpace ( DistortionRenderDesc const &distortion,
639 const Vector2f &framebufferNDC );
640 void TransformScreenNDCToTanFovSpaceChroma ( Vector2f *resultR, Vector2f *resultG, Vector2f *resultB,
641 DistortionRenderDesc const &distortion,
642 const Vector2f &framebufferNDC );
643 Vector2f TransformTanFovSpaceToRendertargetTexUV ( ScaleAndOffset2D const &eyeToSourceUV,
644 Vector2f const &tanEyeAngle );
645 Vector2f TransformTanFovSpaceToRendertargetNDC ( ScaleAndOffset2D const &eyeToSourceNDC,
646 Vector2f const &tanEyeAngle );
647 Vector2f TransformScreenPixelToScreenNDC( Recti const &distortionViewport,
648 Vector2f const &pixel );
649 Vector2f TransformScreenPixelToTanFovSpace ( Recti const &distortionViewport,
650 DistortionRenderDesc const &distortion,
651 Vector2f const &pixel );
652 Vector2f TransformScreenNDCToRendertargetTexUV( DistortionRenderDesc const &distortion,
653 StereoEyeParams const &eyeParams,
654 Vector2f const &pixel );
655 Vector2f TransformScreenPixelToRendertargetTexUV( Recti const &distortionViewport,
656 DistortionRenderDesc const &distortion,
657 StereoEyeParams const &eyeParams,
658 Vector2f const &pixel );
660 // A set of "reverse-mapping" functions, mapping from real-world and/or texture space back to the framebuffer.
661 // Be aware that many of these are significantly slower than their forward-mapping counterparts.
662 Vector2f TransformTanFovSpaceToScreenNDC( DistortionRenderDesc const &distortion,
663 const Vector2f &tanEyeAngle, bool usePolyApprox = false );
664 Vector2f TransformRendertargetNDCToTanFovSpace( const ScaleAndOffset2D &eyeToSourceNDC,
665 const Vector2f &textureNDC );
667 // Handy wrappers.
668 inline Vector2f TransformTanFovSpaceToRendertargetTexUV ( StereoEyeParams const &eyeParams,
669 Vector2f const &tanEyeAngle )
670 {
671 return TransformTanFovSpaceToRendertargetTexUV ( eyeParams.EyeToSourceUV, tanEyeAngle );
672 }
673 inline Vector2f TransformTanFovSpaceToRendertargetNDC ( StereoEyeParams const &eyeParams,
674 Vector2f const &tanEyeAngle )
675 {
676 return TransformTanFovSpaceToRendertargetNDC ( eyeParams.EyeToSourceNDC, tanEyeAngle );
677 }
679 } //namespace OVR
681 #endif // OVR_Stereo_h