Skip to content

Instantly share code, notes, and snippets.

@Riordan-DC
Last active January 25, 2024 02:01
Show Gist options
  • Save Riordan-DC/5083cac3a3b6f7d3b238c9228dad9f87 to your computer and use it in GitHub Desktop.
Save Riordan-DC/5083cac3a3b6f7d3b238c9228dad9f87 to your computer and use it in GitHub Desktop.
First Person View Model Shader (Godot Shader Language)
shader_type spatial;
render_mode depth_draw_opaque,cull_back;
uniform float fov : hint_range(20, 120) = 40;
const float M_PI = 3.14159265359;
void vertex() {
// recreate the camera projection matrix with our custom fov value
float scale = 1.0 / tan(fov * 0.5 * M_PI / 180.0);
PROJECTION_MATRIX[0][0] = scale / (VIEWPORT_SIZE.x / VIEWPORT_SIZE.y);
PROJECTION_MATRIX[1][1] = scale;
}
void fragment() {
// Scale the depth value 70%, this prevents most clipping.
DEPTH = FRAGCOORD.z;
DEPTH = FRAGCOORD.z * 0.7;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment