Search Unity

wrap UV around mountains

Discussion in 'Shaders' started by stationx, Jan 19, 2016.

  1. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    Hello!
    I came across this example on how to unwrap a UV on a sphere in a shader!

    http://www.gamedev.net/topic/487369-uv-mapping-a-sphere-in-shader/

    float2 normd = normalize(vtx_position.xy);

    // texture coordinates
    float deg = atan2(normd.y, normd.x);
    deg = degrees(deg);

    if (deg < 0)
    deg += 360;

    deg /= 360;

    l_newUV.x = deg;
    l_newUV.y = vtx_position.z;


    This approuch is interesting but comes with several problems.
    The texture wraps perfect around if 1. the object is very 'sphery' 2, no concave shapes included.
    Otherwise, the texture is horrible distorted.
    Does one have an idea on how to improve this code???

    Regards! Tom