# VEX :: Screen space to world space in SOPs

## Recommended Posts

How can I get the word position of a point I'm seeing through a camera and on the camera's screen plane. Let's say the camera resolution is 1280x720 pixels ( 0,0 at top left and 1280,720 at bottom right), I want to know the world position of a point which will be at the pixel position of 300,200 at render output. Will this differ if I have Orthographic or Perspective camera? I think fromNDC / ptransform functions are the saviors here but I can't quite figure out how exactly.

In general I'd appreciate if anyone can explain the world space, object space and camera space in Houdini in comparison which conventions that OpenGL has for instance. I read here and there that in H world space is actually camera space (or is it only in Mantra and not SOPs?). Also in OpenGL NDC is [-1,1] in all three dimensions, how is this in H?

Cheers

##### Share on other sites

Here's an example, if that's what you're looking for.

just change the W,H and pixels parms (w = x position, h = y pos, pixels = how many pixels around the area you'll see)

screenspace.hipnc

##### Share on other sites

Use fromNDC(camera, position). Position consist of x and y in 0..1 range and z as depth in units.

Tests for Detail wrangle:

```// Create point at the center of the camera view in 3 meters away.
```
```// Camera frustum. Set reasonable clipping distances like 0.2 to 10.
string cam = "/obj/cam1";
float near = -chf("/obj/cam1/near");
float far = -chf("/obj/cam1/far");

void quad(int pt1, pt2, pt3, pt4)
{
int geo = geoself();
}
```

##### Share on other sites

Thanks a lot for the suggestion Shinjipierre but it really didn't work out for me. The use of the hi-rez grid and using its points' uv seemed to do the job in some cases but it's not a generic solution and it's an overkill IMO. What f1480187 suggested was more what I was after.

Thanks again f1480187 for helping me out, your solution did the job beautifully.

## Create an account

Register a new account