Search Unity

Making Better Terrains.

Discussion in 'Community Learning & Teaching' started by Frostbite23, Sep 2, 2014.

  1. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    430

    Now this tutorial will guide you on how to make a better looking terrain.
    Mostly aimed for the people with unity Indie and for the people who dont have the money to buy products like RTP3 (Amazing product), etc. And the people who want to learn how to do it.

    Ok So now lets start​

    You have your scene
    http://puu.sh/bhnrX/6eea4ae5ca.png

    And also, notice that in the terrain you see a huge variety textures and shapes? Especially in the grass? Start doing that in your terrains. The more you do it, the better and more believable your terrains will look.

    "So what should we do? The scene is good enough for a game right? But what else am I supposed to add to make it look better?"

    Bump maps, luckily unitys terrains support bump maps. So lets bump it up.
    http://puu.sh/bhoa1/51167b3aa7.png
    Adding bump maps adds more details, but costs more performance (not that expensive to render).

    You dont have to add bump maps, unless if you want to sacrifice performance for beauty.

    "Still the scene doesn't look good enough! What else?"
    Ambient Color, Unitys ambient lighting system is just a flat constant color. But you can take advantage of it by changing the color, in this case it should be a dark bluish color because of the sunset.
    But however that makes the scene have a bluish color, so we can fix this by intensifying color of the sun.
    Looks better right?
    Still the ambient color looks too flat, We can fix this by creating 1 additional directional light for the bounced light.
    Doesn't make much of a difference, but if you look closely you'll see the difference. The reason why it is not that big of a difference is because of the shading, to make it look more proper we can add an Half Lambert ATTEN term to it, but i dont know how to do that yet but if it is possible then the ambient term will look much more vibrant and more realistic.
    Thats pretty much it for the ambient term, you can add one more directional light for the skylighting, but that will cost you more performance.
    Now if you have some knowledge about shaders, you can work your way around this by doing this all in the shader. and which in this case I think much more optimized way instead of doing 2 directional lights. but unity free has its limitations.
    Our scene looks a lot better now, but something still doesnt look right. This is where we get into the small parts.
    Lets change the leaves
    Maybe will add some specular to the rocks as well.
    Now one more thing we need to make sure on the grass.

    We want billboarding on the grass off, because we dont want the grass facing the camera.


    Now our scene looks much better.
    http://puu.sh/bhqki/4422a21980.png

    Now if you want to add a bit of fancy, Just put some lens flares in that sucka
    http://puu.sh/bhrc1/424a22df0a.png

    Now of course im not using any pro assets, im using only the bare assets that are in unity free, now if you are using a unity indie version that is below 4.5, take advantage of that linear space lighting, because in unity 4.5 and above they have removed linear space lighting support. And linear space lighting is more correct then gamma space.
    http://puu.sh/bhrM6/6410d737c4.png

    So we went from somthing that looks like COD World At War, into something that looks better then COD Black Ops 1. But still doesnt look that good.

    Next Up, Modifying the terrain shader.

    P.S On these shader examples, im not giving out the entire code, you have to learn what goes where. You dont learn by taking the code and just using it. So pay attention. If you get any errors, I wont help you because you have to read it correctly.

    Were going to add a fresnel, basically a fresnel is like rim lighting, but actually correct. Another example is, if you have been to the ocean. Have you noticed that when you look down the water isint that reflective? But when you look at the water at the horizon it appears to be more reflective or brighter. That is a fresnel, and it applys to all materials in life.

    But in order to create a fresnel, we have to create a dam lighting model. So in order to do this DL unity built in shaders, Folder < DefaultRecorcesBlahBlah < Nature < Terrain and get the Terrain FirstPass.
    Go into the shader, add these varibles UNDER the sampler2D normal stuff​
    Code (JavaScript):
    1. half _Shininess;
    2. half _Fres;
    3. half _FresPow;
    Then go into the properties section (that is like right below the first line of code, and add this code under the last property
    Code (JavaScript):
    1.     _Fres("Fresnel", Float) = 8.64
    2.     _FresPow("Fresnel Power", Float) = 1
    Now we have our variables, we must Make our lighting model and we have to put this UNDER THE VARIABLES.
    Replace this
    Code (JavaScript):
    1. #pragma surface surf BlinnPhong vertex:vert
    With this
    Code (JavaScript):
    1. #pragma surface surf Model vertex:vert
    and under the varibles (Not the
    properties) heres the lighting model
    Code (JavaScript):
    1. half4 LightingModel (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
    2.     half3 h = normalize (lightDir + viewDir);
    3.     half diff = max (0, dot (s.Normal, lightDir));
    4.     float nh = max (0, dot (s.Normal, h));
    5.     float fresnel = exp2(-_Fres * dot(s.Normal, viewDir)) * _FresPow * s.Albedo;
    6.     float spec = pow (nh, _Shininess) * _SpecColor * s.Albedo;
    7.  
    8.     half4 c;
    9.     c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2) + fresnel;
    10.     c.a = s.Alpha;
    11.     return c;
    12. }
    Now we have a fresnel term
    http://puu.sh/bhEKR/ac8f46d79f.png
    http://puu.sh/bhI92/4a5cebbc63.png

    P.S: ill be editing the post and adding more things
     
    Last edited: Sep 17, 2014
    0tacun and Eric2241 like this.
  2. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    You changed the lighting after the fresnel term addition, so did you change the color of the lights or is it because of the fresnel term?
     
  3. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    Also could you imbed the pics it seems that push.sh has banned my ip. I have no clue why.
     
  4. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    430
    I applied a lighting curve to the terrain, but really though that is just for other purposes. It isint really needed i was just experimenting anyway.
     
    Eric2241 likes this.
  5. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    how do you do that? because it looks great with it.
     
  6. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    430
    Its not that importnat anyway. It just looks darker with it anyway.

    Anyways, anybody else have any other suggestions or feedback?
     
  7. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    Not much looks nice!
     
  8. princeWIGUAN

    princeWIGUAN

    Joined:
    Aug 14, 2013
    Posts:
    337
    This is greate tutorial.
    I stumble upon this thread from Eric2241's thread. :p
     
  9. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    Yeah it is!
     
unityunity