Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Implementing Active Stereo using NVAPI in Unity(NvAPI_Stereo_SetDriverMode before Device creation)

Discussion in 'General Discussion' started by killer_mech, Jun 7, 2018.

  1. killer_mech

    killer_mech

    Joined:
    Jan 13, 2015
    Posts:
    4
    Hi Everyone,
    I have been writing a plugin to implement Active Stereo in unity3d using NVAPI. For now I have been able to create plugin in c++ & initialise NVAPI & start stereo in unity.
    I used this example as reference to compile & make plugin.

    For my next step I want each eye to render with backbuffer which is done using :

    Code (CSharp):
    1. NvAPI_Stereo_SetDriverMode(NVAPI_STEREO_DRIVER_MODE_DIRECT);
    2.  
    3. //Left and right eye rendering:
    4. NvAPI_Stereo_SetActiveEye(right); then render scene
    5. NvAPI_Stereo_SetActiveEye(left); then render scene
    Problem here I encountered is when I try to do this is that NvAPI_Stereo_SetDriverMode to NVAPI_STEREO_DRIVER_MODE_DIRECT although says NVAPI_OK during plugin load; but after loading it will set to automatic mode. Before I go further NvAPI_Stereo_SetDriverMode is where you tell nvidia driver weather or not have the app to control on stereo for render or take over the stereo. In this DirectMode is what allows app to control this.

    To use the above DirectMode you have to initiailize NVAPI & SetDriverMode in directMode before the initialization of d3device. I had used kGfxDeviceEventInitialize to load and set the above values. I found out the NvAPI_Stereo_SetActiveEye gave back NVAPI_SET_NOT_ALLOWED result. Which meant according to this question on stack overflow ; bringing me to conclusion that d3d device is being created first & plugin load is happening afterwards. Also found this thread with similer question. Though the thread is quite old yet now but Iam hoping maybe someone has found a solution for this.

    So that brings me to my question.
    1) Is it possible to make plugin load first & d3dDevice creation later(Highly unlikely)
    2) Destroy the d3ddevice after getting it & reinitialize after I complete the initialization of the NVAPIs?(Might be possible but not sure how will be able to make that?)
    External hooks are possiblity but not sure how to implement them also dont want to use hooks unless it is a very last resort to start direct mode. Would like to know if anyone has implemented this yet?