Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by pipercubjl · Aug 28, 2012 at 03:20 PM · shaderwireframe

How to Use the Barymetric Wireframe Shader

I want to have the game render wireframes, and I saw this shader on the wiki. I tried putting it in a .shader but it doesn't work. On the wiki it said something about mesh.uv but I couldn't find any info on this. Any help would be appreciated.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Phastin · Mar 22, 2013 at 02:33 PM

I've tested the following shader in Unity 4. It will draw a correct wireframe on the standard Unity objects like cubes and planes. Since it draws lines where the texture coordinates are near 0 or 1, it wouldn't give you the desired result when applied to more complex meshes, but unlike the other solutions offered, it will at least work in simple cases. =)

 Shader "Custom/WireFrame"
 {
  Properties
  {
    _LineColor ("Line Color", Color) = (1,1,1,1)
    _GridColor ("Grid Color", Color) = (1,1,1,0)
    _LineWidth ("Line Width", float) = 0.2
  }
  SubShader
  {
    Pass
    {
      Tags { "RenderType" = "Transparent" }
      Blend SrcAlpha OneMinusSrcAlpha
      AlphaTest Greater 0.5
 
      CGPROGRAM
      #pragma vertex vert
      #pragma fragment frag
 
      uniform float4 _LineColor;
      uniform float4 _GridColor;
      uniform float _LineWidth;
 
      // vertex input: position, uv1, uv2
      struct appdata
      {
        float4 vertex : POSITION;
        float4 texcoord1 : TEXCOORD0;
        float4 color : COLOR;
      };
 
      struct v2f
      {
        float4 pos : POSITION;
        float4 texcoord1 : TEXCOORD0;
        float4 color : COLOR;
      };
 
      v2f vert (appdata v)
      {
        v2f o;
        o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
        o.texcoord1 = v.texcoord1;
        o.color = v.color;
        return o;
      }
 
      fixed4 frag(v2f i) : COLOR
      {
        fixed4 answer;
 
        float lx = step(_LineWidth, i.texcoord1.x);
        float ly = step(_LineWidth, i.texcoord1.y);
        float hx = step(i.texcoord1.x, 1.0 - _LineWidth);
        float hy = step(i.texcoord1.y, 1.0 - _LineWidth);
 
        answer = lerp(_LineColor, _GridColor, lx*ly*hx*hy);
 
        return answer;
      }
      ENDCG
     }
  } 
  Fallback "Vertex Colored", 1
 }
Comment
Add comment · Show 3 · 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 · Mar 22, 2013 at 02:40 PM 1
Share

Btw, take a look at the discussion page of the wiki page ;) I've posted an webplayer with unityPackage and some variants of the shader.

avatar image DmitryKanunnikoff · Dec 15, 2017 at 02:08 PM 0
Share

Thank you very much!

avatar image DmitryKanunnikoff · Dec 17, 2017 at 02:53 PM 0
Share

Unfortunately on Android the result looks different - solid pink without edges...

avatar image
0

Answer by ScroodgeM · Aug 28, 2012 at 09:41 PM

this shader works fine with little fixes (below is full shader)

is just used second UV to draw grid. second UV can be done in rather any 3d modelling app and even in unity programmatically. attach it to primitives like plane or cube to see how it works

Shader "BarycentricWireframeUv1" { Properties { _LineColor ("Line Color", Color) = (1,1,1,1) _GridColor ("Grid Color", Color) = (0,0,0,0) _LineWidth ("Line Width", float) = 0.1 } SubShader { Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag

uniform float4 _LineColor; uniform float4 _GridColor; uniform float _LineWidth;

// vertex input: position, uv1, uv2 struct appdata { float4 vertex : POSITION; float4 texcoord1 : TEXCOORD1; float4 color : COLOR; };

struct v2f { float4 pos : POSITION; float4 texcoord1 : TEXCOORD1; float4 color : COLOR; };

v2f vert (appdata v) { v2f o; o.pos = mul( UNITY_MATRIX_MVP, v.vertex); o.texcoord1 = v.texcoord1; o.color = v.color; return o; }

fixed4 frag(v2f i) : COLOR { fixed4 answer; if (i.texcoord1.x < _LineWidth || i.texcoord1.y < _LineWidth) { answer = _LineColor; } else if ((i.texcoord1.x - i.texcoord1.y) < _LineWidth && (i.texcoord1.y - i.texcoord1.x) < _LineWidth) { answer = _LineColor; } else { answer = _GridColor; } return answer; } ENDCG } } Fallback "Vertex Colored", 1 }

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

My custom shader doesn't render in wireframe 0 Answers

Create a Wireframe Shader with Shader Forge 1 Answer

How to make vector monitor graphics in Unity? 3 Answers

Wireframe Shader With Shared Lines Removed 0 Answers

Shader supersampling 1 Answer


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