Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Anonymous's avatar
Anonymous
11 years ago

No sRGB inside HMD (OpenGL, SDK 0.4.3)

Hello,

Here is my experience with the DK2 so far. I work with SDL2, OpenGL 3.3 in default profile (compatibility ?) and Windows 7 64 bits for now. I was surprised to get the Direct HMD mode working flawlessly (with this initialisation order : ovr_Initialize, ovrHmd_Create, window and GL context creation, ovrHmd_AttachToWindow, ovrHmd_ConfigureRendering).

The only problem that disturbs me is that I can't get sRGB correction when outputing to the HMD in direct-HMD mode (colors are okay in extended desktop mode). I usually set my color textures to GL_SRGB8 format to get free conversion to linear space when reading textures, and when I output to color framebuffers (or FBO with GL_SRGB8 attached textures) I usually use the GL_FRAMEBUFFER_SRGB option.

With the rift, I use two SRGB8 textures as framebuffers and use the SDK deformation renderer. The ovrDistortionCap_SRGB flag is set in the ovrHmd_ConfigureRendering call, and I get a correct image on my desktop screen, but not in the HMD (too dark, like if I was outputing the linear colors directly). If I omit this flag, the images on both my screen and the HMD are wrong (again, uncorrected linear colors). And this is in Direct-HMD mode only, I have troubles using extended desktop mode (not related to the SDK) but I can see that colors are correct. If I change the texture formats of my framebuffers from SRGB8 to RGB8 I just lose precision in dark colors (banding).

I don't know if the situation is the same with DirectX, but apparently this is a bug in the SDK. Is there some other experience that contradicts mine, or some devs at Oculus who know what's happening in that part of the SDK ? I want to know if this is something that would get corrected in future versions or if I have to do the old trick of sqrt'ing color writes...

Thanks !

