How to get Camera FOV in Shader Graph?

Hello,

I want to use the camera FOV in a shader. I am aware of the camera node which contains the position and direction, but is there a way to get the FOV? I’m using URP in case that’s relevant.

Thanks in advance

1 Like

From this post I figure I could calculate it with the camera’s projection matrix, but I don’t think this is available as a node in shader graph and when I tried to put this into a custom function I just got errors

I think I actually solved it myself. This is my solution in case anyone is wondering.

For the vertical FOV I use the M11 MAtrix element (seen above) and for horizontal FOV I used the M00 Matrix element.

Bunny83’s answer in this thread as well as the link in my previous post helped me figure it out.

6 Likes

Seems that the division of -1 by the matrix element is only for the Y axis where the matrix element needs to be negated due to Unity flipped Y on some platforms (when UNITY_UV_STARTS_AT_TOP is defined).

In all other cases the matrix element shouldn’t be negated, i.e. divide 1 by the matrix element.

2 Likes