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(){
GL.PushMatrix();
GL.LoadProjectionMatrix(Camera.current.projectionMatrix);
Debug.Log("line mat used: "+ lineMaterial.name);
lineMaterial.SetPass(0);
//…. Lines drawn, cleanup performed
}
If render the camera with:
cam.Render()
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
cam.RenderWithShader(testShader,null)
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?