Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Terrain PBR?

Discussion in 'Unity 5 Pre-order Beta' started by PhobicGunner, Oct 28, 2014.

  1. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
    Now that Unity 5 has switched to PBR, are you going to be updating the terrain shader? I see that it still only has Diffuse and Normal inputs, ideally I'd like to see Diffuse, Specular, and Normal so I can properly integrate terrain in a PBR-shaded scene.
     
    hermie and Jerome-P like this.
  2. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    1,266
    My hunch is that built in solutions for this will be later in the 5.x cycle along with other improvements to the terrain system. But in the meantime I would hope that 3rd parties will provide solutions in the coming months, e.g. with nice asset store terrain stuff.
     
  3. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
    I tried Relief Terrain Pack, which turned out to be a horribly buggy mess. I could develop my own hacky workarounds I suppose (maybe have extra inputs for specular in the shader which are assigned through custom script), although I have no idea how to integrate my own shaders with Unity's PBR (the Universal shader is no help here, I can't for the life of me make heads or tails of it).
     
    hermie likes this.
  4. bmccall1

    bmccall1

    Joined:
    Jul 28, 2013
    Posts:
    120
    Yeah RTP is a disaster right now. A real shame, because terrains made with it in U4 kind of look better than the flat ones in u5 now.
     
    hermie likes this.
  5. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    816
    There are some terrain shaders in Lux you could try, but I have no idea what results you'll get with it in Unity5.
     
  6. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
    Nah, that wouldn't work (because ofc it doesn't integrate with Unity's new deferred pipeline).

    As far as I can tell, the meat of deferred shaders is a vertex fragment shader, the vert and frag functions look something like this:

    Code (csharp):
    1.  
    2. VertexOutputDeferred vertDeferred (VertexInput v)
    3. {
    4. // stuff...
    5. }
    6.  
    7. void fragDeferred (
    8.    VertexOutputDeferred i,
    9.    out half4 outDiffuse : SV_Target0,       // RT0: diffuse color (rgb), --unused-- (a)
    10.    out half4 outSpecRoughness : SV_Target1,   // RT1: spec color (rgb), roughness (a)
    11.    out half4 outNormal : SV_Target2,       // RT2: normal (rgb), --unused-- (a)
    12.    out half4 outEmission : SV_Target3       // RT3: emission (rgb), --unused-- (a)
    13. )
    14. {
    15. // more stuff...
    16. }
    17.  
    So it looks like we need a terrain shader that uses these in order to work with Unity's new deferred pipeline. Although we still need to hack the specular map input somehow... perhaps with a custom script that assigns them to the material.
     
  7. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    489
    Yeah, this has kind of been overlooked. I'm very surprised by this. The ground is a pretty big thing to leave out of your PBR pipeline.
     
  8. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
    Agreed.
    I'd really like to get an official UT response on this. Are they just going to neglect terrain for Unity 5, are we going to get an updated terrain shader, etc...?
     
  9. zeroyao

    zeroyao

    Unity Technologies

    Joined:
    Mar 28, 2013
    Posts:
    158
    Hi,

    Currently Unity 5 doesn't support PBR on terrain yet. But it's on top of our roadmap and we really hope we can have a PBR shader working for terrain soon in 5.0 (it's not a promise ;)), even if it might be basic at the beginning.
     
    hermie, jashan, philwinkel and 2 others like this.
  10. Shkarface-Noori

    Shkarface-Noori

    Joined:
    Jun 10, 2013
    Posts:
    825
    a Unity Technologies official?
     
  11. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    882
    Yes, zeroyao works at Unity Technologies.
     
  12. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    816
    You don't need a script for that, just use a custom terrain material that uses the new shader, and assign them in the material inspector.
     
    Shkarface-Noori likes this.
  13. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,097
    Any update on the likelihood of this making it to 5.0?
     
  14. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    57
    this is good news...
     
  15. philwinkel

    philwinkel

    Joined:
    Jun 6, 2013
    Posts:
    276
    this is news from october

    this would be really great, even if it's just 4 textures first pass.


    also, there was a terrain shader that was shared on the forums recently,
    http://forum.unity3d.com/threads/so-i-created-this-pbr-terrain-shader.281658/#post-1878021

    I haven't tried it yet, but it may be worth looking into
     
  16. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    19,671
    We'd love it to self optimise in the same way. I appreciate its a lot of extra work on your part. Also a variant which uses vertex colour for splatting would be nice since we could use those on normal meshes as well.
     
  17. astrand130

    astrand130

    Joined:
    Nov 9, 2014
    Posts:
    21
    Perhaps we could implement the Unity 5 BRDF shading model from the UnityUniversalBRDF.cginc (comes in the built-in shaders.zip for unity 5) into a custom terrain shader. I have been trying but I haven't been very successful since I am a bit of a beginner (I have had some decent progress but I broke something) perhaps somebody with a more extensive knowledge of shader programing could come up with a better solution. This is what I have so far for the terrain basemap shader: (There are Errors and it is a work-in-progress)

    Code (CSharp):
    1. Shader "Nature/Terrain/Terrain_PBR LightingBase" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    5.     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    6.     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    7.     _BumpMap ("Normalmap", 2D) = "bump" {}
    8. }
    9.  
    10. CGINCLUDE
    11. #include "UnityCG.cginc"
    12. #include "UnityUniversalBRDF.cginc"
    13. #include "UnityUniversalUtils.cginc"
    14.  
    15. sampler2D _MainTex;
    16. sampler2D _BumpMap;
    17. fixed4 _Color;
    18. half _Shininess;
    19.  
    20. struct Input {
    21.     float2 uv_MainTex;
    22.     float2 uv_BumpMap;
    23. };
    24.  
    25. void surf (Input IN, inout SurfaceOutput o) {
    26.  
    27.  
    28.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    29.     o.Albedo = tex.rgb * _Color.rgb;
    30.     o.Gloss = tex.a;
    31.     o.Alpha = tex.a * _Color.a;
    32.     o.Specular = _Shininess;
    33.     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    34. }
    35.  
    36. half4 LightingTerrainBRDF (SurfaceOutput s, fixed3 lightDir, half3 viewDir, half3 specGI, half4 light)
    37. {
    38.     half3 h = normalize (lightDir + viewDir);
    39.  
    40.  
    41.     half reflectivity = RGBToLuminance(s.Specular);
    42.     half roughness = 1 - _Shininess;
    43.     s.Albedo = s.Albedo * (1 - reflectivity);
    44.  
    45.     half nl = DotClamped (s.Normal, lightDir);
    46.     half nh = BlinnTerm (s.Normal, h);
    47.     half nv = DotClamped (s.Normal, viewDir);
    48.     half vh = DotClamped (viewDir, h);
    49.     half lv = DotClamped (lightDir, viewDir);
    50.     half lh = DotClamped (lightDir, h);
    51.  
    52.     half F = FresnelTerm (reflectivity, vh);
    53.     half G = GeometricTerm (nl, nh, nv, vh);
    54.     half R = BlinnPhongNormalizedTerm (nh, RoughnessToSpecPower (roughness));
    55.     R = max (0, R);
    56.  
    57.     half nlPow = pow((1.00001-nl), 5);
    58.     half nvPow = pow((1.00001-nv), 5);
    59.  
    60.  
    61.     half Fd90 = 0.5 + 2 * pow(lh, 2) * roughness;
    62.  
    63.     half disneydiffuse = (1 +(Fd90 - 1)*nlPow) * (1 + (Fd90 - 1)*nvPow);
    64.  
    65.     half spec = max(0, (F * G * R) / (4 * nv + 1e-5f) );
    66.     //float spec = pow (nh, s.Specular*128.0) * s.Gloss;
    67.     half diff = disneydiffuse * nl;
    68.  
    69.     half fresnel = FresnelTerm(0, nv);
    70.  
    71.     fixed4 c;
    72.     //c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten * 2);
    73.  
    74.     c.rgb = s.Albedo * (light.ambient + light.color * diff) + s.Specular * (specGI + (light.color * spec)) + (1-reflectivity) * (1-roughness) * specGI;
    75.  
    76.     //c.rgb = combinedcolor, fresnel(0, nv) * (1-roughness));
    77.  
    78.     return c;
    79. }
    80.  
    81.  
    82. ENDCG
    83.  
    84. SubShader {
    85.     Tags { "RenderType"="Opaque" }
    86.     LOD 400
    87.  
    88.     CGPROGRAM
    89.     #pragma surface surf TerrainBRDF
    90.     #pragma target 3.0
    91.     ENDCG
    92. }
    93.  
    94. SubShader {
    95.     Tags { "RenderType"="Opaque" }
    96.     LOD 400
    97.  
    98.     CGPROGRAM
    99.     #pragma surface surf TerrainBRDF nodynlightmap
    100.     ENDCG
    101. }
    102.  
    103. //FallBack "Legacy Shaders/Specular"
    104. }
    105.  
     
  18. n00body

    n00body

    Joined:
    Dec 17, 2010
    Posts:
    673
    We've recently added a PBR terrain shader to the Alloy 3 alpha for Unity 5. Just in case anyone is interested. ;)
     
    philwinkel likes this.
  19. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    226
    Hello Unity, are there any plans for parallax occlusion mapping in your standard shader? Very interested in it. It adds this very convincing depth effect to textures, with good texture it can look like real 3d geometry. Current parallax is at least S***ty(if it works at all).
     
  20. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    309
    There is a tesselation shader out there already. You can try looking that up :)
     
  21. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,390
    As I see some promotional entries above I feel encouraged to inform:

    My RTP3.2 terrain shading package works now with U5 (beta19 at least but will be adjusting this when needed).

    Tom

    P.S. And there is PBR present since RTP3.1 (Unity4)
     
    Last edited: Jan 16, 2015
    philwinkel and sqallpl like this.