Custom Rendering Unity Plugin

Hi to all,
I’m an Objective-C/OpenGL programmer, and I’d like to experiment with Unity and low-level OpenGL programming.
During the great UNITE 2012 I tried to obtain some answers about Unity custom-plugin development, and I’m starting to make some experiments.
The most interesting example I found is this:

witch explains how to “manage Plugin Callbacks on the Rendering Thread”. The example renders a simple triangle that rotates in the scene:

Starting from this example, I have a couple of questions:

  • The plugin uses custom worldMatrix and projectionMatrix to locate the triangle in the scene, so it’ll be rendered at the center of the scene independently from the Unity3D camera. For example, if I try to translate Unity3D camera the scene will display this:

From the images I can understand that:

  • custom-plugin OpenGL is rendered after Unity3D rendering.
  • custom-plugin knows the values of ZBuffer of the rendered Unity3D scene (in the custom-plugin there is glEnable (GL_DEPTH_TEST));
    → Is it correct?
    → How can I render OpenGL-code in my custom plugin using the active camera in Unity3D so as to render my triangle from Unity3D camera point of view?
  • The triangle rendered is not part of the Unity3D scene, so for example it will not have shadows or post processing effect. If I apply blur effect to the unity3D camera the scene will display this:

From the image I can understand that:

  • custom-plugin OpenGL is rendered after Unity3D rendering AND Unity3D post-processing effect: the post-processing effect reset ZBuffer, this is why the triangle is displayed like if it shouldn’t intersect the plane.

→ How can I render OpenGL-code in my custom plugin and apply Unity3D camera post-processing effects also to that?

Thank you for any kind of help!

Anyone?

Try sending a PM to Aras.
He is the guy who does the graphics programming for Unity. He should be able to help you out.

Try to calling the gl rendering call before the end of the frame

i try it in d3d11:

  1. tansform matrixs MVP from unity to c plugins, used in HLSL.
  2. write your "GL.IssuePluginEvent() " in MainCamera’s “void OnPostRender()” (for the post-process effect).

en,i just testing…
1235085--52417--$Cplugin.PNG