20 Replies

  • sth's avatar
    sth
    Honored Guest
    I get the <1fps problem as well after a short while. :(
  • Could someone who got OpenGL Direct Mode working provide an example of their initialization code (specifically from ovr_Initialize to ovrHmd_ConfigureRendering)? I have this order but still not functional. I get the same "OVRcreateDXGIFactory2 result 0x0" error popping up in my console that I did in prior SDK versions. An example would help alot!
  • skynet's avatar
    skynet
    Honored Guest
    BTW: Is TimeWarp working for you?


    Latency testing might be broken with sRGB. In the 0.4.2 code I saw that in the 'latency pixel' render code is trying to 'counter' sRGB encoding in the shader instead of just disabling GL_FRAMEBUFFER_SRGB when rendering that pixel. In conjunction with the other anormalies with sRGB, we could assume that it all doesn't work well.
  • Anonymous's avatar
    Anonymous
    "HartLabs" wrote:
    Could someone who got OpenGL Direct Mode working provide an example of their initialization code (specifically from ovr_Initialize to ovrHmd_ConfigureRendering)? I have this order but still not functional. I get the same "OVRcreateDXGIFactory2 result 0x0" error popping up in my console that I did in prior SDK versions. An example would help alot!


    It's not straightforward to give my init code, as it's not in only one place, but it's almost that :

    ovr_Initialize();
    hmd = ovrHmd_Create(0);
    // stripped fallback if hmd == NULL
    ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);
    ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0);

    Somewhere else ('x', 'y', 'width' and 'height' are set to hmd->WindowPos and hmd->Resolution values) :

    SDL_Init(SDL_INIT_VIDEO);
    window = SDL_CreateWindow(title, x, y, width, height, SDL_WINDOW_OPENGL | flags);
    context = SDL_GL_CreateContext(window);
    glewInit();

    And then :

        SDL_SysWMinfo info;
    SDL_VERSION(&info.version);
    SDL_GetWindowWMInfo(getWindowState()->window, &info);

    union ovrGLConfig glcfg;
    memset(&glcfg, 0, sizeof(glcfg));
    glcfg.OGL.Header.API = ovrRenderAPI_OpenGL;
    glcfg.OGL.Header.RTSize = hmd->Resolution;
    glcfg.OGL.Header.Multisample = 0;
    #if defined(OVR_OS_WIN32)
    glcfg.OGL.Window = info.info.win.window;
    glcfg.OGL.DC = wglGetCurrentDC();
    if (!(hmd->HmdCaps & ovrHmdCap_ExtendDesktop))
    ovrHmd_AttachToWindow(hmd, info.info.win.window, NULL, NULL);
    #elif defined(OVR_OS_LINUX)
    glcfg.OGL.Disp = info.info.x11.display;
    glcfg.OGL.Win = info.info.x11.window;
    #endif

    for (int i = 0; i < 2; i++) {
    ovrSizei size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left + i, hmd->DefaultEyeFov[i], pixelDensity);

    frameFBO[i] = createFBO(size.w, size.h, blahblahblah...);

    frameDesc[i].OGL.Header.API = ovrRenderAPI_OpenGL;
    frameDesc[i].OGL.Header.TextureSize.w = size.w;
    frameDesc[i].OGL.Header.TextureSize.h = size.h;
    frameDesc[i].OGL.Header.RenderViewport.Pos.x = 0;
    frameDesc[i].OGL.Header.RenderViewport.Pos.y = 0;
    frameDesc[i].OGL.Header.RenderViewport.Size.w = size.w;
    frameDesc[i].OGL.Header.RenderViewport.Size.h = size.h;
    frameDesc[i].OGL.TexId = frameFBO[i]->color[0]->id;
    }

    if (!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp | ovrDistortionCap_HqDistortion | 0*ovrDistortionCap_SRGB | ovrDistortionCap_Overdrive, hmd->DefaultEyeFov, eyeDesc))
    argh();


    Only tested on Win 7 x64.
  • Thanks! I got it working, kind of. I was calling ovr_Initialize() prior to creating the window but after allocating the window variable. Moving both to after ovr_Initialize() fixed it right up.

    It is still not usable though. I am getting 37.5fps with minimal GPU load. Tried all versions of VSync settings in the NVidia control panel. Additionally on the rift (not the mirror) I get double images. I tried to disable mirroring to troubleshoot more but if in initialization I call:

    ovrHmd_SetEnabledCaps(program.oculus.hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction | ovrHmdCap_NoMirrorToWindow);


    I crash with the message "Interfering software is preventing your rift from activating...". Any ideas?
  • sth's avatar
    sth
    Honored Guest
    "HartLabs" wrote:
    It is still not usable though. I am getting 37.5fps with minimal GPU load.

    Sounds like you're calling SwapBuffers manually. This is already done by ovrHmd_EndFrame().
  • Anonymous's avatar
    Anonymous
    There are some (different ?) performance problems here and there for now. Some have sometime abyssal performance (way below 1 fps) like I did with 0.4.3. I now only create a window (not fullscreen) for direct and extended mode and I don't have this problem anymore. It's also the only way to make things work fine on computers with lower resolution than 1080p.

    jspenguin (thanks a lot for the SDK DLLs !) also reported a fairly high cost of the function ovrHmd_EndFrame() especially since 0.4.3. An Oculus dev explained that they actually use 2 sync points to reduce latency, and that can hinder performance somewhat. Better solutions should come in the future. But with V-Sync off, I can't have more than ~160 fps with a spinning cube :( (okay, Core 2 Duo, 9800 GTX..., but still, not much room for nice graphics).
  • "sth" wrote:
    Sounds like you're calling SwapBuffers manually. This is already done by ovrHmd_EndFrame().

    I had this problem when I first implemented the SDK back in 0.4, and the symptoms are identical but there are no extra SwapBuffers in my code. My present code works fine in extended which I would imagine would not be the case if I had an extra swap buffer somewhere.

    Any idea how an extra Swap call might be made while in Direct? It seems to me it might have to do with the mirror somehow, but like I said I crash if I attempt to turn it off. I am rendering to a singe shared texture, I could see that somehow causing it as well maybe?

    I tried turning off timewarp, dynamic prediction, only rendering one eye, turning off vsync everywhere possible, no change. Seems kind of strange it is not affected if I turn off Vsync.

    Hmmm just noticed another weird symptom. If I unplug my second monitor my program hangs. Plugging it back in and it runs. But now plugged back in it has no output even though the system recognizes it.

    I am creating a borderless fullscreen window, tried full windowed, fullscreen, no change.
  • sth's avatar
    sth
    Honored Guest
    Strange... Your setup sounds very similar to mine, but I "only" get the "less than 1fps after a while" bug. :?
  • "sth" wrote:
    I "only" get the "less than 1fps after a while" bug.


    I actually just realized I get this bug as well. What I though was the program hang after unplugging my second monitor is actually the <1 FPS bug. I found it is cleared by alt tabbing out of my program. FPS instantly goes right back to 37.5 once that is done. I get this problem even if I boot without the second monitor at all. Strange.