The documentation on Graphics.Blit(), which is located at Unity - Scripting API: Graphics.Blit, indicates that if you want to use a stencil buffer that is part of the source, you need to draw a quad manually.
I’m working with CommandBuffers, so I’d like to do this entirely from a command buffer.
It gives me the option to draw a mesh using CommandBuffer.DrawMesh.
And here’s what it asks for:
- [mesh] Mesh to draw.
- [matrix] Transformation matrix to use.
- [material] Material to use.
The material is simple enough to pass. And I’m pretty sure I can figure out what mesh to give, if I glean that information from the GL.quad page (at Unity - Scripting API: GL.QUADS).
But what do I pass for the projection matrix? I know it needs to be orthographic, but that’s exactly where my knowledge ends. It wants a Matrix4v4. How do I get a ortho matrix4v4? Or am I totally confused here.
Good to know nobody knows how to do it.
Good to know CommandBuffers are still trash in 2017. Still can’t access the stencil buffer without pulling out all your teeth and amputating several legs.
1 Like
You’re totally confused here.
That matrix is the world transform matrix for the mesh, which if you’re drawing a full screen quad you kind of don’t care about. Just make sure it’s vaguely in front of the camera. It’ll draw the mesh with the camera’s current view and projection matrices… but you kind of don’t care about any of those since when you’re drawing a full screen quad you should be skipping all of that and just do:
o.pos = float4(v.vertex.xy, 0.0, 0.5);
Assuming you’re using the default Unity quad mesh, there’s no matrix multiply at all as you can just write out directly to the final clip space pos. If you search for “draw a full screen quad in Unity” and skip the posts that say “use Blit” you’ll come across plenty of examples.
3 Likes