GLSL Learning

GLSL built-in function

tan()

Returns the tangent of an angle in radians, sin / cos. It shoots off to infinity near 90 degrees.

Syntax

float tan(float angle)
vec2 tan(vec2 angle)
vec3 tan(vec3 angle)

Parameters

angle
The angle in radians.

Return value

sin(angle) / cos(angle). Unbounded: very large near PI/2 + k * PI.

Live example

Edit the code and the preview updates as you type.

How it works

tan(a) is sin(a) / cos(a). Around 0 it behaves almost like a straight line, but as the angle approaches 90 degrees (1.5708), cos approaches 0 and the result explodes toward infinity. Then it jumps to minus infinity and starts climbing again. The example shows these repeating branches.

Typical uses

  • Camera field of view: tan(fov * 0.5) tells how wide the view is one unit in front of the camera, used to build ray directions.
  • Stylized distortions: tan on coordinates produces stretched, accelerating patterns.

Common mistakes

  • Evaluating it right at 90 degrees, where it divides by zero. Keep inputs away from PI/2 + k * PI or clamp the result.
  • Expecting a value between -1 and 1 like sin. tan has no limit, so clamp before using it as a color.

Related functions