Intrinsics1 min read

degrees

Converts radians to degrees.

Reading Time
1 min
Word Count
130
Sections
11
Try It Live

Test degrees in a live shader

Open the playground, start from a visual preset, and wire degrees into the fragment stage to see how it behaves with real values.

Open Playground

Live Demo

The degrees function converts an angle from radians to degrees by multiplying by 180/π.

Signature

bwsl
degrees :: (T x) -> T {...}

Where T can be float, float2, float3, or float4.

Parameters

ParameterTypeDescription
xTAngle in radians

Return Value

Returns the angle converted to degrees.

Example

bwsl
pipeline AngleDebug {
fragment {
float3 normal = normalize(input.normal);
float3 lightDir = normalize(lightPos - input.worldPos);
// Calculate angle between normal and light
float cosAngle = dot(normal, lightDir);
float angleRad = acos(clamp(cosAngle, -1.0, 1.0));
float angleDeg = degrees(angleRad);
// Visualize: green when facing light (0°), red when perpendicular (90°)
float t = angleDeg / 90.0;
float3 color = lerp(float3(0.0, 1.0, 0.0), float3(1.0, 0.0, 0.0), saturate(t));
output.color = float4(color, 1.0);
}
}

Common Use Cases

Debug Visualization

bwsl
// Display angle in human-readable form
float angleRad = acos(dot(a, b));
float angleDeg = degrees(angleRad);
// angleDeg now in familiar 0-180 range

Rotation UI

bwsl
// Convert internal radians to display degrees
float displayRotation = degrees(objectRotation);

Angle Thresholds

bwsl
// Define thresholds in degrees, compare in radians
float thresholdDeg = 45.0;
float thresholdRad = radians(thresholdDeg);
// ... or convert computed radians to degrees for comparison
if (degrees(computedAngle) < 45.0) { ... }

Field of View

bwsl
// Display FOV in degrees
float fovDegrees = degrees(fovRadians);

Conversion Factor

degrees(x) is equivalent to x * (180.0 / 3.14159265359) or approximately x * 57.2957795131.

When to Use

Most shader math works in radians, so this function is primarily useful for debugging, UI display, or when interfacing with systems that use degrees.

Compiled Output

When compiled to GLSL:

glsl
degrees(x)

When compiled to HLSL:

hlsl
degrees(x)

When compiled to Metal:

metal
x * 57.29577951308232

See Also

  • radians - Degrees to radians
  • sin - Sine (takes radians)
  • cos - Cosine (takes radians)