• 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
2
Question by asafsitner · Oct 22, 2012 at 09:58 AM · terrainshaderstreesbillboards

Terrain Tree Billboard have bright outline against dark background

This is a question I have the answer for, and it's more fitting to Unity Answers than the forums.

When placing trees on the terrain using the terrain engine, the trees, when becoming billboards, have a bright 'glow' outline to them.

This is something that bothered my team for a long time, and we haven't found any information about it online. To illustrate the problem:

tree outline problem and solution

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

6 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by asafsitner · Oct 22, 2012 at 09:58 AM

We figured out the problem was with the alpha-blending part of the shader, and it was extremely easy to fix. We just downloaded the built-in terrain billboard shader and added the following line of code: `AlphaTest Greater 0.9` after the blending mode definition `Blend SrcAlpha OneMinusSrcAlpha`

You can find the Fixed shader here: Just copy and paste this into a shader file and you're done.

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 Enno · Aug 08, 2013 at 08:43 PM 1
Share

FINALLY! Thank you so much for sharing this fix. I've been searchin for hours and hours, and this has finally resolved my issue. Thanks!

avatar image asafsitner · Aug 08, 2013 at 09:05 PM 0
Share

@$$anonymous$$no - That's great to hear! We're very happy that this actually helped someone :D

avatar image Temka193 · Mar 02, 2014 at 04:00 PM 0
Share

Unfortunately for me, this shader did worse. I lush trees, and after applying this shader they have almost no leaves. How to fix it?

avatar image
1

Answer by BTables · Oct 21, 2015 at 04:46 AM

I just ran into this problem when switching to linear lighting in unity 5.

The above solution didn't solve it, after much digging it turns out the background color of the render texture unity uses for tree billboards isn't black (it's (0.025,0.025,0.025)).

In gamma space this doesn't present itself as a problem. However in linear space, this is converted to gamma space at the end of the render pipeline bringing it to a much more visible grey (0.19,0.19,0.19)

To solve this I modified the TreeCreatorLeavesRendertex.shader to convert the billboard render texture to an approximation of gamma color space with

 c.rgb = sqrt(c.rgb);
 c.rgb = max(c.rgb,0.025); //Ensure our tree is never rendered darker than the background color

towards the end of the fragment shader

Then do the opposite operation in the BillboardTree.shader

 col.rgb = col.rgb * col.rgb;

Not a perfect solution, but will work for us until speedtree stops performing so poorly

Comment
Add comment · Show 1 · 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 Loishtc · Oct 24, 2015 at 11:27 AM 0
Share

Where to exactly paste this?!?!?! can you please paste the full code sir?

avatar image
1

Answer by mitaywalle · Jul 04, 2016 at 01:30 PM

[UPDATED 22.03.17] I've used this shader, plus:

  1. TOD_TreeBillboardState. Means need to Colorize or not (Night or Day), set through Shader.SetGlobalFloat

  2. TOD_TreeBillboardColor. Which Color to use for fill. Uses white-to-black Gradient, based on Night-time. Set through Shader.SetGlobalColor

Gradient t instructions:

 if (Cycle.Hour > 17f)
        t = Mathf.Lerp(0f, .5f, (Cycle.Hour - 17f) / 7f);
 else
        t = Mathf.Lerp(.5f, 1f, Cycle.Hour / 7f);

!All is Updating every frame, with day-night-cycle script. No performance problems.

 Shader "Hidden/TerrainEngine/BillboardTree" {
     Properties {
         _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
     }
     
     SubShader {
         Tags { "Queue" = "Transparent-1" "IgnoreProjector"="True" "RenderType"="TransparentCutout" }
         Pass {
             Tags { "RequireOption" = "SoftVegetation" }
 
             // Dont write to the depth buffer
             ZWrite off
         
             // Set up alpha blending
             Blend SrcAlpha OneMinusSrcAlpha
             Cull Front
             CGPROGRAM
             #pragma vertex vert 
             #pragma fragment frag
             #pragma multi_compile_fog
             #include "UnityCG.cginc"
             #include "TerrainEngine.cginc"
 
             Float TOD_TreeBillboardState;
             fixed4 TOD_TreeBillboardColor;
 
             struct v2f {
                 float4 pos : SV_POSITION;
                 fixed4 color : COLOR0;
                 float2 uv : TEXCOORD0;
                 UNITY_FOG_COORDS(1)
             };
 
             v2f vert (appdata_tree_billboard v) {
                 v2f o;
                 TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);    
                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                 o.uv.x = v.texcoord.x;
                 o.uv.y = v.texcoord.y > 0;
                 o.color = v.color;
                 UNITY_TRANSFER_FOG(o,o.pos);
                 return o;
             }
 
             sampler2D _MainTex;
             fixed4 frag(v2f input) : SV_Target
             {
                 fixed4 col = tex2D( _MainTex, input.uv);
                 if (TOD_TreeBillboardState > .5)
                     if (col.r < .18 && col.a < .9)
                         col.rgb *= TOD_TreeBillboardColor.rgb;
                 col.rgb *= input.color.rgb;
                 clip(col.a);
                 UNITY_APPLY_FOG(input.fogCoord, col);
                 return col;
             }
             ENDCG            
         }
         Pass {
             Cull Front
             CGPROGRAM
             #pragma vertex vert 
             #pragma fragment frag
             #pragma multi_compile_fog
             #include "UnityCG.cginc"
             #include "TerrainEngine.cginc"
 
             struct v2f {
                 float4 pos : SV_POSITION;
                 fixed4 color : COLOR0;
                 float2 uv : TEXCOORD0;
                 UNITY_FOG_COORDS(1)
             };
 
             v2f vert (appdata_tree_billboard v) {
                 v2f o;
                 TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);    
                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                 o.uv.x = v.texcoord.x;
                 o.uv.y = v.texcoord.y > 0;
                 o.color = v.color;
                 UNITY_TRANSFER_FOG(o,o.pos);
                 return o;
             }
 
             sampler2D _MainTex;
             fixed4 frag(v2f input) : SV_Target
             {
                 fixed4 col = tex2D( _MainTex, input.uv);
                 col.rgb *= input.color.rgb;
                 clip(col.a - .99);
                 UNITY_APPLY_FOG(input.fogCoord, col);
                 return col;
             }
             ENDCG            
         }
     }
     Fallback Off
 }
