GL is more powerful, but there are fewer open interfaces in unity. (Personal Edition is not available)
I am using two cameras in the project, one set to the ambiguous mode, render to Rendertexture, and another render main scene.
1 Public classGlline:monobehaviour2 {3 /*GL is relatively low-level , difficult to control, unity Open Interface is not many, can not use much,4 * have time to continue studying in-depth study5 *6 */7 PrivateList<vector3>Linepos;8 Private BOOLStartdraw =false;9 PrivateVector3 oldmouseposition;Ten Public floatStepsize = 80f;//step of each difference One Public floatsize = 60f;//width of each individual module A PublicMaterial linematerial; - PublicColor color =color.red; - Public floatRoud = -; the - voidStart () - { - +Linepos =NewList<vector3>(); - + A } at - voidUpdate () - { - if(Input.getmousebuttondown (0)) - { -Oldmouseposition =input.mouseposition; incolor =color.red; -Startdraw =true; to } + if(Input.getmousebuttonup (0)) - { theStartdraw =false; *Linepos.clear ();//Clean drawing points, otherwise each frame will be redrawn $ }Panax Notoginseng if(Input.getmousebuttondown (1)) - { theOldmouseposition =input.mouseposition; +Startdraw =true; Acolor =Color.White; the } + if(Input.getmousebuttonup (1)) - { $Startdraw =false; $Linepos.clear ();//Clean drawing points, otherwise each frame will be redrawn - } - if(Startdraw) the { - if(Stepsize = =0)return;Wuyi varNewmouseposition =(Vector2) input.mouseposition; the if(Vector2.distance (Newmouseposition, oldmouseposition) < size)return; - floatStepcount = Vector2.distance (oldmouseposition, newmouseposition)/stepsize +1; Wu for(inti =0; i < Stepcount; i++) - { About varSubmouseposition = Vector3.lerp (oldmouseposition, newmouseposition, I/stepcount); $ Linepos.add (submouseposition); - } -Oldmouseposition =newmouseposition; - A } + the - $ the the } the /// <summary> the ///Automatic engine invocation - /// </summary> in Public voidOnrenderobject () the { the GL. Pushmatrix (); AboutLinematerial.setpass (0); the for(inti =0; I < Linepos.count-1; i++) the { theVector3 startpos =Linepos[i]; +Vector3 Endpos = linepos[i +1]; - Drawlinefun (startpos.x, Startpos.y, endpos.x, endpos.y); the }Bayi GL. Popmatrix (); the the } - voidDrawlinefun (floatX1,floatY1,floatX2,floaty2) - { the theDrawRect (X1-roud, Y1-roud,2*Roud, color); the } the - voidDrawRect (floatXfloatYfloatwidth, Color mycolor) the { the the floatHeight =width;94 //Drawing 2D Images the GL. Loadortho (); the GL. Begin (GL. QUADS); the GL. Color (MyColor);98Gl. TexCoord3 (0,0,0);//set the Paste picture to remove when solid color AboutGl. Vertex3 (X/screen.width, Y/screen.height,0); -Gl. TexCoord3 (0,1,0);//set the Paste picture to remove when solid color101Gl. Vertex3 (X/screen.width, (y + height)/screen.height,0);102Gl. TexCoord3 (1,1,0);//set the Paste picture to remove when solid color103Gl. Vertex3 ((x + width)/screen.width, (y + height)/screen.height,0);104Gl. TexCoord3 (1,0,0);//set the Paste picture to remove when solid color theGl. Vertex3 ((x + width)/screen.width, Y/screen.height,0);106 GL. End ();107 108 }109}
Specific Code
Unity3d Brush Implementation Series 02-UNITYGL