How can i convert uv coordinates to world space?

前端 未结 2 1698
我在风中等你
我在风中等你 2021-01-26 21:37

I am trying to implement a shader. It will use with Unity LineRenderer. Shader will have noise that scrolling overtime raltive to texture coordinates. For example in parallel to

相关标签:
2条回答
  • 2021-01-26 21:52

    Texture coordinates are already in texture space. If I understand correctly, you should be able to just do this:

        v2f vert(appdata_t IN)
        {
            v2f OUT;
    
            OUT.vertex = UnityObjectToClipPos(IN.vertex);
    
            OUT.texcoord = IN.uv;
            OUT.srcPos = IN.uv;
            OUT.srcPos *= _Freq;
    
            fixed2 scrollOffset = fixed2(1, 0);
            OUT.srcPos.xy -= fixed2(scrollOffset.x, scrollOffset.y) * _Time.y * _Speed;
    
            return OUT;
        }
    
    0 讨论(0)
  • 2021-01-26 22:07

    Option 1

    Each of your UVs is associated with a specific vertex. Once you can establish which UV is assigned to which vertex, then look up the world position of the vertex.

    Option 2

    Another way to do this though may be with a texture that is a pre-baked image of the local space coordinates of the object. In the texture, the XYZ coords would map to RGB. Then you'll do a texture lookup and get to local object coordinates. You'll then have to multiply that vector by the world projection matrix in order to get the actual world space value.

    When you create the texture, you'll have to account for the inability to store negative values. So first you'll have to set up the object so that it fits entirely inside the world coordinates of [-1, 1], in all three axes. Then, as part of the baking procedure, you'll have to divide all values by two, and then add .5. This will ensure that all your negative coordinate space values are stored from [0,.5) and all positive values are stored from [.5,1].


    Note

    I had a hard time understanding your exact request. I hope my options help with your program

    0 讨论(0)
提交回复
热议问题