0
$\begingroup$

I've been trying to recreate the clip space coordinate system in Blender's shader nodes. From what I know, the only coordinate systems you have access to are object coordinates (position), world coordinates (via vector transform node), and window (?) space coordinates (which the vector transform node calls "camera")

Basically, what I'm trying to do is transform a point from a 3d space onto a 2d projection, but using an actual Blender camera object rather than the screen/window. No real reason other than out of curiosity and interest

Blender doesn't have matrix data support yet (though it's coming eventually, albeit only in geometry nodes) so I had to make do with a pretty awkward node set up to replicate matrices and matrix operations. I'd like to think I'm almost there but this looks wrong and I don't really have anything to compare it to

"Camera Transforms" node group

Camera's view

I used drivers to get the camera parameters into shader nodes and used it to construct a model, view, and projection matrix (using this post: How can I get the camera's projection matrix?)

I have a simulated frustum visual for reference

Camera frustum visual

I have a mockup here of what i was expecting clip space to look like, with the Z component (or Y as i mislabeled in the image) representing the depth and the XY coordinates being the 2d coordinates

Clip space mockup

here's the blend file

$\endgroup$
1
  • $\begingroup$ Just a quick note: what the Vector Transform node calls "Camera", are the same coordinates you get from the Camera output of the Texture Coordinate node (at least if set to Point and convert from World). It is not the same as the coordinates from the Window output. $\endgroup$ Commented Mar 15 at 10:03

1 Answer 1

0
$\begingroup$

figured it out

It seems like i messed up the calculations in my "matrix inverse" node group, specifically from the "matrix adjugate" node group. I don't know what specifically was the problem, but I just remade the group from scratch and it seems to be accurate now. Possibly something to do with the reversing/transpose of the rows/columns between the cofactor matrix and adjugate matrix.

But it works fine now and it seems to interact with stuff like focal length and clip end/start properly.

blender clip space coordinates

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .