Intrinsics1 min read

sin

Computes the sine of an angle in radians.

Reading Time
1 min
Word Count
153
Sections
12
Try It Live

Test sin in a live shader

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

Open Playground
bwsl
sin :: (T x) -> T {...}

The sin function returns the sine of an angle specified in radians. It is one of the most fundamental functions for creating organic motion, waves, and procedural effects in shaders.

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

Example - Rippling Wave Effect

Parameters

ParameterTypeDescription
xTAngle in radians

Return Value

Returns the sine of x, in the range [-1, 1].

Example

Common Use Cases

Wave Motion

bwsl
// Oscillating wave
float wave = sin(time * frequency) * amplitude;
// Multiple overlapping waves
float combined = sin(x * 1.0) * 0.5 + sin(x * 2.3) * 0.3 + sin(x * 4.1) * 0.2;

Circular Motion

bwsl
// Point moving in circle
float2 circlePos = float2(cos(time), sin(time)) * radius;

Color Cycling

bwsl
// Rainbow color cycling
float3 rainbow = float3(
sin(time) * 0.5 + 0.5,
sin(time + 2.094) * 0.5 + 0.5, // offset by 2π/3
sin(time + 4.189) * 0.5 + 0.5 // offset by 4π/3
);

Water Surface

bwsl
// Simple water waves
float height = sin(pos.x * waveFreq + time) * sin(pos.z * waveFreq * 0.7 + time * 1.3);

Procedural Noise

bwsl
// Simple pseudo-random using sin
float random = fract(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);

Input Range

The input is expected in radians. For degrees, use sin(radians(degrees)) or multiply by π/180.

Performance

Modern GPUs compute sin and cos together in a single instruction. If you need both, consider using sincos() for clarity.

Compiled Output

When compiled to GLSL:

glsl
sin(x)

When compiled to HLSL:

hlsl
sin(x)

See Also