Search Unity

Question How to find the coordinates of a pixel based on its color?

Discussion in 'Shaders' started by MMeyers23, Feb 9, 2021.

  1. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
    Short story: I have a texture on a plane. Its black with a small white circle. I need to find out how to answer this question "what are the coordinates of the white pixels (ideally just the one at the center of the circle)?" Doesnt really matter to me if its a UV coordinate, object coordinate, or world pos coordinate.

    Details: I have a texture (a render texture) applied to a plane in my scene. The white dot represents the sun. This texture show what the sun looks like from the perspective of the main camera, if everything in the scene were black except for the sun.

    https://giphy.com/gifs/876XrLYF5I45y8Xq6N

    this will be used to make an occlusion buffer (to show how occluded the view of the sun is (blocked by other objects, off screen, etc).
    The last step in making this feature would be to have a camera sitting close to this plane, such that the white circle takes up the entire view of this new camera. The camera needs move with the white circle (so when it goes up on the texture, the camera is moving with it, the circle remaining in the center of its view).

    I cannot figure out how to move a camera so that it follows the white circle. I am led to believe that I need to sample the pixels on this texture, and find the coordinates of a white pixel. If I can find the coordinates of the white, whether it is in UV coordinates, object coordinates, or world, I think I can do the rest from there.

    Can somebody meet me at my very basic level of understanding here and help me figure out how to achieve this? I get lost when reading about color arrays...

    Thank you!