Unity Commandbuffer Learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.