Hi there,
While working on a plugin doing some advanced rendering, I’ve come across some issues regarding how it interferes with the regular graphics pipeline as soon as you go further than the typical triangle and vertex colors.
Currently I (well, mostly our customers using the plugin) have encountered the following issues on which I’d love to hear some insight. Stuff like workarounds or how to “do it right” (with the native rendering in the command buffers coming in 5.2, for instance).
For the sake of context, here is how we currently do our rendering :
- Main pass is done with a GL.IssuePluginEvent in the camera’s OnPostRender method. This relies on the scene’s z-buffer to render correctly OR on the depth texture described below.
- When enabled/necessary we get the scene’s depth with an additional offline camera (which by the way is really expensive, considering the apparent triviality of the task, if there’s a cheaper/more viable way, I’d love to hear about it). The resulting render texture is passed as a native handler to the main pass described above and the pass described below.
- When enabled we render an additional offline camera with GL.IssuePluginEvent in the OnPostRender method. We use the RenderTexture in an image effect to render screen-space distortions. This pass requires the aforementioned depth texture.
Now, about the problems encountered:
-
When the camera has a third-party image effect that adds an OnRenderImage method with the [ImageEffectOpaque] attribute, the scene’s z-buffer is empty when the native rendering is done.
This is not an issue when retrieving the depth from the render texture but is when doing rendering relying on z-testing only because nothing gets culled.
I’m not sure if this is a bug or the intended behaviour. -
When doing native rendering from the OnPostRender method, Unity’s lens flares just disappear.
This happens as soon as the plugin event is issued in OnPostRender, regardless of the graphics’ state (even happens when UnityRenderEvent does nothing). This doesn’t happen if the plugin event is issued from a coroutine waiting for the end of the frame (like in the native rendering plugin sample from the documentation). It also won’t happen in OpenGL (at least on MacOSX), which lead me to think it was a bug, hence I reported it (here, case 723015 https://fogbugz.unity3d.com/default.asp?723015_qqv8uiudi9unbriq).
There’s also the problems relating to bad integration with the transparent materials (native rendering is always on top), but I believe this can be fixed using the command buffers when native rendering will be allowed in 5.2. I haven’t had the time to look at the beta yet but I will at some point. Although if someone has any clues regarding this, I’m all ears. ![]()
Thanks in advance,