GLSL Learning

GLSL built-in function

radians()

Converts an angle from degrees to radians, the unit that sin, cos and the other trigonometric functions expect.

Syntax

float radians(float degrees)
vec2 radians(vec2 degrees)
vec3 radians(vec3 degrees)

Parameters

degrees
The angle in degrees (360 is one full turn).

Return value

The angle in radians: degrees * PI / 180.

Live example

Edit the code and the preview updates as you type.

How it works

Shaders measure angles in radians, where a full turn is about 6.2831 (2 * PI) instead of 360. Most people think in degrees, so radians does the conversion:

degreesradians(degrees)
0.00.0
90.01.5708
180.03.1416
360.06.2831

The example writes the rotation angle in degrees, swinging between 0 and 90, and converts it with radians before building the rotation matrix.

Typical uses

  • Readable angles: rotate(radians(30.0)) says "30 degrees" more clearly than rotate(0.5236).
  • Field of view: camera code often stores the field of view in degrees and converts it once.

Common mistakes

  • Converting twice. If an angle already comes from atan or u_time, it is already in radians.
  • Writing integer literals: radians(90.0), not radians(90).

Related functions