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 ozturkcompany · Apr 04, 2015 at 02:48 PM · linerenderer

Trail and line renderer causes dirty looking lines on curves

Hello, I am working on a small project by myself. The goal is to draw graphs of math functions on mobile. I have three ways of doing it but couldn't decide which one to go with. Here are those; 1) This is the simplest solution that i have found but cannot guess if would it be so heavy for mobile. Since a line is a collection of dots, i've been thinking to draw lines using small quad meshes. Instantiating thousands of quad meshes along the path and create a line. 2)Using the line renderer which is almost the same with trail renderer. 3)Using the trail renderer which an empty gameobject will move along the path of the curve to create trail that will represent a line afterwards.

Also i have one problem that is caused by the particle additive shader. The problem is where the curve occurs there are some dirty looking straight lines because of the shader itself is transparent somehow. I set all the alpha values to 255 but it doesn't solve the dirty look. Any ideas? Thank you in advance! alt text

asond.jpg (151.4 kB)
Comment
Add comment · Show 7
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 Owen-Reynolds · Apr 04, 2015 at 05:08 PM 1
Share

Those little lines can only be fixed by turning off transparency. The mesh is build using quads(?). Those are caused by tiny backwards quads, and partly overlapping quads, inside the same mesh, on sharp bends. Since two faces overlap, transparency double-colors them.

A fix, which is tricky if you already know how, otherwise a huge pain, is to code a hand-built mesh, which "knows" the fan-sections and fixes the ends.

I suspect, as you do, that lineRender and trailRenderer are about the same. Approach #1 sounds horrendous.

Also, probably depends on the equation for these lines (is that really a saw-tooth? Or a sin wave?)

avatar image ozturkcompany · Apr 04, 2015 at 06:22 PM 0
Share

Hello, thank you for your reply. It is a sin wave in the screenshot. I understand now why those dirty little lines appear BUT i really don't know where to turn off transparency. If i set the alpha to 0 then no colors seems to be appearing if is set it to 255(or any other value) then these dirty lines appear. I am comfortable with all of the 3 way but i've tested that approach#1 is so heavy for a mobile and the line sometimes uncontinuous. Is there any 4th way of drawing lines? I've been thinking about it but cannot find any other way atm. And definetely i don't know how to make a custom mesh either :)

avatar image Glurth · Apr 05, 2015 at 03:37 PM 0
Share

Transparency is a shader/material option, if you change to an opaque shader of that material those glitches should go away.

One option you didn't mention, though I doubt it would look as good, and wouldn't plot more than 2 axis: you can draw the curve on a 2dtexture, and apply that to a plane or some 3D object, as a material.

Personally, I would create a custom mesh. The samples on this page showed me how to make my own. http://wiki.unity3d.com/index.php/ProceduralPrimitives

(I would draw a ring of X verticies around each computed point, perpendicular to the direction(slope) of the function at that point. )

avatar image ozturkcompany · Apr 05, 2015 at 03:55 PM 0
Share

I think that the best way of doing it is creating a custom mesh as you mentioned. Looking at the link you shared right now. Thank you!

avatar image ozturkcompany · Apr 05, 2015 at 04:01 PM 0
Share

Wow i need a few days to understand this...

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Katzelschnurr · Aug 10, 2016 at 07:53 PM

maybe try this shader: (just ignore the commented zExtrusion :) )

 Shader "TrailWithZWrite" {
     Properties{
         _Color("Main Color", Color) = (1,1,1,0.5)
         _AlphaTex("Base (RGB) Trans (A)", 2D) = "white" {}
         //_ExtrusionAmount("Z Extrusion Amount", Float) = 0
     }
         SubShader{
             Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
             LOD 100
 
             ZWrite On
             ZTest Less
             Blend SrcAlpha One
             //Offset 0, -5000
 
         Pass{
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             fixed4 _Color;
             sampler2D _AlphaTex;
             //float _ExtrusionAmount;
             float4 _AlphaTex_ST;
 
             struct v2f {
                 float4 pos : SV_POSITION;
                 half4 color : COLOR0;
                 float2 uv : TEXCOORD0;
             };
 
             v2f vert(appdata_full v)
             {
                 v2f o;
 
                 //float3 camDirObjSpace = normalize(ObjSpaceViewDir(v.vertex));
                 //v.vertex.xyz += _ExtrusionAmount * camDirObjSpace;
                 o.color = v.color;
 
                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.uv = TRANSFORM_TEX(v.texcoord, _AlphaTex);
                 return o;
             }
 
             fixed4 frag(v2f i) : SV_Target
             {
                 fixed4 texcol = tex2D(_AlphaTex, i.uv) * i.color;
                 return texcol * _Color;
             }
             ENDCG
         }
     }
     FallBack "Unlit/Transparent Cutout"
 }
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

22 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

Related Questions

Different materials in line renderer and antialiasing 0 Answers

LineRenderer draw every second line 2 Answers

Linerenderer circle not drawing as expected 3 Answers

Draw line in runtime 1 Answer

Raycasting, How to draw a line to the position of the rays end when nothing is hit 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