Skip to main content
New Participant
April 7, 2013

Code for applying distortion

Hi all,

my C++ and DirectX knowledge is very limited, so I have a hard time coming to grips with the rendering part of the SDK.

For now I'd like to create a simple stereo viewer. Load 2 images (left eye and right eye), distort them properly and combine them into the one image for the Rift.

The issue is: I dont know how to apply the distortion filter (do I need to use Direct3D or can I apply the filter to a 2D image?). Can anyone provide some (simple) sample code of loading a texture and distorting it for the rift? The SDK code is not simple and all embedded in actual scene rendering code. C# would be best (if possible). C++ could also work.

Cheers

    21 replies

    Up and Coming
    May 3, 2013
    Yet another reason I need to get a high speed camera. Alas, I don't have the budget for it.
    (╯°□°)╯︵┻━┻
    Up and Coming
    May 4, 2013
    Would a PS3 Eye not suffice?
    Up and Coming
    May 4, 2013
    High speed camera is so I can actually make a video of how a display updates its pixels. I want at least 240 frames per second.

    I've been wanting one for motion controller and virtual reality research because I can film users and see things I'd ordinarily not see.
    (╯°□°)╯︵┻━┻
    Up and Coming
    May 9, 2013
    "geekmaster" wrote:
    With a rolling display, those vertical lines should look slanted, because the pixel columns were at different locations as the display moved while the scanlines were being drawn. That is not what I remember having seen in my Rift DK...
    "jwilkins" wrote:
    Yet another reason I need to get a high speed camera. Alas, I don't have the budget for it.

    A high speed camera will not show the slanted lines. That is a perceptual thing your brain does with where it EXPECTS the pixels to be on a moving display.

    "jwilkins" wrote:
    High speed camera is so I can actually make a video of how a display updates its pixels. I want at least 240 frames per second.

    I've been wanting one for motion controller and virtual reality research because I can film users and see things I'd ordinarily not see.

    With appropriate software to drive an animated diagnostic screen, you can photograph a progression of pixel update states with a still camera, as shown on the "Response time test - ghosting" and "Input lag test" LCD tests on this page:
    http://www.lagom.nl/lcd-test/response_time.php
    You'll get a higher accuracy with a photo camera set to a short shutter time (for example 1/400 s at ISO 800 or ISO 1600).

    Example: dark-to-light 2 frames (33.3 ms), light-to-dark 5 frames (83 ms). Taken at shutter time 1/400 s.
    The photo above shows that the leftmost two bars are fainter than the other bars. This means that the dark-to-light response time is 2×16.67 ms = 33.3 ms. A millisecond (ms) = 0.001 seconds. The test pattern consists of 10 bars; in this image, 15 bars are visible, which means that this monitor needs 15–10 = 5 frames (83 ms) to do a light-to-dark transition. It is best to take several picture and take the average.
    ...
    The input lag test shows both a stopwatch in milliseconds and a frame number from 0 to 59. LCD monitors are generally updated 60 times per second, which means that the accuracy is never better than 16.67 milliseconds. Take a photo with a short shutter time of both screens to evaluate this. If necessary, try to improve the response time by clicking different gray-level buttons

    Input lag, tested between an LCD television (top) and a laptop.
    In the image above, the bottom screen has a slower response time, which makes it harder to make out the numbers. However, for both screens, the frame number is a mixture between 39 and 40. It is the highest number that counts, which means that in this case, there is no significant difference in input lag between the two screens. If the highest frame numbers were different, e.g. [39] (top) and [41] (bottom), it would mean that the top screen is the one with most input lag; more accurately: 2×16.67 = 33.3 ms.

    They also say at that site that the best way to measure LCD lag (latency) is to duplicate your display desktop to a CRT monitor (zero latency) and the LCD to measure (Rift DK in our case), run the programs above, and take a single photograph containing both displays (CRT and LCD), then visually compare the differences. This simplifies a similar method I read about in one of the PDF links I provided in a previous post (here or at MTBS3D).

    There are a LOT of other great LCD tests at that site too...

    As these (and other) tests show, with animated displays driven by appropriate (free) test software, and a single still photograph (not video), there are a lot of useful LCD measurements that can be obtained.
    This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
    Up and Coming
    May 9, 2013
    Ah, good stuff as always gm.

    With a HS camera I was expecting to see tearing, not curved/slanted lines, so I didn't mean to imply that.

    Not directly related except it is another perceptual foible: I found recently that even with red-cyan 3D glasses you get interesting effects when you move your head. Your brain is trying to anticipate what will happen when you move and creates this odd illusion of parallax that cannot be real. I guess this kind of thing keeps us from getting eaten by lions...

    I should be able to do these tests with still photos with the HS camera I get set to still mode. Right now I don't have a good camera at all :(

    I was actually thinking about test patterns and calibration/configuration images for the Rift recently. For example I had ideas for setting the IPD and other configuration values using only head tracking and visual and/or audio queues. Hopefully this will result in hands free configuration.
    (╯°□°)╯︵┻━┻
    Up and Coming
    May 14, 2013
    "jwilkins" wrote:
    Not directly related except it is another perceptual foible: I found recently that even with red-cyan 3D glasses you get interesting effects when you move your head. Your brain is trying to anticipate what will happen when you move and creates this odd illusion of parallax that cannot be real. I guess this kind of thing keeps us from getting eaten by lions...
    Red/cyan glasses do not have equal luminance in both lenses. You can get different contrasting filter colors that DO have equal luminance, but they also require different anaglyph color encoding. Besides all my Red/Blue, Red/Green, and Red/Cyan glasses, the synthetic 3D-Video encoder I recently purchased came with (brown/blue) "ColorCode 3-D" glasses shown here:
    http://www.amazon.com/3D-Glasses-Plastic-ColorCode-Internet/dp/B0036JPY08
    and described here:
    http://en.wikipedia.org/wiki/Anaglyph_3D

    The darker luminance in one eye makes your brain take longer to perceive that image. This is known as the "Pulfrich Effect" and has caused numerous helicoptor accidents from sunglasses causing the rotors to look shorter than they actually are, leading to accidents. The Pulfrich Effect is also used for a form of stereoscopic 3D, where a panning image (such as video shot from a vehicle side window) is viewed through special 3D glasses with one transparent lens and one darkened lens. When the video is moving in the correct direction, you eyes see the video from different points in time, causing stereoscopic parallax from the perceptual time delay between moving camera images. More info here:
    http://en.wikipedia.org/wiki/Pulfrich_effect

    I plan to use a synthetic Pulfrich effect for sterescopic 360-degree panorama 3D, shot from either a pair of mirrorball reflectors, or a forward-facing pair and rear-facing pair of fisheye cameras. The side views will lack differential camera parallax due to being coplanar, but I will delay the side quadrants to the forward eye in the side quadrants, which will work when the camera is moving in a forward direction (such as is common in 360-panorama video).

    Anyway, the perceived 3D you mentioned when moving your head with anaglyph 3D glasses is probably mostly caused by the Pulfrich Effect. Sorry about the above lecture... these things trigger brain dumps like this (a lifetime of technical knowledge wanting a creative outlet and looking for the least excuse to escape into a forum like this).
    :D
    This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
    Up and Coming
    May 14, 2013
    Oh wow geekmaster... I did a long wiki-walk a while ago on optical illusions and I didn't run across this.

    I've actually wanted to write a book about visual perception, but seems to be becoming a glass of water too tall to drink in one gulp...

    I'm not so sure what I'm seeing is the Pulfrich effect though. I'll have to observe it further with what I know about the effect in mind to be sure.

    If you have the glasses, give this image a look:
    (╯°□°)╯︵┻━┻
    Up and Coming
    May 14, 2013
    "jwilkins" wrote:
    ... If you have the glasses, give this image a look: ...

    Ah, yes. The muzzle flash-suppressor is on my side of the screen. Nice! Of course, you can only get away with negative parallax like that for objects constrained to the screen center, to prevent annoying stereoscopic window-violation errors when framing your subject:
    http://www.vmresource.com/camera/stereowindow.htm

    BTW, I used (and recommend) inexpensive and relatively high quality anaglyph glasses like these:
    http://www.ebay.com/itm/280789749370
    MUCH better than tinted cellophane and cardboard glasses, and only $1.49 (free shipping) for TWO pairs of glasses.
    This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
    Up and Coming
    May 14, 2013
    Those are exactly the pair I bought off of Amazon a few weeks ago :)

    Actually I got two pairs so I could share.

    They were part of a new program where they only sell you certain things if you spend over $25 (so I went ahead and bought a DVI splitter/amp).

    EDIT: Now that I've had a chance to look at this image again with the glasses I can see that there is parallax both side to side and up and down. This rules out the Pulfrich effect doesn't it? What is so weird about it is that lengths and angles change as-if you are really moving around the object, but being a 2D image there is no way this can actually be happening. So after moving your head, observing parallax, and then examining the image closely you realize that nothing has changed. I find this illusion to be rather fascinating.
    (╯°□°)╯︵┻━┻
    Up and Coming
    May 14, 2013
    "jwilkins" wrote:
    Those are exactly the pair I bought off of Amazon a few weeks ago :)

    Actually I got two pairs so I could share.

    They were part of a new program where they only sell you certain things if you spend over $25 (so I went ahead and bought a DVI splitter/amp).

    EDIT: Now that I've had a chance to look at this image again with the glasses I can see that there is parallax both side to side and up and down. This rules out the Pulfrich effect doesn't it? What is so weird about it is that lengths and angles change as-if you are really moving around the object, but being a 2D image there is no way this can actually be happening. So after moving your head, observing parallax, and then examining the image closely you realize that nothing has changed. I find this illusion to be rather fascinating.

    I think you are just experiencing the negative parallax effects there (objects this side of the screen). Nothing new there for me, I am afraid (into 3D since about 3 years old, and drawing many anaglyph geometric patterns when I was 9, using colored pencils and DIY anaglyph glasses I made from postcards and colored cellophane from Easter basket wrapping. I still have my anaglyph artwork, but the old paper is yellowed and a bit crumbly at the edges...

    Pufrich needs different images (delayed for one eye) for true 3D. Moving around with no head tracking makes the negative parallax parts appear to move with your head. All of my anaglyph artwork was like that, appearing as a 3D "toothpick" construction on TOP of the paper (negative parallax), that moved WITH my head movements. Perhaps that is what you are seeing...
    This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.