Search Unity

Standard Terrain Shader: Smoothness [SOLVED]

Discussion in 'Unity 5 Pre-order Beta' started by Zylex, Feb 12, 2015.

  1. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    We use terrains in all of our levels but the usage of the standard terrain shader isn't really an option for dry like maps. The problem is illustrated below.




    Both screenshots are with 0 smoothness. While that effect might be alright for other materials it simply does not work for earth like terrain shaders. As you can see it is really vague and looses all color because of the reflection. No other possible setting gets rid of this problem. The same problem happens with the standardSpecular terrain shader.

    In its current state it is really un usable for bigger terrains you need to allow to tweak this fresnel(?) effect or even smoothness below 0 must be possible. Let me know what you think.
     
    Last edited: Feb 12, 2015
    Garrettec likes this.
  2. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    185
    Actually, if you use the specular shader you can... if you set the specular color to black it will have no reflection at all and will be very dark.

    However, that is not realistic since everything has fresnel... I guess the problem is the lack of proper reflections which PBR depends on...
     
  3. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    @cakeslice Like I said in the post that does not solve it since you still have the same effect(fresnel) which should not occur on earth like materials. See:


    Black specular + Black Smoothness + Black Albedo, only normal map.
     
  4. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    185
    Are you talking about this?

    fff.png

    That's probably ambient lighting, if you change "Ambient Intensity" to 1 it will be black

    EDIT: Another thing you need to consider is the fact that one of the darkest materials on earth has an albedo of 50/255... your terrain is probably too dark
     
    Last edited: Feb 12, 2015
  5. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    No I'm not talking about that. It is the vague white hue all over the terrain when looking at light especially. The thing is with real life terrains that there are a lot of small bumps and sand which reflect light all over the place. Also you'd have small grass and other things making it extremely rough. In Unity terrain the terrain stays a smooth plane. Adding the standard terrain shader to that gives unexpected results.

    Expected result would be more like this:

    This is the legacy specular shader. Although it gives a proper result for dry there is now way to combine this with dry and muddy materials. Also it does not use all the advantages of PBR.

    Standard Shader:

    This does make use of all the PBR advantages and could combine dry and wet surfaces but it does not reflect on how a terrain in real life would respond to lightning since a terrain has a lot more roughness than most surfaces do. It needs a special treatment or an option to solve that.
     
  6. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    185
    Maybe try to use an occlusion map for the splats... like you said, in real life that terrain would have a lot of little cracks and bumps, that's what the occlusion map is for.
     
  7. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    Cakeslice, I also already tried an occlusion map and that does not solve the problem since that only really works in shadowed areas. And by the way the standard terrain shader does not even support occlusion atm.
     
  8. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    185
    Take a look at this:



    This is a demo Unity made, the "dry" mud looks right to me... so there has to be a way to make it look right without using hacks. PBR is all about not having to use hacks in the first place.
     
  9. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    I know that looks good but the backstory behind that demo is this:

    "In this demo, for instance, we cloned and modified the Standard shader to create a terrain shader that had other texture inputs."

    But since this demo has not been released or that specific shader there is nothing much we can do except write our own version of that. But as for now the standard built in shader is not use-able and does not give this effect as you can see and I would like to see a solution since making our own shader is not that simple with predefined Unity Engine inputs.
     
  10. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    189
    Hi Zylex,

    I agree the standard terrain shader on your terrain is not looking realistic, and we want to do something to improve it.

    Can you send us a simple project with the same assets (terrain textures and skybox) and lighting settings, so that we can accurately reproduce the results, and update you our progress with comparable screenshots?
     
    Devil_Inside and shkar-noori like this.
  11. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,646
    If you want a surface that has no reflectity you want to make sure that:
    Metallic = 0
    Smoothness = 0

    You can either define Smoothness in the albedo.a or in the terrain settings Override Smoothness.

    It seems the most likely reason you get your results is that your textures don't have an alpha channel and thus the texture sample ends with smoothness = 1.
     
  12. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    Try messing around with the alpha channels of your textures!
     
  13. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    Thanks for your replies.
    @Joachim_Ante the first screenshots in fact do override the smoothness to 0. All of our textures do have alphas but for illustrative purpose I did test the override aswell. All of the settings give unwanted results for dry earth terrain materials.

    @yuanxing_cai I made a repro scene for you and you can download it here:

    http://verdungame.com/images/SmoothnessTerrainRepro.unitypackage

    I believe it might has something to with linear vs gamma as gamma seems to provide better results:

     
    Last edited: Feb 13, 2015
  14. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    I just looked in to it some more and I'm 99% sure this is a bug with the linear setting and the terrain shader. In Gamma it seems to work fine but when having either the Standard or the StandardSpecular shader the smoothness seems get really intense resulting in vague white terrains. See:

    From left to right the textures have:
    1. low specular high smoothness
    2. high specular low smoothness
    3. low specular low smoothness
    4. fully black
     
  15. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    626
    That just says that they made a terrain shader which at that time didn't exist.

    The shaders are completely fine. Linear lighting is the issue. I am not able to get proper cloth working for instance and get the same terrain issues.
    I assume that the PBS equations or the outputs are wrong in linear lighting mode because some values are not converted correctly.

    It is OK that LinearLighting provides other results for the same setup, but currently it is just wrong.

    EDIT: I made a test with the lighting calculations as you can see in the image attached.
    I modified the CalculateLight (unity_v2f_deferred i) method in Internal-DeferredShading.shader.
    Code (csharp):
    1.     specColor = pow(specColor,2.2);
    2.     specColor = pow(specColor,2.2);
    That's not correct of course but shows that something is wrong with the gamma correction.

    linearspace.jpg
     
    Last edited: Feb 14, 2015
  16. seattlebluesky

    seattlebluesky

    Joined:
    Sep 2, 2014
    Posts:
    170
    FWIW I've seen lights getting blown out in Linear color space also. For now I've stuck with Gamma color space as I prefer the results w.r.t. lighting. Maybe this is expected lighting behavior, seems like one wouldn't expect such a marked contrast in the lighting intensity though between the two.
     
  17. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    626
    I haven't noticed but that's true. Even without specular value the result is over-bright. It is the exact opposite of what I expect from Linear Lighting. That's how it should look like, now it's more like the other way around.

     
  18. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,646
    There seems to be some issues with linear / gamma space in the terrain. My guess is that since it is stored in the alpha channel it is in linear space while it is expected to be in gamma space. Thus in linear mode it is calibrated differently than in gamma space. We'll investigate and figure something out.

    However i am not aware of anything wrong in the standard shader or lighting model in terms of linear vs gamma.

    @EyecyArt: can you create a sample project and either file it as a bug or post it here that shows where standard shader is not behaving as expected.
     
  19. seattlebluesky

    seattlebluesky

    Joined:
    Sep 2, 2014
    Posts:
    170
    There was an issue with lighting in Directional light-mapping where for legacy shaders the lighting was incorrectly decoded as the legacy shaders didn't understand the Directional light-map. I could be remembering that. I have to investigate lighting more when the RC settles down.
     
  20. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    I created a bug report for this with a repro scene where it should be shown. Case number is: 672083_d32tc2assstor231
     
  21. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,646
    This is fixed in RC2.
     
  22. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    626
    It happens always. The issue seems to be down in UNITY_BRDF_PBS () methods.
    Here is the Bug report

    But I have to admit I didn't use the release candidate and was working with the b22. I am just installing to check if the issue is still there.
     
    Last edited: Feb 14, 2015
  23. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,646
    @Zylex: I looked at your sample. But as far as I can see everything looks as expected.
    The more intense specular in linear is as it should be.

    There is a difference between gamma and linear space. This is expected, the math in linear is physically correct. The math in gamma space is not. I think the issue is that your materials are not properly calibrated for PBR.

    http://forum.unity3d.com/threads/official-5-0-pbr-calibration-charts.289416/
     
  24. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,646
    Specifically the pebbles texture has a very bright smoothness value. I think thats somewhat unexpected for rocks like this.
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,855
    hi there,

    it seems as if i can reproduce the problem:
    when using the metallic setup „ambient specular reflections“ seem to be too strong.
    switching to specular and darkening the specular color fixes this.

    (in the example the specular color is set to rgb = 32,32,32 = 0,125 – which still is much too hight for a dielectric material which „usually“ should use a specular color between 0.02 and 0.04.
    smoothness is set to „0.0“)

    so i assume that „unity_ColorSpaceDielectricSpec.a“ is not set correctly and when the shader converts from metallic to specular in „DiffuseAndSpecularFromMetallic“, specular colors simply gets too bright.

    (example screen shoots are taken in linear color space, rc1, os x)

    lars

    specularBug.jpg
     
  26. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    185
    I also thought there was something wrong with unity_ColorSpaceDielectricSpec but if you see the value they used, it's 0.03 or something like that which is right. Every metallic PBR uses a value similar to that including UE4.

    It seems that something is wrong with Unity but I don't know what it is... my money is on the lack of proper reflections
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,855
    but if it is not the secular value what else remains?
    all i can think of right now is
    - the fresnel term (well: it contains "oneMinusRoughness" aka "Smoothness" – but direct specula looks alright).
    - the sample from the reflection probe.
     
  28. ReJ

    ReJ

    Unity Technologies

    Joined:
    Nov 1, 2008
    Posts:
    370
    So I think what happens is that today by default Standard shader does not allow enough roughness for the terrain. It is true that this problem is less noticeable in Gamma rendering mode, but mostly that is just side-effect of Gamma mode being less "right".

    Currently our Standard shader is made to follow the roughness values of Marmoset Toolbag2 and I can see the same problem there too and no, adjusting Fresnel in Toolbag2 does not help either.

    As a workaround for Terrain, I suggest to switch away from Toolbag2 roughness curve (yes, we have different roughness curve implementation inside Standard shader already - one which gives more range in the roughness). To do that download zip file with Builtin shaders (should be next to the link where you downloaded Unity5), extract it and copy following files into your project (no need to do any modifications to this files):
    • TerrainShaders/Splats/Standard-FirstPass.shader
    • TerrainShaders/Splats/Standard-AddPass.shader

    then find UnityStandardConfig.cginc file in CGIncludes next to your Unity.exe (or inside Unity.app on OSX) and copy it into your project.

    In UnityStandardConfig.cginc find #define UNITY_GLOSS_MATCHES_MARMOSET_TOOLBAG2 1 and change it to #define UNITY_GLOSS_MATCHES_MARMOSET_TOOLBAG2 0

    Voila! (maybe you will actually need to assign custom shader in Terrain)
    Roughness should become "more rough" now :)
     
    a436t4ataf, Reanimate_L and Zylex like this.
  29. Zylex

    Zylex

    Joined:
    Nov 25, 2008
    Posts:
    183
    @ReJ Thanks! That seems to do the trick for terrain and solves my problem, it approaches the micro occlusion a terrain should have. Hope to see you built it in Unity along with the StandardSpecular terrain shader.
     
  30. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    947
    In the long run, I think it would be great to have a dropdown selection menu, where you could select between Uncalibrated, Marmoset Toolbag2, Quixel, recently anounced Mizuchi, and other calibration profiles.
     
  31. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    652
    Hold on, are you saying that when we got switched to the Marmoset Toolbag2 style curves we lost some roughness range? That sounds like it can only be a bad thing.

    Also the idea of using a different curve for terrain vs other objects sounds like a recipe for disaster. If you have a rock texture on your terrain, and you use the same textures for an actual rock, the results will be totally different.
     
    GoGoGadget likes this.
  32. ReJ

    ReJ

    Unity Technologies

    Joined:
    Nov 1, 2008
    Posts:
    370
    Well, that is a tradeoff today. Either you get broader range or compatibility. Pick one :(
    I'm going to try to convince Toolbag2 that they should switch to the same formula as we use (Morten Mikkelsen's) in the future.

    If you want to have both Standard shader and Terrain shader in sync - drop in Standard.shader into your project as well. It will pick the same UnityStandardConfig.cginc.


    Agree.
     
    Paulohmm and Reanimate_L like this.
  33. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    652
    I really don't like the idea of not having access to the entire roughness range, but I'm planning on using substance painter to author my textures, with it's unity export settings, which will obviously give out numbers compatible with the standard unity curve.

    :( sounds pretty pants to me.