GLSL built-in function

degrees()

Converts an angle from radians to degrees. Handy when you want to reason about an angle like 45 or 90.

Demo version: GLSL ES 1.00 / WebGL 1Demo stage: Fragment

Syntax

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

Parameters

radians
The angle in radians.

Return value

The angle in degrees: radians * 180 / PI.

Live example

Edit the code and the preview updates as you type.

How it works

degrees is the reverse of radians: degrees(3.1416) is 180.0.

The example takes the angle from atan, which is in radians, converts it to degrees and adds 180 so it runs from 0 to 360. After that, cutting the circle into 45-degree slices is simple arithmetic: floor(angle / 45.0) gives 8 slices.

Typical uses

  • Angle-based patterns in round numbers: pie slices, clock faces, compass directions.
  • Debugging: converting an angle to degrees makes it easier to check against what you expect.

Common mistakes

  • Feeding the result back into sin or cos. Those still need radians.
  • Forgetting the range of atan. It returns -PI to PI, which becomes -180 to 180 degrees, not 0 to 360.

Related functions