3
$\begingroup$

I would like to detect if a cube is in the right half of the camera's view:

enter image description here

I'm trying to do this with geometry nodes. Here's what I have so far:

enter image description here

(Bottom half of this image) I normalize the cube's position, bring it to view-space and perform a dot product on it (with the camera's local x-axis?) and output the dp value as an attribute.

(Top-left of this image) I use this dp value to color the cube in the scene.

(Top-right of this image) There's a camera with its local axis orientation annotated on the screen as well as the cube I mentioned before.

enter image description here

The problem I'm having here is I don't think I'm using the correct camera's positive x-axis when performing the dot product. When I move the cube around the camera on the x-y plane, the cube turns black when it's on the right side of the camera (meaning the dp <= 0) and when it's on the left side of the camera, it turns white (dp > 0), which is the complete opposite of what I want.

Here's a video showing the incorrect result: https://i.sstatic.net/UQzbW.jpg

I know I can simply add a "Math" node after the "Separate XYZ" and multiply it by -1 to flip it but I want to get the correct positive x-axis without having to flip it.

Edit: Please ignore the incorrect use of the "Separate XYZ" into the dot product node; it inputs a vector with a value of (X,X,X) into the dot product. I thought it was going to input (X,0,0) into it. I fixed that tiny mistake by putting a "Combine XYZ" (using (X,0,0) as the values) after the "Separate XYZ". But this is a moot point because if you look at @RobinBetts reply below, I need to use "Vector" and "Vector Rotate" for the local x-axis instead anyway.

$\endgroup$

2 Answers 2

5
$\begingroup$

Is this group any good to you? It stores, on the modified object's points, whether the object is camera-right or camera-left.

enter image description here

The 'Rotation' outputs of various nodes have three components, but they are not Cartesian vectors. They are collections of three angles. So Dot-Products of those don't make any conventional sense. To get the Camera-X vector, take (1,0,0) and rotate it by the camera's rotation.

enter image description here

$\endgroup$
6
  • $\begingroup$ I made 2 changes to get it to somewhat working properly (it's still not correct though): 1) it seems my view transform was incorrect. For the translation, I have to subtract. computergraphics.stackexchange.com/questions/2037/… 2) I applied your "Vector" and "Vector Rotate" nodes Here's what my nodes currently look like: imgur.com/a/PaH7Fhm Here are my results: you can see that the dot product value becomes zero way before the cube reaches the middle of the camera: imgur.com/a/Sa7gKei $\endgroup$
    – Sam
    Commented Mar 2, 2023 at 6:32
  • $\begingroup$ Sorry about the formatting issue above. I'm not sure how to put the sentences on a new line. I used shift-enter and that looks fine but once I add the comment, it seems to ignore formatting. :( $\endgroup$
    – Sam
    Commented Mar 2, 2023 at 6:37
  • $\begingroup$ Hi, @Sam ! np about the formatting. Comment markdown is limited, I can not get this group, as shown, to fail at my end, nor can I understand why it should, unless your camera is carrying a shift, or something? Try this file, and let us know? It's a bit of a mystery, to me ... $\endgroup$
    – Robin Betts
    Commented Mar 2, 2023 at 7:00
  • $\begingroup$ This group does give a result for object-origin L/R. It would need tweaking for point L/R. I see your GN group is on a 3rd-party object.. is that necessary? $\endgroup$
    – Robin Betts
    Commented Mar 2, 2023 at 7:02
  • $\begingroup$ Not sure what "carrying a shift" means. Yeah. The 3rd-party object is necessary, that's why I'm trying to transform it to view space. (Object-origin L/R is fine. Don't need point L/R.) $\endgroup$
    – Sam
    Commented Mar 2, 2023 at 16:02
4
$\begingroup$

If you like, you can do it with shader nodes only:

Camera Data View Vector -> Separate X -> Greater Than 0

The View Vector is the normalized vector from the camera to the shading point, in camera space.

In camera space, the right half of the screen is just X > 0.

$\endgroup$
1
  • $\begingroup$ Unfortunately, I can only do it in the Geometry Shader. The only reason why I output the dot product value to the shader is just to visualize/confirm the value. I did learn a lot about the "Camera Data" node from you though! I didn't know it and its View Vector existed. Thanks for that! :) $\endgroup$
    – Sam
    Commented Mar 2, 2023 at 5:58

You must log in to answer this question.

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