How To Get Vertical Camera FOV

I couldn’t find how to get the vertical camera FOV value directly so I wrote this.

This shader provieds an example of how to get the vertical FOV value of the camera in either radians or degrees from the PROJECTION_MATRIX.

Also, to prove that it works, you can apply this shader to any object and it wil be white if the ‘compare_FOV’ fits the camera FOV and it will be black otherwise. I chose 70° as default as that is the default FOV in the editor.

Shader code
shader_type spatial;

uniform float compare_FOV = 70;

void fragment() {

	float FOV_in_radians = atan(-1.0 / PROJECTION_MATRIX[1][1]) * 2.0;
	float FOV_in_degrees = degrees(FOV_in_radians);

	if(FOV_in_degrees > compare_FOV - 0.1 && FOV_in_degrees < compare_FOV + 0.1)
	{
		ALBEDO = vec3(1.0,1.0,1.0);
	}
	else
	{
		ALBEDO = vec3(0.0,0.0,0.0);
	}

}
Tags
helper, how to, tool
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Glitshy

Holographic Sight Reticle

Related shaders

Vertical Drops

Fisheye & Anti fisheye Camera Effect

sine wave camera view shader

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments