• 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 AA8A5 · Aug 17, 2015 at 10:50 AM · shaderwireframe

Wireframe shader line width

Hi everyone, I need to add line width to this shader, how can I do it? And how can I add fog to it? ANother question is will this shader work on mobile devices? Thanks!

 Shader "Custom/Wireframe" 
 {
     Properties 
     {
         _WireColor("WireColor", Color) = (1,0,0,1)
         _Color("Color", Color) = (1,1,1,1)
     }
     SubShader {       
         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
         Blend SrcAlpha OneMinusSrcAlpha
 
         Pass 
         {
 
             CGPROGRAM
             #include "UnityCG.cginc"
             #pragma target 4.0
             #pragma vertex vert
             #pragma geometry geom
             #pragma fragment frag
             
             
             half4 _WireColor, _Color;
         
             struct v2g 
             {
                 float4  pos : SV_POSITION;
                 float2  uv : TEXCOORD0;
             };
             
             struct g2f 
             {
                 float4  pos : SV_POSITION;
                 float2  uv : TEXCOORD0;
                 float3 dist : TEXCOORD1;
             };
 
             v2g vert(appdata_base v)
             {
                 v2g OUT;
                 OUT.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                 OUT.uv = v.texcoord; //the uv's arent used in this shader but are included in case you want to use them
                 return OUT;
             }
             
             [maxvertexcount(3)]
             void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream){
             
                 float2 WIN_SCALE = float2(_ScreenParams.x/2.0, _ScreenParams.y/2.0);
                 
                 //frag position
                 float2 p0 = WIN_SCALE * IN[0].pos.xy / IN[0].pos.w;
                 float2 p1 = WIN_SCALE * IN[1].pos.xy / IN[1].pos.w;
                 float2 p2 = WIN_SCALE * IN[2].pos.xy / IN[2].pos.w;
                 
                 //barycentric position
                 float2 v0 = p2-p1;
                 float2 v1 = p2-p0;
                 float2 v2 = p1-p0;
                 //triangles area
                 float area = abs(v1.x*v2.y - v1.y * v2.x);
             
                 g2f OUT;
                 OUT.pos = IN[0].pos;
                 OUT.uv = IN[0].uv;
                 OUT.dist = float3(area/length(v0),0,0);
                 triStream.Append(OUT);
 
                 OUT.pos = IN[1].pos;
                 OUT.uv = IN[1].uv;
                 OUT.dist = float3(0,area/length(v1),0);
                 triStream.Append(OUT);
 
                 OUT.pos = IN[2].pos;
                 OUT.uv = IN[2].uv;
                 OUT.dist = float3(0,0,area/length(v2));
                 triStream.Append(OUT);                
             }
             
             half4 frag(g2f IN) : COLOR
             {
                 //distance of frag from triangles center
                 float d = min(IN.dist.x, min(IN.dist.y, IN.dist.z));
                 //fade based on dist from center
                  float I = exp2(-4.0*d*d);
                  
                  return lerp(_Color, _WireColor, I);                
             }
             ENDCG
 
         }
     }
 }
Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to Use the Barymetric Wireframe Shader 2 Answers

Why color not rendering in my shader? 0 Answers

Wireframe Shader With Shared Lines Removed 0 Answers

Create a Wireframe Shader with Shader Forge 1 Answer

My custom shader doesn't render in wireframe 0 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