10
Mar
08

GLSL CosH, SinH & TanH

GLSL lacks builtin functions to calculate hyperbolic Cosines, Sines and Tangents. Turns out it’s very simple to do all three in GLSL (as anyone who, unlike me, knew anything about maths would know)…

/// COSH Function (Hyperbolic Cosine)
float cosh(float val)
{
	float tmp = exp(val);
	float cosH = (tmp + 1.0 / tmp) / 2.0;
	return cosH;
}

// TANH Function (Hyperbolic Tangent)
float tanh(float val)
{
	float tmp = exp(val);
	float tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);
	return tanH;
}

// SINH Function (Hyperbolic Sine)
float sinh(float val)
{
	float tmp = exp(val);
	float sinH = (tmp - 1.0 / tmp) / 2.0;
	return sinH;
}
Advertisements

0 Responses to “GLSL CosH, SinH & TanH”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Twitter

March 2008
M T W T F S S
« Feb   Apr »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Links

Blog Stats

  • 468,884 hits

%d bloggers like this: