i want to archiv the GetPixel Function in ShaderGraph,
Unfortunately I can’t get any further. I want to use a texture to color the objects for each position in World Space. The texture is 64x64 pixels and the world positions are different, how can i calculate the right position gets the right pixel from the texture?
Currently iam haveing a position node in worldspace, ignore the y position, puts them as UV in Sample Texture 2D, but its colors it wrong.
Hope someone can understand my problem.
Edit:
A better showcase of my problem.
i got a texture and i want to color the object with the specific pixel, at the texture, how can i convert the worldspace position to the pixel at the texture in all 3 directions? Also i want to change the midpoint of the worldspace in shader.
This example in the image is more like texture 3D. Let’s solve this problem for 2D space and we are going to assume everything is aligned to cardinal axes X and Y.
First of all you need to transform position of object/pixel to space of your texture. Your texture has origin in the corner, so you need to find relative position from that point: relativePosition = objectPosition - textureOrigin
Next you need to remap relative position to normalized texture coords (whole thing is just inverse lerp).
My texture gonna be 10x10 units: uv = relativePosition / float2(10, 10)
Done, you use this UV to sample your texture. You can use object position in world space if you want to sample one color based on origin, or pixel position to paint object like texture was casted on it.