Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

SpeedTree shader broken ?

Discussion in '5.4 Beta' started by AdamGoodrich, Apr 22, 2016.

  1. dreyhal

    dreyhal

    Unity Technologies

    Joined:
    Jan 5, 2016
    Posts:
    15
    @makeshiftwings Take a look at shading mode-> Deferred -> Normal. You will see the normals exactly as they are and you will see what I mean.
     
    Last edited: Jun 15, 2016
  2. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    I see, but honestly I can't tell what the normals "should" look like just by color. But they look fine; I don't understand what about them causes the leaf to wash out only when the camera is looking towards the directional light. Since the normals are somewhat random, shouldn't there be washed out leaves from every angle? Specular reflections on regular objects seem to look pretty similar when looking at something while facing towards the directional light or in the exact opposite direction away from the directional light. But with leaves it is completely different: towards the light results in wash out, away from the light looks totally fine.

    Edit: Wait, I see what you mean I think. It's basically acting like it's at a grazing angle with the light when you're looking towards it, regardless of the actual facing of the leaf itself; I assume because the normals are pointed upwards parallel to the leaf instead of out of it.
     
    Last edited: Jun 15, 2016
  3. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    Well rather than turn off specularity, couldn't you just get rid of the normal map on the leaves, and have them use their actual normals?
     
  4. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    Or turn off just the fresnel contribution? Is that a thing that can be done?
     
  5. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    Sorry about the spam of posts but I want to make sure I know what's going on. Am I right that the main problem is that because the normals on leaves can be all over the place, lots of leaves have normals that are parallel (or nearly parallel) to their actual plane rather than sticking out of it, and this means that you get fresnel reflection as if it were at a grazing angle when it's actually facing you? If so, why doesn't this problem show up in any other engines or games that use SpeedTree with PBR shaders?
     
  6. camel82106

    camel82106

    Joined:
    Jul 2, 2013
    Posts:
    304
    @dreyhal
    1. So I would like to ask you guys. Can you make comparisons like the first one in this topic? Just to make sure that you don't have any difference? Because if you still don't have any, then we will just figure out why it is not applying for you.
    Will do it later. I hope that tomorrow.
    2. What DX version do you use?
    DX11 but I have tried DX9 now with same result
    3. @camel82106 these dark spots that you see are very weird. It seems like a different problem to me. If you could provide me a link to some repro package, I would gladly take a look.
    It's not that easy as I have relative killer big project. 21GB without compression. Usually support give me access to cloud where I upload project. Is it possible? Of course I will gladly collaborate.

    4. Do you render with shadows?
    Yes,here is comparison. Without shadows it's even worse. I have disabled all image effects in these screenshots:
    shadows on

    shadows off


    And yes forward rendering fixes it. But that is not very nice thing to change in actual phase of project...

    P.S.:
    it looks like that problem with too light and too dark areas is very specific for scots pine speedtree. I have tried default one from store too. And it's there. I have tried some white oaks and it's more consistent there. Bad but less visible.

    @Dannyoakes Maybe someone from speedtree would see what is specific for scots pine?
     
  7. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    I can try later today; it takes like a half hour to recompile the shaders so at the moment I can't. But I thought this was to fix the washed out leaves, so if this fix does nothing about that it's probably not what I was looking for.

    DX 11.

    Yes, my example screenshot with the white leaves was with full shadows, Ambient Occlusion baked on the SpeedTree, and an additional ambient obscurance effect on the camera. Still way too noticeable, in my opinion.
     
  8. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    Also, how did Alloy get it to work?
     
  9. uiniti

    uiniti

    Joined:
    Feb 4, 2015
    Posts:
    74
    Before (ingame)


    Now (editor)


    1. Better comparison tomorrow,
    2. DX11
    4. trees receive shadows they don't cast them.
     
    dreyhal likes this.
  10. dreyhal

    dreyhal

    Unity Technologies

    Joined:
    Jan 5, 2016
    Posts:
    15
    Thanks for the info flow. So let's kill specular on all away facing normals and be done with it. The change below.

    In UnityStandardBRDF.cginc find one more line, this one:
    Code (CSharp):
    1. specularTerm = max(0, specularTerm * nl);
    and ADD this one after it:
    Code (CSharp):
    1. specularTerm *= pow(saturate(1.0f + dot(normal, viewDir)), 4.0);
    The downside of this hasty solution is that you will pay the cost of these instructions for all pixels being lit with BRDF. But we will think about making that smarter later.

    Remember to clear your shader cache again, and restart Unity.

    As previously - really happy to hear feedback from you. I hope this one is heavy enough that you will really experience a difference.

    EDIT: Keep in mind, you need the previous change also.
     
    Last edited: Jun 16, 2016
    uiniti and AdamGoodrich like this.
  11. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    That's definitely better, but not great. It changes it from white leaves to a white highlight around the edges of all the leaves:

    Capture.JPG

    Also, doesn't messing around with UnityStandardBRDF change the lighting on everything, not just the trees?

    I figured out what lars and n00body were talking about on the first page and changed the SpeedTree shader to include the Face Sign, and that definitely made a difference: it reduced the amount of white leaves by quite a bit, though there were still a few.
     
    dreyhal likes this.
  12. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,741
    Nice work - here are some before and after images on 5.3.5p3. Linear deferred with no post fx.

    Before :
    Grab 20160616110241 w1900h1200 x-37y84z-47r158.jpg

    After (Realtime GI unbaked):
    Grab 20160616111524 w1900h1200 x-37y84z-47r158.jpg

    After (Realtime GI baked):
    Grab 20160616182708 w1900h1200 x-37y84z-47r158.jpg

    Close Up:
    Grab 20160616182823 w1900h1200 x-34y86z-57r159.jpg
     
    Last edited: Jun 16, 2016
    dreyhal likes this.
  13. dreyhal

    dreyhal

    Unity Technologies

    Joined:
    Jan 5, 2016
    Posts:
    15
    It does, but in this case we are killing specular for the away facing pixels. As long as we don't flip the normals, these pixels shouldn't really have specular anyway. Although they could :) It's shaders right? :)
    But seriously - this is not the final shape of this change as far as shipping a Unity version goes. But it is possible that it will help you guys until the change it's shipped. We will continue working on it tomorrow, so no worries.
     
  14. camel82106

    camel82106

    Joined:
    Jul 2, 2013
    Posts:
    304
    Now it's much better than before. When I was trying it for first I got some glimmering of white pixels on the ground. So I was thinking that it's unusable. But than I have tried it second time and it was than good. Not sure what happened. Restart helped...

    Here is screenshot. Most artifacts are gone. Other things are maybe more specific for this model.


    P.S.:
    I really really hope that Unity will start to focus on Speedtree. It's a way how to show superb looking Unity games to world. And it was reason for me to buy Unity 5. And after 2 years it's not working.
    Thanks

    @makeshiftwings
    Could you please share what have you done with that FacingSign change? I have seen that struct input change. But I suppose that you need to change something else too to get it working. Thanks
     
    Last edited: Jun 16, 2016
    dreyhal likes this.
  15. uiniti

    uiniti

    Joined:
    Feb 4, 2015
    Posts:
    74
    Actual situation with the new change

    Many other objects are now white
     
  16. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    714
    (solved)The result is worse after the .cginc edit
    nogood.jpg

    before.
     
    Last edited: Jun 16, 2016
  17. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    714
    (solved) also the other shaders are worse

    before:
    SMM-10.jpg After:
    BAD3.jpg

    Edit:
    Now (after reboot) works

    5.3.4p6 with fix
    Fix OK.jpg
     
    Last edited: Jun 16, 2016
  18. dreyhal

    dreyhal

    Unity Technologies

    Joined:
    Jan 5, 2016
    Posts:
    15
  19. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    714
    Yes,I did!

    note:
    - Unity 5.3.4p6
    - Deferred - Linear - DX11
    - Windows 10 - Nvidia GTX 770
    - Target platform PC Standalone
    - GI Realtime - 1 Directional - SoftShadow
    - All Standard Shader (Specular ssetup) + Speedtree(trees) + Advanced Foliage Shader v.4 (grass)
     
    Last edited: Jun 16, 2016
  20. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    714
    Simple Test Scene(Standard assets Broadleaf speedtree + simple cube with standard shader material):

    Unity 5.3.4p6 no edit
    TreeTest - 5.3.4p6- no CG Edit.jpg

    Unity 5.3.4p6 with @dreyhal changes
    TestTree 5.3.4p6 - CGEdit.jpg

    Unity 5.2.3p3
    TreeTest - 5.2.3p3.jpg
     
    Last edited: Jun 17, 2016
    AdamGoodrich likes this.
  21. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    714
    Great news...after a bit of frustration i did a pc reboot and now the both dreyhal edits are working :confused:.
    Post above edited
     
    Last edited: Jun 16, 2016
  22. Dannyoakes

    Dannyoakes

    Joined:
    Feb 10, 2015
    Posts:
    118
    I vote that we call this "The Dreyhal Solution" for posterity.
     
    AdamGoodrich likes this.
  23. uiniti

    uiniti

    Joined:
    Feb 4, 2015
    Posts:
    74
    Sorry I made a mistake aplying the second change, it looks like this now


    Thanks


    EDIT: ingame the effect is worse, but better than before.
     
    Last edited: Jun 16, 2016
  24. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,741
    You need to delete the ShaderCache directory in Library, and also restart unity for the new settings to take effect.
     
    S4G4N likes this.
  25. uiniti

    uiniti

    Joined:
    Feb 4, 2015
    Posts:
    74
    I did, it's much better but still very noticeable
     
  26. dreyhal

    dreyhal

    Unity Technologies

    Joined:
    Jan 5, 2016
    Posts:
    15
    @uiniti, since I don't know the exact asset you are using, can you make a zoomed-in view and description of what problem do you see? I see a couple of problems with these trees and I don't know what to focus on.
     
    uiniti likes this.
  27. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    714
    uiniti likes this.
  28. uiniti

    uiniti

    Joined:
    Feb 4, 2015
    Posts:
    74
    With tree shadows enabled, disabled and zoomed

     
    Last edited: Jun 18, 2016
  29. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    714
    If I understand correctly the first is with RT shadow and the second without....is correct? Seems all fine.
     
    uiniti likes this.
  30. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    I can see the white edges around the leaves like in my screenshot. It's more noticeable in play mode when it's actually moving.
     
  31. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,741
    I am not getting white edges in mine, as per the earlier screen shots. Did you apply all the changes into the shader file ?
     
  32. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    Yes. As earlier with the white leaves, it only happens when you are looking towards a directional light. Put a bright directional light in your scene, look towards it; make sure bloom and other effects are turned off.
     
  33. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    I'm going to test this out too. This is an issue that actually is pushing me to ditch Unity for UE4... so if this fix works, i'll be very happy
     
    uiniti likes this.
  34. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,741
    I have heard the same thing from a whole range of studio's, including some very high profile ones. Glad a fix is not far away :)
     
  35. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    Yeah... I think announcing "SpeedTree support" in 5.0 was way too early. I gave Unity the benefit of the doubt when they didn't work in 5.0. Wasn't particularly surprised when they still didn't work in 5.1. Got kind of annoyed when they still didn't work in 5.2. Started losing faith when they still didn't work in 5.3. Now 5.4 is running late and they still aren't working. Other games and engines have figured this out. Alloy's apparently figured it out. I feel like there's got to be a better way for Unity to fix this than for them to post code on the forum and ask me to run it in Unity myself and wait for me to tell them if it worked or not. You guys should set up your own test suites with your own trees and do a pass every release to see what they look like.
     
    Flurgle likes this.
  36. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    I just did a test, and will be posting an album with several screenshots. My verdict is that the Deferred Linear speedtrees look (hopefully i did it right) pretty bad (especially with ambient lighting at 0 - which I use a lot).
     
    Last edited: Jun 18, 2016
    uiniti likes this.
  37. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Here's an album: http://imgur.com/a/sG7oT

    Before Fix

    And





    After Fix:
    1) Deferred Linear (ambiance to zero with directional light at 1 intensity) - sun is behind tree:

    2) Deferred Linear, sun behind, ambiance set to default (sun is behind again)



    It's sorta better or worse than it was before. If you want a sparkling, wet look, this seems to work.
     
  38. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Here's SJM Tech's project (Strange it looks like the no edit version seen above):

    You can tell in the post above that my edit did something (I'm using 5.4 latest). I'll try the edit with 5.3 and see what happens. I did both edits + restart + shaderCache delete

     
  39. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    Here's some help for my fellow white-leaf-sufferers:

    https://www.dropbox.com/s/fi697rx2j0148c6/SpeedTreeShaders.zip?dl=0

    This is based on what lars and n00body from Alloy were talking about on page 1; using the face sign to flip the backfacing normals. Unzip and drop these into your project, and then go find your tree's materials and change the shader from "Nature/SpeedTree" to "Nature/SpeedTreeCustom". This will lower the amount of white leaves but not totally get rid of them. You can totally get rid of them by using this shader and also going into the LOD level of each of your trees and unchecking "Normal Map". This will make the trees look a bit more bland because you won't get as much lighting variation within the leaves, but it will completely get rid of white leaves, borders, or sparkles. Note that if you use this shader and turn off the normal maps, you don't need the UnityStandardBRDF fix from dreyhal.
     
    uiniti likes this.
  40. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Thanks for the info @makeshiftwings

    I just tried out the shaders - and turned normals off (seems to look worse?):

     
    uiniti likes this.
  41. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    Hmmm... weird. It looks like it's still using the normal map for some reason. You could try clicking on the prefab root (Broadleaf_Desktop) and in the little LOD graph thing, click each LOD and uncheck "Normal Map" and then click "Apply and Generate Materials". Without the normal map, each frond should act like a regular plane as far as lighting goes; there shouldn't be any variation.

    Edit: I should add I've only tested this in 5.3.5; I haven't tried it in 5.4 yet. It's possible something changed between versions.
     
    Last edited: Jun 18, 2016
  42. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    OK cool. I'll try 5.3 right now
     
  43. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    I should stress it's not a great fix, since like I said, it tends to make the trees bland. But it's an option if you really don't like the white outlines from the BRDF fix. I think I'm going to stick with the BRDF fix instead of disabled normal maps since the outlines aren't tooooo noticeable.
     
  44. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Looks the same with 5.3
     
  45. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    @makeshiftwings do you have Alloy tree shaders? I'm curious what they look like in a screenshot - if you have time.
     
  46. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,344
    I don't. I'm just going by what was said on page one with "Alloy fixed it".
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,439
    uiniti likes this.
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,439
    @sjm tech this would also fix the grass lighting.
     
    sjm-tech and Flurgle like this.
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,439
    and this is how a physically based speed tree might look like:

    lux_speedtree01.jpg
     
    adventurefan, sjm-tech and Flurgle like this.
  50. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    714
    Thanks Lars...seems fantastic... I'll do some tests soon.
    Max
     
unityunity