• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by POLYGAMe · Jul 16, 2011 at 10:48 PM · meshwireframeretrovector graphics

Wireframe Rendering?

Hi guys and gals, I've looked around but can't seem to find any info on whether it's possible to have the main camera render in wireframe mode? I did find some stuff on Unity Pro but that doesn't help me :(

I'd quite like to do some cool retro stuff, a la Battlezone.

Is t$$anonymous$$s possible?

Comment
Chris D
MrVerdoux

People who like this

2 Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chris D · Jul 17, 2011 at 12:02 AM 4
Share

For those who have pro and wander into this question, it looks like there's an implementation available here.

avatar image Bunny83 · Jul 17, 2011 at 12:59 AM 1
Share

Actually the GL class works also with the indy version. I'm not sure if it's a bug since the docs states it's pro only but i used it a lot in the editor and also in indy-webbuilds.

avatar image POLYGAMe · Jul 17, 2011 at 02:23 AM 0
Share

I got one of the scripts working but it only displays black lines :( Can't seem to change it...

avatar image Bunny83 · Jul 17, 2011 at 03:35 AM 3
Share

If you had read the whole thread you would have noticed that the shaderlab syntax has changed (this thread is quite old). At the second page there is a post with the corrected line-material.

avatar image POLYGAMe · Jul 17, 2011 at 05:20 AM 0
Share

Thanks, Bunny! I don't know how I missed that! All working sweet, now :)

Show more comments

5 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Eric5h5 · Jul 17, 2011 at 01:38 AM

http://www.starscenesoftware.com/vectrosity.html

http://www.starscenesoftware.com/tankzone.html

Comment
Chris D
POLYGAMe
Herman-Tulleken

People who like this

3 Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image POLYGAMe · Jul 17, 2011 at 02:25 AM 0
Share

Thanks, I'll check it out. I didn't realise you could use it for pre-existing models, too. Very cool. Now I just have to raise the cash...lol. Is there a demo so I can check it out properly? I have to spend wisely, being a game student. LOL.

avatar image POLYGAMe · Jul 17, 2011 at 02:31 AM 0
Share

Just checked out the online demos... VERY NICE! I think I'll have to purchase when I can afford it ;-) Let's hope my first game sells so I can! LOL. This is EXACTLY what I want ;-)

avatar image Eric5h5 · Jul 17, 2011 at 02:34 AM 1
Share

@POLYGAMe: there are various demos on the Vectrosity page. If you mean a demo of the actual product, that's not really feasible. 99% of people who've bought it like it though. If it doesn't work for you, I'll give you a refund. It probably won't take long to find $20 worth of beer cans to recycle. ;)

avatar image POLYGAMe · Jul 17, 2011 at 03:07 AM 0
Share

Sounds good. I'll try scrounge up some cash (although you mentioned beer... wouldn't mind some of that, either) ;-)

avatar image POLYGAMe · Nov 05, 2012 at 04:05 AM 0
Share

Hi Eric... got sidetracked by new game project, which is selling quite well, so decided to buy your plugin. Does it support Unity 3.5? I have noticed that these scripts no longer do...

Cheers!

Show more comments
avatar image

Answer by POLYGAMe · Jul 17, 2011 at 05:25 AM

For anyone who stumbles across t$$anonymous$$s, here is the working script from the forums:

     // attach to an object with a mesh filter 
 //vers 12/11/2008
 
 var lineColor : Color; 
 var backgroundColor : Color; 
 var ZWrite = true; 
 var AWrite = true; 
 var blend = true; 
 
 private var lines : Vector3[]; 
 private var linesArray : Array; 
 private var lineMaterial : Material; 
 private var meshRenderer : MeshRenderer; 
 
 
 function Start () 
 { 
     renderer.enabled = false;
    meshRenderer = GetComponent(MeshRenderer); 
    if(!meshRenderer) meshRenderer = gameObject.AddComponent(MeshRenderer); 
    meshRenderer.material = new Material("Shader \"Lines/Background\" { Properties { _Color (\"Main Color\", Color) = (1,1,1,1) } SubShader { Pass {" + (ZWrite ? " ZWrite on " : " ZWrite off ") + (blend ? " Blend SrcAlpha OneMinusSrcAlpha" : " ") + (AWrite ? " Colormask RGBA " : " ") + "Lighting Off Offset 1, 1 Color[_Color] }}}"); 
     
 // Old Syntax without Bind :    
 //   lineMaterial = new Material("Shader \"Lines/Colored Blended\" { SubShader { Pass { Blend SrcAlpha OneMinusSrcAlpha ZWrite On Cull Front Fog { Mode Off } } } }"); 
 
 // New Syntax with Bind : 
    lineMaterial = new Material("Shader \"Lines/Colored Blended\" { SubShader { Pass { Blend SrcAlpha OneMinusSrcAlpha BindChannels { Bind \"Color\",color } ZWrite On Cull Front Fog { Mode Off } } } }"); 
     
    lineMaterial.$$anonymous$$deFlags = HideFlags.HideAndDontSave; 
    lineMaterial.shader.$$anonymous$$deFlags = HideFlags.HideAndDontSave; 
     
    linesArray = new Array(); 
    var filter : MeshFilter = GetComponent(MeshFilter); 
    var mesh = filter.sharedMesh; 
    var vertices = mesh.vertices; 
    var triangles = mesh.triangles; 
     
    for (i = 0; i < triangles.length / 3; i++) 
    { 
       linesArray.Add(vertices[triangles[i * 3]]); 
       linesArray.Add(vertices[triangles[i * 3 + 1]]); 
       linesArray.Add(vertices[triangles[i * 3 + 2]]); 
    } 
     
    lines = linesArray.ToBuiltin(Vector3); 
 } 
 
 
 function OnRenderObject() 
 {    
    meshRenderer.sharedMaterial.color = backgroundColor; 
    lineMaterial.SetPass(0); 
     
    GL.PushMatrix(); 
    GL.MultMatrix(transform.localToWorldMatrix); 
    GL.Begin(GL.LINES); 
    GL.Color(lineColor); 
     
    for (i = 0; i < lines.length / 3; i++) 
    { 
       GL.Vertex(lines[i * 3]); 
       GL.Vertex(lines[i * 3 + 1]); 
        
       GL.Vertex(lines[i * 3 + 1]); 
       GL.Vertex(lines[i * 3 + 2]); 
        
       GL.Vertex(lines[i * 3 + 2]); 
       GL.Vertex(lines[i * 3]); 
    } 
           
    GL.End(); 
    GL.PopMatrix(); 
 }
