Jump to content

Depth information


Peter2
 Share

Recommended Posts

I'm looking for the depth information (per pixel) of a camera's view on the scene:

  • distance
  • position: x,y,z

Currently I'm using the scene pick functionality for each pixel:

for x = 0 to maxX
   for y = 0 to maxY
      scene.pick(x,y,null,false,camera)

Then use the returned PickingInfo's distance and pickedPoint.

Is there a better/faster way to get the depth information, because the above mentioned code takes several seconds.

Maybe via a shader?

Link to comment
Share on other sites

I got something like:

VertexShader:

varying vec4 vPosition;

void main(void) {
    vec4 pos = vec4(position, 1.0);
    vPosition = world * pos; 

    gl_Position = worldViewProjection * pos;
}

PixelShader:

varying vec4 vPosition;

void main(void) {
    gl_FragColor = vec4(vPosition.xyz / 255.0 + 0.5, 1.0);
}

Is this correct?

I'm losing precision this way I think.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...