Comment
Add comment · Show 2 · 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 UrielKane · Sep 14, 2016 at 10:35 AM 0
Share

Well it does actually improve a little bit the billboard problem but it doesn't fix it at all. I mean the outline alpha issue persist it just become dark rather than white wich is not a definitive fix. I'm start to think i'm going to change between the two shaders acording the day/night cycle. I'm not a shader writer at all so i don't know if it's actually possible to pick the light color or something like that and use that to fade the alpha issue.

avatar image Glcomar · Jan 04, 2017 at 05:19 PM 0
Share

Thanks man, i take ur code and modify that part:

if (col.a < .99f && col.r <.2f) col.rgb *= 0.0020;

$$anonymous$$y trees ok now)

avatar image
1

Answer by TimNick151297 · Apr 17, 2017 at 01:16 PM

Another pretty simple solution for that is changing the alpha cutout directly in the shader. Simply go to "clip(col.a)" and add -0.9 to it. This will increase the cutout and removes the grey outline.

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

Answer by Brandon_Lindberg · Dec 11, 2014 at 07:31 PM

An easy way to fix this is to go to terrain settings and change the billboard to about halfway, and if it still appears, put it up all the way.

Comment
Add comment · Show 1 · 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 _invalidusername · Nov 15, 2015 at 01:55 PM 2
Share

You mean increase the billboard start distance? That's not a fix, that's just moving the problem further away, and your performance will take a serious knock

  • 1
  • 2
  • ›

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

20 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

Related Questions

Why doesn't built-in Nature->SoftOcclusion->Leaves/Bark support spot lighting? 0 Answers

Terrain system trees slightly sharpen and blur depending on camera rotation 2 Answers

Terrain Trees remain lit up when no light is cast 1 Answer

How to hide Unity terrain trees when they are blocking the camera view? 0 Answers

Terrain surfaceshader, or terrain shader supporting multiple lights - need example 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