Comment
Fattie
jethrogillgren

People who like this

2 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GankMeXXX · Mar 07, 2014 at 06:32 AM 0
Share

also needs renderer with the mesh filter if adding to an empty game object

avatar image

Answer by reckless_glitch · Dec 09, 2013 at 05:01 PM

Hey guys, I prefer c# so I rewrote and uhm changed the script a bit it renders every line two times so now you can choose, w$$anonymous$$ch line of the triangles to render, w$$anonymous$$ch gives some kind of random but faster mesh, quite interesting too.

 using UnityEngine;
 using System.Collections;
 
 public class wireframe : MonoBehaviour {
 
     public bool render_mesh_normaly = true;
     public bool render_lines_1st = false;
     public bool render_lines_2nd = false;
     public bool render_lines_3rd = false;
     public Color lineColor = new Color (0.0f, 1.0f, 1.0f);
     public Color backgroundColor = new Color (0.0f, 0.5f, 0.5f);
     public bool ZWrite = true;
     public bool AWrite = true;
     public bool blend = true;
     public float lineWidth = 3;
     public int size = 0;
     
     private Vector3[] lines ;
     private ArrayList lines_List ;
     public Material lineMaterial ;
     //private MeshRenderer meshRenderer; 
 
     /*
     ████████       ▄▀▀■  ▀▀█▀▀  ▄▀▀▄  █▀▀▄  ▀▀█▀▀ 
     ████████       ▀■■▄    █    █■■█  █▀▀▄    █   
     ████████       ■▄▄▀    █    █  █  █  █    █   
     */
 
     
     void Start () {
         //meshRenderer = gameObject.GetComponent<MeshRenderer>();
         if (lineMaterial == null) {
             lineMaterial = new Material ("Shader \"Lines/Colored Blended\" {" +
                                         "SubShader { Pass {" +
                                         "   BindChannels { Bind \"Color\",color }" +
                                         "   Blend SrcAlpha OneMinusSrcAlpha" +
                                         "   ZWrite on Cull Off Fog { Mode Off }" +
                                         "} } }");
                 
             /*lineMaterial = new Material ("Shader \"Lines/Colored Blended\" {" +
                                         "SubShader { Pass {" +
                                         "    Blend SrcAlpha OneMinusSrcAlpha" +
                                         "    ZWrite Off Cull Front Fog { Mode Off }" +
                                         "} } }");*/
         }
         lineMaterial.$$anonymous$$deFlags = HideFlags.HideAndDontSave;
         lineMaterial.shader.$$anonymous$$deFlags = HideFlags.HideAndDontSave;
         lines_List = new ArrayList();
         
         MeshFilter filter  = gameObject.GetComponent<MeshFilter>();
         Mesh mesh = filter.mesh;
         Vector3[] vertices = mesh.vertices;
         int[] triangles = mesh.triangles;
         
         for (int i = 0; i+2 < triangles.Length; i+=3)
         {
             lines_List.Add(vertices[triangles[i]]);
             lines_List.Add(vertices[triangles[i + 1]]);
             lines_List.Add(vertices[triangles[i+ 2]]);
         }
         
         //lines_List.CopyTo(lines);//arrays are faster than array lists
         lines = (Vector3[]) lines_List.ToArray(typeof(Vector3));
         lines_List.Clear();//free memory from the arraylist
         size = lines.Length;
     }
     
     // to simulate t$$anonymous$$ckness, draw line as a quad scaled along the camera's vertical axis.
     void DrawQuad(Vector3 p1,Vector3 p2 ){
         float t$$anonymous$$sWidth = 1.0f/Screen.width * lineWidth * 0.5f;
         Vector3 edge1 = Camera.main.transform.position - (p2+p1)/2.0f;    //vector from line center to camera
         Vector3 edge2 = p2-p1;    //vector from point to point
         Vector3 perpendicular = Vector3.Cross(edge1,edge2).normalized * t$$anonymous$$sWidth;
         
         GL.Vertex(p1 - perpendicular);
         GL.Vertex(p1 + perpendicular);
         GL.Vertex(p2 + perpendicular);
         GL.Vertex(p2 - perpendicular);
     }
 
     Vector3 to_world(Vector3 vec)
     {
         return gameObject.transform.TransformPoint(vec);
     }
 
     /*
     ████████       █  █  █▀▀▄  █▀▀▄  ▄▀▀▄  ▀▀█▀▀  █▀▀▀ 
     ████████       █  █  █▀▀   █  █  █■■█    █    █■■  
     ████████       ▀▄▄▀  █     █▄▄▀  █  █    █    █▄▄▄ 
     */
     
 
     void OnRenderObject () {
         gameObject.renderer.enabled=render_mesh_normaly;
         if (lines == null || lines.Length < lineWidth) {
             print("No lines");
         } 
         else
         {
             lineMaterial.SetPass(0);
             GL.Color(lineColor);
             
             if (lineWidth == 1) {
                 GL.Begin(GL.LINES);
                 for(int i = 0; i+2 < lines.Length; i+=3)
                 {
                     Vector3 vec1 = to_world(lines[i]);
                     Vector3 vec2 = to_world(lines[i+1]);
                     Vector3 vec3 = to_world(lines[i+2]);
                     if(render_lines_1st){
                         GL.Vertex(vec1);
                         GL.Vertex(vec2);
                     }
                     if(render_lines_2nd){
                         GL.Vertex(vec2);
                         GL.Vertex(vec3);
                     }
                     if(render_lines_3rd){
                         GL.Vertex(vec3);
                         GL.Vertex(vec1);
                     }
                 }
             } else {
                 GL.Begin(GL.QUADS);
                 for(int i = 0; i+2 < lines.Length; i+=3) {
                     Vector3 vec1 = to_world(lines[i]);
                     Vector3 vec2 = to_world(lines[i+1]);
                     Vector3 vec3 = to_world(lines[i+2]);
                     if(render_lines_1st) DrawQuad(vec1,vec2);
                     if(render_lines_2nd) DrawQuad(vec2,vec3);
                     if(render_lines_3rd) DrawQuad(vec3,vec1);
                 }
             }
             GL.End();
         }
     }
 }
 
