Search Unity

How Can I Get The Min And Max Value Of A Planet's Radius

Discussion in 'Shaders' started by MikaelAkopyan, Apr 13, 2019.

  1. MikaelAkopyan

    MikaelAkopyan

    Joined:
    Apr 13, 2019
    Posts:
    3
    I have sculpted a planet in Zbrush and now I am trying to make a shader that would work based on elevation and slopes. I have learned that the position node stores the center of the planet, but I can;t understand how to get values for surface elevation.

    I can bake a Height map, true. I just want to learn how to do this more efficiently
     
    Last edited: Apr 13, 2019
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    A height map baked into the vertices is the most efficient way to do this. Could be stored as the vertex color, or a second UV set. A height map texture is also an acceptable way to do this.

    If you want a purely shader based approach, you can look at the length of the object space position which gives you the distance from the center of the planet. You will have to manually supply the min & max ranges as material properties. Shaders don't have information about the entire mesh, each invocation only knows about the individual vertex or screen pixel it is currently working on.
     
  3. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Like bgolus said, you can take the fragment position distance to the center to get elevation. For slope bake the elevation to a tangent space normal map on a regular sphere, then sample that.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Or just do a dot product between the normalized object space position and the object space vertex normal.
     
    neoshaman likes this.
  5. MikaelAkopyan

    MikaelAkopyan

    Joined:
    Apr 13, 2019
    Posts:
    3
    Thanks guys, I'll get to working on that. On a side note, any idea why emission isn't making an object glow? I am trying to make atmosphere for a planet, Perhaps not the best way to do it, because there is limited control? how would you suggest I go about that?