Intrinsics1 min read
cosh
Computes the hyperbolic cosine.
Reading Time
1 min
Word Count
119
Sections
11
Try It Live
Test cosh in a live shader
Open the playground, start from a visual preset, and wire cosh into the fragment stage to see how it behaves with real values.
Open PlaygroundThe cosh function returns the hyperbolic cosine of x, defined as (exp(x) + exp(-x)) / 2.
Live Demo
Signature
bwsl
cosh :: (T x) -> T {...}
Where T can be float, float2, float3, or float4.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | T | The input value |
Return Value
Returns the hyperbolic cosine of x. The result is always greater than or equal to 1.0 for real-valued inputs.
Example
bwsl
pipeline CatenaryGlow {
fragment {
float2 p = input.uv * 2.0 - 1.0;
// Catenary-shaped curve using hyperbolic cosine
float curve = (cosh(p.x * 1.8) - 1.0) * 0.22 - 0.35;
float line = smoothstep(0.025, 0.0, abs(p.y - curve));
float3 color = lerp(float3(0.03, 0.03, 0.05), float3(1.0, 0.72, 0.25), line);
output.color = float4(color, 1.0);
}
}Common Use Cases
Catenary Curves
bwsl
// Hanging cable or chain shape
float y = cosh(x / tension) * tension;Even Curve Shaping
bwsl
// Symmetric growth on both sides of zero
float shaped = cosh(centeredValue) - 1.0;Soft Radial Amplification
bwsl
// Amplify distance with an even hyperbolic curve
float radial = cosh(length(centeredUv) * scale) - 1.0;Even Function
cosh(-x) equals cosh(x), making it useful for symmetric effects around zero.
Compiled Output
When compiled to GLSL:
glsl
cosh(x)
When compiled to HLSL:
hlsl
cosh(x)
When compiled to Metal:
metal
cosh(x)