Search Unity

Graphics Command buffers and native rendering.

Discussion in '5.2 Beta' started by booyah, Sep 1, 2015.

  1. booyah

    booyah

    Joined:
    Mar 5, 2013
    Posts:
    220
    Hi!

    I started looking into the shiny new interface to try and get our plugin to make the best out of it but I'm a bit lost so far.

    I downloaded the sample project (RenderingPluginExample52) from the documentation (CommandBuffer.IssuePluginEvent indirectly sent me there) but it only shows the new interface.

    So, is there any sample showing off some native rendering along with the command buffers?
    I'd like to experiment with some native rendering in the G-Buffer or lighting buffer.

    Cheers,
     
  2. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
  3. booyah

    booyah

    Joined:
    Mar 5, 2013
    Posts:
    220
    @TomasJ : Yeah, I know.
    That's exactly the feature I'd like an example of (in the RenderingPluginExample52, for example). ^^
    Well, I'll get by. I was just wondering if there was something that could have saved me some time.

    Thanks,
     
  4. booyah

    booyah

    Joined:
    Mar 5, 2013
    Posts:
    220
    Actually some sort of sample would be useful, as I can't seem to get my command buffer to issue the plugin event...

    I tried adapting the RenderingPluginExample52 project to render in the G-buffer or something but the breakpoint I set in the render event function of the native plugin is never hit.

    Using the original UseRenderingPlugin.cs, I commented out of the Start() method the coroutine start and initialized a new command buffer instead.

    Code (csharp):
    1.    public CommandBuffer   m_CmdBuf;
    2.    public Camera       m_Cam;
    3.  
    4.    IEnumerator Start()
    5.    {
    6.      SetUnityStreamingAssetsPath(Application.streamingAssetsPath);
    7.      m_CmdBuf = new CommandBuffer();
    8.      m_CmdBuf.name = "test native";
    9.      m_Cam.AddCommandBuffer(CameraEvent.BeforeLighting, m_CmdBuf);
    10.  
    11.      CreateTextureAndPassToPlugin();
    12.      yield return null;
    13. //     yield return StartCoroutine("CallPluginAtEndOfFrames");
    14.    }
    Then I wrote an OnWillRenderObject to add the plugin event to the command buffer :
    Code (csharp):
    1.   public void OnWillRenderObject()
    2.    {
    3.      // see Edit2 below
    4.      m_CmdBuf.Clear();
    5.      SetTimeFromUnity (Time.timeSinceLevelLoad);
    6.      m_CmdBuf.IssuePluginEvent(GetRenderEventFunc(), 1);
    7.    }
    The script is attached on the plane visible by the main camera and the main camera is attached to the script via m_Cam.
    So... Either there's something I'm not getting or the command buffer IssuePluginEvent is not working.

    Edit : Ok, I fiddled some more and it turns out it works only for certain values of CameraEvent, for some reason.
    Also, the performances are bad. 3 FPS-bad. :(
    Edit2 : Ok, I didn't realize I needed to clear the command buffer before refilling it, so the performance issue is gone, but most CameraEvents still won't work.

    Thanks,
     
    Last edited: Sep 2, 2015
  5. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    You don't need to clear command buffers. Just configure the buffer once.
    Command buffer IssuePluginEvent is not immediate like GL.IssuePluginEvent, so just add the plugin call in your Start method.
     
  6. booyah

    booyah

    Joined:
    Mar 5, 2013
    Posts:
    220
    Indeed.
    So, the only issue is actually with the ineffective CameraEvent values.
     
  7. booyah

    booyah

    Joined:
    Mar 5, 2013
    Posts:
    220
  8. booyah

    booyah

    Joined:
    Mar 5, 2013
    Posts:
    220
    So I guess my interrogations all boil down to the following question :
    In practice, how do I get the rotating triangle from the samples to be correctly lighted and shaded?

    :)
     
  9. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    Hello @Aras , see above
     
  10. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,544
    I don't think there's an easy way of achieving that from the native code plugin. Since that needs all shader state + all variables it needs to be set up.
     
  11. booyah

    booyah

    Joined:
    Mar 5, 2013
    Posts:
    220
    Hi Aras! Thanks for chiming in.
    I figured there was no easy way. ;)
    I'm trying to understand how hard it can be with the current command buffers, if possible at all. Possibly in a way that won't break with the next Unity update.
    I'm not afraid by the complexity of the task. As long as I don't have to reverse the graphics pipeline in Pix, I'll be all fine and dandy.
    I'm concerned about maintainability, though.
     
    Last edited: Sep 4, 2015
  12. booyah

    booyah

    Joined:
    Mar 5, 2013
    Posts:
    220
    Bump!
    @Aras : Sooo... Anything more detailed than "it's complicated"?
    I'm guessing it's just a matter of writing to the right render targets with the appropriate shaders...
     
unityunity