GLSL built-in function

tanh()

Smoothly maps real inputs into the open interval minus one to one.

Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment

Syntax

genType tanh(genType x)

genType means float / vec2 / vec3 / vec4; matching placeholders use the same type.

Parameters

x
Input value or left-hand vector

Return value

A value strictly between -1 and 1 for each finite input component, with the same type as x.

Live example

Edit the code and the preview updates as you type.

What tanh does

Smoothly maps real inputs into the open interval minus one to one.

Read the preview

tanh(x*3.0) approaches -1 and 1 at the sides without reaching them. Lower 3.0 to 1.0 to make the central transition occupy more of the image.

Core call

tanh(x*3.0);

It approaches plus or minus one asymptotically rather than clipping.

Experiment

Try tanh(x*6.0) in the result line. The transition narrows around x = 0 while the outer regions stay close to the two saturation colors.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions