Intrinsics1 min read

asin

Computes the arc sine (inverse sine).

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

Test asin in a live shader

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

Open Playground

Live Demo

The asin function returns the arc sine (inverse sine) of the input value. The result is an angle in radians.

Signature

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

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

Parameters

ParameterTypeDescription
xTValue in range [-1, 1]

Return Value

Returns the arc sine of x in radians, in the range [-π/2, π/2].

Example

bwsl
pipeline SphericalMapping {
fragment {
// Convert normal to spherical UV coordinates
float3 normal = normalize(input.normal);
// Latitude from asin of Y component
float latitude = asin(normal.y);
// Map to [0, 1] range
float v = latitude / 3.14159 + 0.5;
float u = atan2(normal.z, normal.x) / 6.28318 + 0.5;
float4 envColor = sample(envMap, float2(u, v));
output.color = envColor;
}
}

Common Use Cases

Spherical Coordinates

bwsl
// Convert Cartesian to spherical
float elevation = asin(normalized.y); // Latitude
float azimuth = atan2(normalized.z, normalized.x); // Longitude

Angle from Dot Product

bwsl
// Get angle between vectors (when dot product is known)
float cosAngle = dot(normalize(a), normalize(b));
float angle = acos(cosAngle); // or asin for complement

Normal Map Decoding

bwsl
// Decode spherical normal map
float2 encoded = texNormal.xy * 2.0 - 1.0;
float3 normal;
normal.xy = encoded;
normal.z = sqrt(1.0 - saturate(dot(encoded, encoded)));

Refraction Angle

bwsl
// Snell's law: sin(θ2) = (n1/n2) * sin(θ1)
float sinTheta1 = sin(incidentAngle);
float sinTheta2 = (n1 / n2) * sinTheta1;
float refractAngle = asin(clamp(sinTheta2, -1.0, 1.0));

Domain

asin(x) is only defined for x in [-1, 1]. Values outside this range will produce undefined results. Use clamp(x, -1.0, 1.0) to ensure valid input.

Range

The result is always in the range [-π/2, π/2] (approximately [-1.5708, 1.5708]).

Compiled Output

When compiled to GLSL:

glsl
asin(x)

When compiled to HLSL:

hlsl
asin(x)

See Also