Intrinsics1 min read
rcp
Computes the reciprocal of a value.
Reading Time
1 min
Word Count
102
Sections
7
Try It Live
Test rcp in a live shader
Open the playground, start from a visual preset, and wire rcp into the fragment stage to see how it behaves with real values.
Open PlaygroundThe rcp function returns the reciprocal of a value, computed as 1.0 / x. Use it when the shader logic is explicitly working with inverse scale, inverse distance, or reciprocal weights.
Live Demo
Signature
bwsl
rcp :: (T x) -> T
Where T can be float, float2, float3, or float4.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | T | The value to invert |
Return Value
Returns 1.0 / x.
Example
bwsl
float distance = max(length(lightVector), 0.001);
float inverseDistance = rcp(distance);Zero Values
rcp(0.0) produces infinity. Clamp or bias values when zero is possible.
Compiled Output
When compiled to GLSL:
glsl
1.0 / x
When compiled to HLSL:
hlsl
rcp(x)
When compiled to Metal:
metal
1.0 / x