I want to draw something to a RenderTexture, with materials and rectangle range provided.
I originally think DrawMesh should considered the RenderTexture in normalized screen space, which is ranged from (0, 0) to (1, 1) or from (-1, -1) to (1, 1), and the matrix in parameter is for transforming mesh from local space to normalized space.
void OnEnable()
{
RenderPipelineManager.beginContextRendering += this.OnRendering;
}
void OnDisable()
{
RenderPipelineManager.beginContextRendering -= this.OnRendering;
}
void OnRendering(ScriptableRenderContext context, List<Camera> cameras)
{
cmd = cmd ?? new CommandBuffer();
cmd.SetRenderTarget(renderTexture);
cmd.ClearRenderTarget(true, true, Color.red);
foreach(var entry in entries)
{
var trs = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
cmd.DrawMesh(ProtaUnityConstant.rectMeshOne, trs, entry.material, 0, 0);
}
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
}
However it doesn’t work properly, I try to modify TRS matrix to fill the RenderTexture, and it needs to be 780 units width. I also found that the width required changes as my Scene window resizes, so I guess it uses sceneview camera’s clip space.
Is there any other way to draw a rect mesh on RenderTexture in normalized space? Or simply reset camera params?
I had looked into CommandBuffer.Blit(). but I don’t see any parameter for my TRS matrix to fit in… It doesn’t have an override where both material and scale&offset appears in parameter list… kinda weird…