Unity's Official tutorial: https://blogs.unity3d.com/cn/2015/02/06/extending-unity-5-rendering-pipeline-command-buffers/
A demo project is included at the bottom of the article
Changed with the official example, as a test script
usingUnityengine;usingunityengine.rendering;usingSystem.Collections;usingSystem.Collections.Generic; Public classtest:monobehaviour{ PublicMesh Testmesh; PublicMaterial testmaterial; Dictionary<camera, commandbuffer> M_cameras =NewDictionary<camera, commandbuffer>(); voidondisable () {foreach(varCaminchM_cameras) { if(Cam. Key) {cam. Key.removecommandbuffer (cameraevent.beforelighting, Cam. Value); } } } voidlateupdate () {varact = gameobject.activeinhierarchy &&enabled; if(!Act) {ondisable (); return; } varCam =camera.current; if(!Cam)return; Commandbuffer buf=NULL; if(M_cameras.containskey (CAM)) {buf=M_cameras[cam]; Buf. Clear (); } Else{buf=NewCommandbuffer (); Buf.name="Test Command Buffer"; M_cameras[cam]=buf; Cam. Addcommandbuffer (Cameraevent.afterfinalpass, buf); } buf. DrawMesh (Testmesh, Matrix4x4.trs (Camera.main.transform.position+ Camera.main.transform.forward *4f, Quaternion.identity, Vector3.one), testmaterial); }}
View Code
The script is simple and draws a mesh after Finalpass
Commandbuffer supports deferred rendering and forward rendering, but it is important to note that if deferred rendering events such as Cameraevent.aftergbuffer are used in forward rendering, this will not work.
Unity's framedebug can be debugged on Commandbuffer
Be free and perfect
Unity Commandbuffer Learning