Calculating the distortion shader parameters
- 4 replies
- 5085 views
Today I wanted to implement Rift support into our game engine http://rayne3d.com/ and I am having some trouble with calculating the parameters needed for the distortion shader.
The needed parameters and what I found out:
(A list like this would have made this A LOT easier...)
This is what I got from the docs and samples and what seems to work for me, but if anyone could confirm me if this is correct that would be awesome.
My problem now is how to calculate the factor. Oculus recommends to scale to fit to the width. But if I try it like shown below, it gets too big.
as you can see here:
Bildschirmfoto 2013-08-07 um 20.10.13 (2).png
The Util library does it different as it multiplies the scalefactor with the radius just to divide by it a bit later how does that make any sense?
What am I doing wrong and how do I fix it?
For better quality I should just scale my render target with the same 1/factor, right?
Can the FOV also just be scaled by that value?
Is there btw anything special with gamma correction (I just apply it after the distortion and color shifting, as it anyway just effect each pixels color channel individually)? So far it seems to look fine and everything, just wodering...
Thank you!
The needed parameters and what I found out:
vec2 LensCenter; //x+(w+projshift)*0.5, y+h*0.5
vec2 ScreenCenter; //left view: x+w*0.5, y+h*0.5
vec2 Scale; // w*0.5/factor, h*0.5*aspect/factor
vec2 ScaleIn; // 2/w, 2/h/aspect
vec4 HmdWarpParam; //HMDInfo.DistortionK
vec4 ChromAbParam; //HMDInfo.ChromaAbCorrection
x = 0 for left and 0.5 for right view (views x coordinate in 0-1)
y = 0 (views y coordinate in 0-1)
w = 0.5 (views width in 0-1)
h = 1.0 (views height in 0-1)
projshift = 0.15197 for left and -0.15197 for right view (1.0f-2.0f*HMDInfo.LensSeparationDistance/HMDInfo.HScreenSize)
aspect = 0.8 (w/h)
factor = ?
(A list like this would have made this A LOT easier...)
This is what I got from the docs and samples and what seems to work for me, but if anyone could confirm me if this is correct that would be awesome.
My problem now is how to calculate the factor. Oculus recommends to scale to fit to the width. But if I try it like shown below, it gets too big.
float scaleradius = (-1.0-LensCenter.x);
float scalefactor = scaleradius*scaleradius;
scalefactor = HmdWarpParam.x + HmdWarpParam.y*scalefactor + HmdWarpParam.z*scalefactor*scalefactor + HmdWarpParam.w*scalefactor*scalefactor*scalefactor;
as you can see here:
Bildschirmfoto 2013-08-07 um 20.10.13 (2).png
The Util library does it different as it multiplies the scalefactor with the radius just to divide by it a bit later how does that make any sense?
What am I doing wrong and how do I fix it?
For better quality I should just scale my render target with the same 1/factor, right?
Can the FOV also just be scaled by that value?
Is there btw anything special with gamma correction (I just apply it after the distortion and color shifting, as it anyway just effect each pixels color channel individually)? So far it seems to look fine and everything, just wodering...
Thank you!
