- Home /
Graphics.DrawMeshInstanced Does Not Write to _CameraDepthNormalsTexture
Hey there, I am using EdgeDetection on my camera and recently converted my rendering system to use Graphics.DrawMeshInstanced, however my meshes do not receive the EdgeDetection image effect anymore. Any hints as to why? Any ideas how I can make these two systems work together?
EDIT:
Just discovered that when I use the Deferred Rendering Path, that the Edge Detection filter is applied, however I am using an Orthographic Camera, and thus cannot easily use the Deferred Rendering Path. I am now looking into using a Deferred Rendering Path in the Perspective Camera setting, but by applying a custom Orthographic Projection Matrix.
EDIT 2: Using Deferred Rendering with an Orthographic Projection Applied via Script (while the camera remains "perspective" in the editor) is not a feasible solution.
Is there a reason that the Standard Assets Edge Detection does not work with Graphics.DrawMeshInstanced using Forward Rendering?
EDIT 3: The "Luminance Threshold Setting" works, but looks much worse than Edge Detection using Triangle Depth Normals
EDIT 4: Determined that _CameraDepthNormalsTexture does not get written to while using DrawMeshInstanced in Forward Rendering mode, but _CameraDepthTexture does. I raised a bug with a repro project.
EDIT 5: The Unity QA Team responded to my bug report and are going to work on fixing this!
EDIT 6: They told me to use the CommandBuffer.DrawMeshInstanced version. Haven't tested if this works. Unity is likely not fixing this due to the impending release of ScriptableRenderLoops, where everything should be better and working!
I'm afraid I can't help, but just wanted to +1 for a great question and updates - do please let us know what response you get to the bug report.
That's a very nice thing to say tanoshimi! Thank you! The Unity QA Team responded to my bug report and are going to work on fixing this!
Answer by bnogal · Apr 18, 2017 at 09:54 AM
it got "resolved" as Won't Fix.
They told me to use the CommandBuffer.Draw$$anonymous$$eshInstanced version. Haven't tested if this works. Unity is likely not fixing this due to the impending release of ScriptableRenderLoops, where everything should be better and working!
For people wondering how to do it, follow this commit where I did exactly that in a public project. In addition to Graphics.Draw$$anonymous$$eshInstanced() which was already there, I use a command buffer just to add rendering into the depth+normals texture, using a custom shader: https://pastebin.com/$$anonymous$$vrF8svA
Hi @Ar$$anonymous$$Rigo could you post the code here- the pastebin link no longer works and I cant find any other info on this- thanks!
Ah, sorry. The project is https://baroquesoftware.com/nan-industry/ and the file is available at https://baroquesoftware.com/hg/nan-industry-vr/file/tip/Assets/Scripts/World.cs . Sorry, I don't have my own paste any more where I tried to reduce it, but look for the call to cmdbuf.Draw$$anonymous$$eshInstanced
, as well as the logic for getting one command_buffer
per camera.
Your answer
