View Full Version : GLSL equivalents of C/C++ math functions.

Baggio

02-23-2006, 09:57 AM

I was wondering what are the equivalents of the following C/C++ funtions in GLSL?

log (http://www.cplusplus.com/ref/cmath/log.html) - Note that the this is the natural logarithm which means e = 2.71828... and not 2 like in the log2() I know in GLSL. log10 (http://www.cplusplus.com/ref/cmath/log10.html) exp (http://www.cplusplus.com/ref/cmath/exp.html)

Thanks in advance.

Korval

02-23-2006, 11:50 AM

Note that the this is the natural logarithm which means e = 2.71828... and not 2 like in the log2() I know in GLSL.No log base is better than any other. With just one log function, you can compute the log at any base.

Observe:

log[base e](50) = log[base 2](50)/log[base 2](e).

Baggio

02-23-2006, 03:15 PM

Yeah, I wasn't saying that one was better than the other or anything, I'm just saying that they are not the same so maybe there was a function in GLSL that would be the exact same equivalent of the C/C++ functions. Anyway that's what I'm looking for, if there are functions in GLSL that would do the same as the functions in the list, if not I would like to know if someone has the code to implement that the fastest way as possible since I'm pretty new to GLSL (as I'm still waiting for my copy of the orangebook to arrive, it will take about 25 days before it arrives).

David Spilling

02-24-2006, 03:54 AM

You can download the spec from http://www.opengl.org/documentation/oglsl.html while you are waiting. Section 8.2 describes the exponential functions.

You have log, exp, log2, exp2, but not log10. log10 you'll have to do as posted above.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.