Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Pipding · Feb 09, 2016 at 03:09 PM · 2dtrailrenderer

Trail Renderer overlap changes trail colour

In this simple game I have a ball with a trail renderer. The problem is that when the ball changes direction and the trail overlaps with itself, the colour of the trail changes. I'm trying to keep the trail one uniform colour because as you can see, the change looks quite ugly. Is there a setting I'm missing in the trail renderer to disable this behaviour or will I have to write a script to stop it?

Thanks for any help!

(In this image the ball has just bounced off the left-hand side of the screen)

alt text

traildiscolour.png (15.4 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Katzelschnurr · Aug 10, 2016 at 11:48 AM

You could try using this shader: (just ignore the commented zExtrusion part)

 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 · Show 4 · 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 AlexanderTeaH · Dec 14, 2017 at 08:18 PM 0
Share

Thank you! Worked flawlessly.

avatar image Hugo-Bille · Aug 23, 2018 at 02:58 PM 0
Share

Every time I start a project I end up trying to solve this problem, and every time I give up. There's so little discussion about it, and the improved trail renderers on the Asset Store don't help either. This shader is the closest I've come to a solution, but it seems to me that it trades one problem for another, at least if you're using a semitransparent texture in your trail material. The alpha now overrides earlier pixels whenever the trail crosses itself or another similar trail (see image). Can anyone think of a shader that is free from both of these issues? I imagine it would help a lot of people like me to get more use out of the trail and line renderers...

ztest.png (53.9 kB)
avatar image Tortuap Hugo-Bille · Feb 25 at 10:58 AM 0
Share

Yes you could use a shader that test over a stencil buffer for that.

avatar image Tortuap · Feb 25 at 10:56 AM 0
Share

Thank you! Thank you! Thank you! I didn't think of that.. I was blindly looking for a Trail Renderer system on asset store that could avoid overlap when constructing the geometry. I was so wrong! Thank you!

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

7 People are following this question.

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

Related Questions

Unity Trail for Eyes 2D 0 Answers

Can't get a smooth following line 1 Answer

Want to do an on-hit effect for a trail renderer in 2D 0 Answers

Collition Coding not working 1 Answer

Can the new ParticleSystem Trigger Module access the particle's collision collider? 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