Intrinsics1 min read
radians
Converts degrees to radians.
Reading Time
1 min
Word Count
126
Sections
12
Try It Live
Test radians in a live shader
Open the playground, start from a visual preset, and wire radians into the fragment stage to see how it behaves with real values.
Open PlaygroundLive Demo
The radians function converts an angle from degrees to radians by multiplying by π/180.
Signature
bwsl
radians :: (T x) -> T {...}
Where T can be float, float2, float3, or float4.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | T | Angle in degrees |
Return Value
Returns the angle converted to radians.
Example
bwsl
pipeline RotatedTexture {
fragment {
// Rotate texture by 45 degrees
float angle = radians(45.0);
float s = sin(angle);
float c = cos(angle);
float2 centered = input.uv - 0.5;
float2 rotated = float2(
centered.x * c - centered.y * s,
centered.x * s + centered.y * c
);
rotated += 0.5;
float4 color = sample(tex, rotated);
output.color = color;
}
}Common Use Cases
Defining Angles in Degrees
bwsl
// Field of view in degrees
float fovRad = radians(90.0);
float tanHalfFov = tan(fovRad * 0.5);Spotlight Cone Angles
bwsl
// Define cone angles in degrees for readability
float innerConeRad = radians(15.0);
float outerConeRad = radians(30.0);
float spotFactor = smoothstep(cos(outerConeRad), cos(innerConeRad), cosAngle);Rotation Increments
bwsl
// Rotate by 90 degree increments
float rotation = radians(90.0 * float(quadrant));Camera Parameters
bwsl
// Convert camera settings from degrees
float pitchRad = radians(cameraPitchDeg);
float yawRad = radians(cameraYawDeg);Trigonometric Calculations
bwsl
// Calculate with degree input
float sineOf30 = sin(radians(30.0)); // = 0.5
float cosOf60 = cos(radians(60.0)); // = 0.5Conversion Factor
radians(x) is equivalent to x * (3.14159265359 / 180.0) or approximately x * 0.01745329251.
Constants
For common angles, you can precompute: π/6 (30°), π/4 (45°), π/3 (60°), π/2 (90°), π (180°), 2π (360°).
Compiled Output
When compiled to GLSL:
glsl
radians(x)
When compiled to HLSL:
hlsl
radians(x)
When compiled to Metal:
metal
x * 0.017453292519943295