Good afternoon, I am currently struggling to get DrawMesh from a CommandBuffer to behave properly.
I just started with a super simple component, just grabbing a mesh, a material and calling DrawMesh bound to the afterGBuffer. The result I get is this:
The material used is the red material, the red sphere is rendered normally by unity, the white one is the result I get. (I can get it to cast and receive shadows if I bind the commands to the lights, that is not an issue).
The weird thing is that I can see the albedo value properly written in the GBuffer:
Also, the normals get in nicely, only the 4th buffer is a bit weird, the sphere is fully white, by investigating that buffer it looks like is a float16 RGBA, that made me think maybe had to do with HDR. Indeed if I go and disable HDR I get the following result:
Now the shading is getting done but is much darker for some reason. Does anyone know what is going on here? I am currently running on 2018.2.f1 but I got it to reproduce on 2017.
I kinda have the feeling that maybe I am doing something stupid and missing a detail?
Any advice is more than welcome, dummy project is attached to the thread.
Here the raw code of the component:
public class customDraw : MonoBehaviour {
public GameObject m_object;
public Material m_mat;
private Mesh m_mesh;
private CommandBuffer cmd;
void Start () {
m_mesh = m_object.GetComponent<MeshFilter>().mesh;
cmd = new CommandBuffer();
cmd.name = "customRender";
}
// Update is called once per frame
void Update() {
var cam = Camera.main;
cam.RemoveCommandBuffer(CameraEvent.AfterGBuffer,cmd);
cmd.Clear();
int idx =m_mat.FindPass("Deferred");
cmd.DrawMesh(m_mesh, m_object.transform.localToWorldMatrix, m_mat,0,idx);
cam.AddCommandBuffer(CameraEvent.AfterGBuffer, cmd);
}
}
PS: Forgot to mention that the very same DrawMesh works no problem if triggered from Graphics.DrawMesh.
3569658–287868–dummy.zip (253 KB)