Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Determining Point in World space by point on a screen

Discussion in 'General Graphics' started by Aleksey1555, Feb 27, 2018.

  1. Aleksey1555

    Aleksey1555

    Joined:
    Sep 17, 2017
    Posts:
    12
    Hello
    Every point on a screen is a point with 2 coordinates x and y
    Every point in 3d is a point with 3 coordinates x and y and z
    I want to determine point in 3d in world space by point on a screen
    i know that there is a function Camera.ScreenToWorldPoint but it
    does not give me z component of the point in 3d
    How can i do this?
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
    How do you expect it to give you anything for the 3rd axis? It doesn't know what or where you expect it to return.

    If you want it to stop at an object, use a raycast. If you want it to be at a specific distance from the camera, just make z that value.
     
  3. Aleksey1555

    Aleksey1555

    Joined:
    Sep 17, 2017
    Posts:
    12
    This is possible because there is a Z Buffer
    Z Buffer was created for delete invisible pixels
    Z buffer make in possible to determine what point is visible

    This is looks like it no possible but only because z buffer today we see what we have
    When the resulting image drawing on screen video card use z buffer to understand what point or pixel is visible
    Another example is a game Hitman code 47 in whitch player can move mouse cursor to any place of the scene
    AND hitmat will shoot in this place
    in hitman player can move cursor to the point on screen and hitman can shoot to close or to far
    I want do the same
     
  4. Aleksey1555

    Aleksey1555

    Joined:
    Sep 17, 2017
    Posts:
    12
    z buffer store's z component of visible point on screen!!
    there is the function Camera.ScreenToWorldPoint whitch can translate screen x y coordinate and Z buffer can tell z coordinate of visible pixel
     
  5. Aleksey1555

    Aleksey1555

    Joined:
    Sep 17, 2017
    Posts:
    12
    please help
     
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    The Z Buffer is on the GPU, not the CPU, and is calculated after the CPU side game code is finished running for each frame. You could copy the last frame’s depth buffer back to the CPU, or maybe copy just a specific pixel’s value from the last frame’s depth buffer.

    Or you can just do a raycast which will be cheaper and easier. (Assuming raycasting the against collision is good enough).
     
  8. Aleksey1555

    Aleksey1555

    Joined:
    Sep 17, 2017
    Posts:
    12
    You right z buffer on the GPU side I forget this )))
     
  9. Aleksey1555

    Aleksey1555

    Joined:
    Sep 17, 2017
    Posts:
    12
    Thank you!
    You really help me
    it works!!!!
    Now i can determine point in world space)))