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
0
Question by triangle4studios · Feb 11, 2021 at 01:49 AM · shadermathverticeshlslwireframe

Wireframe Shader With Shared Lines Removed

I am working on this wireframe shader:

It uses some adapted code from various shaders, and I am wanting to get rid of the lines that cut through the quads. I really do not know how to go about this in HLSL and was wondering if someone could share their insight.

 Shader "WireframeShader"
 {
     Properties
     {
         [HDR] _EmissionColor("Color", Color) = (0,0,0)
            
         _EdgeThickness ("Edge Threshold", float) = .9
         _WireThickness ("Wire Thickness", RANGE(0, 800)) = 100
  }
 
     SubShader
     {
         Tags { "RenderType"="Opaque" }
 
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma geometry geom
             #pragma fragment frag
             #pragma multi_compile _ USEDISCARD_ON
             #include "UnityCG.cginc"
 
             float _WireThickness;
             fixed4 _EmissionColor;
             float _EdgeThickness;
 
             struct appdata
             {
                 float4 vertex : POSITION;
             };
 
             struct v2g
             {
                 float4 projectionSpaceVertex : SV_POSITION;
                 float4 worldSpacePosition : TEXCOORD1;
             };
 
             struct g2f
             {
                 float4 projectionSpaceVertex : SV_POSITION;
                 float4 worldSpacePosition : TEXCOORD0;
                 float4 dist : TEXCOORD1;
             };
 
             
             v2g vert (appdata v)
             {
                 v2g o;
                 o.projectionSpaceVertex = UnityObjectToClipPos(v.vertex);
                 o.worldSpacePosition = mul(unity_ObjectToWorld, v.vertex);
                 return o;
             }
             
             [maxvertexcount(3)]
             void geom(triangle v2g i[3], inout TriangleStream<g2f> triangleStream)
             {
                 float2 p0 = i[0].projectionSpaceVertex.xy / i[0].projectionSpaceVertex.w;
                 float2 p1 = i[1].projectionSpaceVertex.xy / i[1].projectionSpaceVertex.w;
                 float2 p2 = i[2].projectionSpaceVertex.xy / i[2].projectionSpaceVertex.w;
 
                 float2 edge0 = p2 - p1;
                 float2 edge1 = p2 - p0;
                 float2 edge2 = p1 - p0;
 
                 float area = abs(edge1.x * edge2.y - edge1.y * edge2.x);
                 float wireThickness = 800 - _WireThickness;
 
                 g2f o;
                 o.worldSpacePosition = i[0].worldSpacePosition;
                 o.projectionSpaceVertex = i[0].projectionSpaceVertex;
                 o.dist.xyz = float3( (area / length(edge0)), 0.0, 0.0) * o.projectionSpaceVertex.w * wireThickness;
                 o.dist.w = 1.0 / o.projectionSpaceVertex.w;
                 triangleStream.Append(o);
 
                 o.worldSpacePosition = i[1].worldSpacePosition;
                 o.projectionSpaceVertex = i[1].projectionSpaceVertex;
                 o.dist.xyz = float3(0.0, (area / length(edge1)), 0.0) * o.projectionSpaceVertex.w * wireThickness;
                 o.dist.w = 1.0 / o.projectionSpaceVertex.w;
                 triangleStream.Append(o);
 
                 o.worldSpacePosition = i[2].worldSpacePosition;
                 o.projectionSpaceVertex = i[2].projectionSpaceVertex;
                 o.dist.xyz = float3(0.0, 0.0, (area / length(edge2))) * o.projectionSpaceVertex.w * wireThickness;
                 o.dist.w = 1.0 / o.projectionSpaceVertex.w;
                 triangleStream.Append(o);
             }
 
             fixed4 frag (g2f i) : SV_Target
             {
                 float minDistanceToEdge = min(i.dist[0], min(i.dist[1], i.dist[2])) * i.dist[3];
                 if(minDistanceToEdge > _EdgeThickness)
                 {
                     discard;
                     return (0,0,0,0);
                 }
                 return _EmissionColor;
             }
             ENDCG
         }
     }
 }
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

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.

Follow this Question

Answers Answers and Comments

179 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How is _WorldSpaceLightPos0 calculated for a directional light? 0 Answers

Mathf.Repeat in ShaderLab? 1 Answer

Why color not rendering in my shader? 0 Answers

Shader shows odd Simplex Noise behavior on Android 0 Answers

(Shader)How to find the cordinate of a given color inside a ramp texture? 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