Search Unity

Question How can I achieve Fortnite grass?

Discussion in 'Shader Graph' started by ImperialDragon98, Dec 10, 2019.

  1. ImperialDragon98

    ImperialDragon98

    Joined:
    Nov 7, 2018
    Posts:
    28
    http://prntscr.com/q8lutr

    Fortnite and this unity demo achieved such nice looking grass. I notice the grass changes color depending on what part of the texture its on, is this achievable in unity shader graph and if it is how can I do it?
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Its not really clear what you mean by "changed color based on what part of texture its on". What exactly is that in the screenshot? The blades of grass seem the same color all the way up.

    Either way, you can color something based on where it is in texture by using the UV co-ordinates, The co-ordinates are 0-1 so you can just map a color against that.

    Alternatively, you can also use the worldspace position on one or more axis, or object space position, to color something based on its location.

    All of these are accessible by nodes on the graph :) That should get you started, the rest is up to you. Shadergraph already removes syntax so you should have the info you need to explore and find a solution now. Good luck.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i guess you are talking about what some people call a "pigment" map – which basically is a rgb color texture containing a top down projection of the terrain aka "base map".
    given this texture the vertex shader within the grass shader would look up the color of the base or pigment map based on the world space position of the current vertex. in order to do so you have to go from world space to uv space like:
    float2 samplePos = (positionWS.xz - terrainOrigin.xz) * oneOverTerrainSize.xz;
    the smapled color hen would be passed from the vertex to the fragment shader were it was multiplied/combined with the color sampled from the grass detail texture.

    unfortunately shader graph does not let you specify texture lookups to be done per vertex unless they will drive the normal, tangent or position. so your shader will do it in the fragment shader which makes it a bit slower...