What Is the Difference Between radians and degrees in GLSL?

In the OpenGL Shading Language (GLSL), the radians() and degrees() built-in functions serve as conversion utilities between two standard units of angular measurement. While radians() converts an angle given in degrees into radians, degrees() performs the exact inverse operation by converting radians back into degrees. Understanding this difference is essential in shader programming because all native GLSL trigonometric functions—such as sin(), cos(), and tan()—strictly operate in radians, whereas developer inputs, uniform variables, and 3D modeling transformations are frequently specified in degrees.

Mathematical Behavior and Formulas

The core distinction between the two functions lies in the mathematical conversion factor applied to the input argument:

Both functions handle floating-point values and execute element-wise across vector types.

Vector Support and Overloads

GLSL defines both radians() and degrees() for scalar floats as well as multi-component floating-point vectors:

When passed a vector, the conversion is applied independently to every component (\(x\), \(y\), \(z\), and \(w\)), eliminating the need for manual looping or per-component calculations.

Practical Shader Example

A common use case involves passing rotation angles in degrees from the CPU application via uniform variables, then converting those values to radians inside the vertex or fragment shader prior to constructing rotation matrices or evaluating trigonometric curves:

uniform float u_rotationInDegrees; // e.g., 45.0
uniform vec3 u_eulerRotation;      // e.g., vec3(0.0, 90.0, 180.0)

void main() {
    // Convert single float from degrees to radians
    float angleRad = radians(u_rotationInDegrees);
    float cosAngle = cos(angleRad);
    float sinAngle = sin(angleRad);

    // Convert full vector of angles at once
    vec3 rotationInRadians = radians(u_eulerRotation);

    // Perform inverse calculation if needed
    vec3 backToDegrees = degrees(rotationInRadians);
}

Side-by-Side Comparison

Property radians() degrees()
Input Unit Degrees (\(0^\circ \text{ to } 360^\circ\)) Radians (\(0 \text{ to } 2\pi\))
Output Unit Radians (\(0 \text{ to } 2\pi\)) Degrees (\(0^\circ \text{ to } 360^\circ\))
Multiplier \(\frac{\pi}{180.0}\) \(\frac{180.0}{\pi}\)
Primary Use Case Prepping human-readable degree values for GLSL sin(), cos(), tan() Exporting computed angular data back into standard \(0^\circ\text{–}360^\circ\) formats
Supported Types float, vec2, vec3, vec4 float, vec2, vec3, vec4

Utilizing these built-in functions ensures hardware-optimized calculation routines and maintains clear, readable shader code when handling coordinate transformations and rotational calculations.