cancel
Showing results for 
Search instead for 
Did you mean: 

Lens Distortion - Lens Center calculation

bhodgman
Honored Guest
I'm integrating oculus stereo/distorted rendering into my engine based on the code from the Tiny Room demo, and the PDF. In the demo, the LensCenter input to the distortion shader is set with this code:

pPostProcessShader->SetUniform2f("LensCenter",
x + (w + Distortion.XCenterOffset * 0.5f)*0.5f, y + h*0.5f);

I've translated this into my engine as below, which is the same but it's copying into a mapped cbuffer structure:
			pixel.LensCenterX = x + (w + Distortion.XCenterOffset * 0.5f)*0.5f;

However, this produces strange results:


It seems to me that the offset should be to the right for the left viewport, and to the left for the right viewport,
i.e.:

if( x == 0 )//hack hack!
pixel.LensCenterX = x + (w + Distortion.XCenterOffset * 0.5f)*0.5f;
else
pixel.LensCenterX = x + (w - Distortion.XCenterOffset * 0.5f)*0.5f;

Which produces results that match the demo:



Is this a known bug in the sample code? Or have I somehow coincidentally passed in incorrect viewport values which have coincidentally been corrected by my "fix"?
1 REPLY 1

cybereality
Grand Champion
The shader has to be mirrored for the other eye, so it would make sense you need to provide different values. I think the way this works in the demos is that the Distortion.XCenterOffset is flipped in C++ before it reaches the shader. Your hack could work too.
AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV