Camera.RenderWithShader() and GL drawing: possible?

I have a custom renderer that uses GL draw functions to render objects.

While attempting to do some filtering of objects rendered to a camera, using RenderWithShader (layers wouldn’t work for this), I found my custom renderers were not visible, even though I expected them to be.

As a test I configured my custom renderers to use the same exact shader as the one specified in RenderWithShader, and specified null for the tag parameter (to eliminate the filtering as a possible issue).

In my custom renderer, I draw the lines, and specify the material pass to use.

Void OnRenderOject(){
            Debug.Log("line mat used: "+;
//…. Lines drawn, cleanup performed

If render the camera with:


The debug.Log string, and drawn lines show up. In addition, the lineMaterial.Name in the log-string, matches the Material using the testShader; “TestShaderMaterial”.

If I call


The debug.log string does not show up, (nor obviously, do the lines). However, MeshRenderers in the scene, ARE visible (and as expected: are using the testShader).

Side-note/additional Info:

I realize the docs state that when using RenderWithShader: “The camera will not send OnPreCull, OnPreRender or OnPostRender to attached scripts. Image filters will not be rendered either.” Though in this case, it’s OnRenderObject() that is not being called, is suspect that’s because it is “similar to” OnPostRender().

Other tests: Manually calling the GL drawing code (before OR after RenderWithShader) does not actually affect the camera’s output, even though the debug-logs confirm it IS drawing lines… somewhere. I pass the camera to the GL drawing code, but I only use it to get projection matrixes and stuff.

possibly of interest: I have a renderTexture attached to the camera. That texture is the FINAL output I’m looking for. The camera is just how I’m getting it.

Main Question: How can I get my GL drawings output to that camera, and still use RenderWithShader?

Well, first of all GL rendering code has no direct relation to a camera unlike actual “renderer” objects. GL rendering code directly renders to the screen buffer.

RenderWithShader conceptionally won’t run any custom GL rendering code automatically as custom GL code sets the used rendering pass manually so RenderWithShader has no way to change the shader.

However running the rendering code manually after the camera has rendered it’s “normal” scene you should be able to render your GL stuff manually. Keep in mind when rendering stuff manually you have to take care of everything yourself which includes projection and transform / model matrices as well as Viewport settings. Some might be still valid from the last camera rendering, but you shouldn’t rely on that.

You also might need to convert the projection matrix with GL.GetGPUProjectionMatrix however i’m not sure about that as the documentation of GL.LoadProjectionMatrix isn’t really clear about if it’s going to convert the matrix automatically or not.