Comment
MrVerdoux
Glurth
rooftoppr
jethrogillgren
rad1c

People who like this

5 Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MrVerdoux · Dec 09, 2013 at 05:12 PM 0
Share

Works like a charm

avatar image Ryks · Apr 16, 2014 at 06:40 PM 0
Share

Since I can't bump you, here is a Thank You.

avatar image DillonRobinson · Jul 07, 2014 at 06:02 AM 0
Share

Beautiful. Just beautiful. Thank you so much. Going for a Tron-esque 80's sci fi lo-fi look for my title menu and this works great on making vectorized-looking models after I lowered their poly counts.

avatar image Glurth · Jan 27, 2015 at 12:39 AM 1
Share

I got it working in unity 4.6 with the following changes: public Material lineMaterial ; -- >remove "`public`" (don't want to set this manually, it never works- at least with MY materials)

cut the line: GL.Color(lineColor);

paste it under BOTH:

 GL.Begin(GL.LINES);

and

 GL.Begin(GL.QUADS);




avatar image Gekigengar · Apr 23, 2016 at 06:45 AM 1
Share

I am getting purple lines, the line color isn't working, any solution?

Show more comments
avatar image

Answer by supare · Jun 11, 2018 at 12:16 PM

If you don't mind having a fixed black colour for the triangles, you can use the inbuilt VR/SpatialMapping/Wireframe shader, available from 2017 onwards.

On standard displays, t$$anonymous$$s will draw a wireframe on top of black triangles. On AR displays like HoloLens, the triangles will be transparent, leaving the wireframe.

The advantage of t$$anonymous$$s approach is that there are no external dependencies and it works in seconds with any MeshFilter. I often use it for debugging procedural mesh generation scripts.

alt text


capture.png (18.1 kB)
Comment
rad1c
FlyingHighUp

People who like this

2 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by AlexTuduran · Sep 11, 2018 at 08:21 PM

@POLYGAMe You can use GL.wireframe = true;

https://docs.unity3d.com/ScriptReference/GL-wireframe.html

Comment
Bunny83

People who like this

1 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Sep 11, 2018 at 09:45 PM 0
Share

Right, but you have to use it in "OnPreRender". You can't just call it in update.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rendering mesh edges in-game just as they appear in editor mode 1 Answer

Is direct MeshRenderer vertex mutation (or dynamic Mesh building) possible? 2 Answers

Render wireframe on cut section of polygons 2 Answers

how can i build a spherical wireframe grid in unity? 1 Answer

How to see mesh in game mode ? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges