Reverse UV Lookup

Is there a way to do a reverse UV lookup within a pixel shader? As in, I already have a UV-Coordinate and I want to transform that to a mesh’s 3D coordinate in World-Space. Even the 3D coordinate in Local Space would work because I could just pass in the object’s Local to World matrix. To be clear, the pixel we’re drawing isn’t of mesh I’m sampling the 3D coordinate from.

maybe this can help

I think the easiest and most efficient way would be to calculate the worldspace position in the vertex shader and let it be interpolated to be read in the fragment stage.

            struct appdata
            {
                float4 positionOS : POSITION;
            };

            struct v2f
            {
                float4 positionCS : SV_POSITION;
                float3 positionOS : TEXCOORD0;
                float3 positionWS : TEXCOORD1;
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.positionOS = v.positionOS.xyz;
                o.positionWS = TransformObjectToWorld(v.positionOS.xyz);
                o.positionCS = TransformWorldToHClip(o.positionWS);
                return o;
            }

            float4 frag (v2f i) : SV_Target
            {
                i.positionWS; //interpolated fragment position in worldspace
                i.positionOS; //interpolated fragment position in objectspace

                return float4(0,0,0,0);
            }

Hi @kenamis, that wouldn’t work. For starters, that vert is from the object that’s being rendered. As my question states, I want the position of part of a mesh (based on an UV coordinate) other than the one being rendered.

@altepTest, it doesn’t give me the solution, but it does make it make me think a bit more about what’s needed to a UV map to work, and I don’t think what I want is actually possible. The good news is that I don’t need to worry about UV to 3D coordinates changing, so I might be able to calculate the information once before doing any rendering. But, that raises the question of how to pass in the 3D coordinates. Not to mention that even a normal 1080P screen has over 2 million pixels. The use case I have in mind would probably use a 4K signal with an unusual aspect ratio that can result in even more pixels.

Hahahahahaha, I have the UV coordinates. I could create a RenderTexture with 32bit channels at the target resolution of my output, and then pull the XYZ coordinates from the RenderTexture. And, like I said before, I can fill in the RenderTexture ahead of time. And, I can also use the W coordinate as a mask to tell me about UV coordinates that don’t correspond to any part of the model.

oh okay, your question was confusing and odd. Sorry for trying to help.