Download

Possible to get world position from uv coordinate? shader.

As the title says, Is there a way i can sample the scene world position at certain pixel/uvposition on the screen?

My reason for wanting this, is so I can project the player’s mouse screen position to world position, and thus get the player mouse world position in my materials. I realize blueprint can do something similar with linetrace, however that method is not suitable for me, as it requires accurate scene collision.

There’s a transform vector node that transforms between screen, world, local, tangent spaces. But I don’t know if there’s a ‘get’ and ‘set’ capability in the material editor.

Would the transform node allow me to convert a UV coordinate position to a world position? I have tried using that node, transforming from view to world space, but it didn’t produce the correct result.

Well, I think tangent space is closer to being UV space, or is UV space for that node (don’t remember well) because it’s in XY (aka UV)…but there’s probably something else that needs to be performed with it. I’m not sure yet, though I’m interested in the function of it so I’ll do research and post anything pertinent I find.

It is simle trig. You know depth from sampling scene depth and you know camera vector from pixel coordinates and camera parameters and you know world position of the camera. This is enough to get world position of a fragment. If you are unsure how, draw a picture.