GLSL pow function?
Asked Answered
B

3

18

I have this:

    float xExponential = pow(xPingPong, 5);

And is not working, claiming:

ERROR: 0:53: No matching overload for call to function 'pow'

Am I doin' something wrong? Developing for iOS with OpenGL ES 2.0.

Bandicoot answered 6/5, 2012 at 15:3 Comment(0)
C
55

Can you try this ?

float xExponential = pow(xPingPong, 5.0);
Convincing answered 6/5, 2012 at 15:7 Comment(2)
Reason is that 5 is a integer and 5.0 is a float (and the pow function is not defined for pow(float,int). There is no automatically typecast in GLSL, but you could force the correct type by float xExponential = pow(xPingPong, float(5)); - not that it makes sense in this example.Worley
@Geri It's considered polite to accept an answer if it helped you solve your problem. Hit the checkmark beside Mennan's answer if it helped you.Subjugate
G
2

Your code is fine just syntax error

Write upto decimal digit

 float xExponential = pow(xPingPong, 5.0);

or

 float xExponential = pow(xPingPong, 5.);
Genotype answered 29/11, 2021 at 12:45 Comment(1)
the answer has already been givenElevation
A
0

Although accurate answers are provided, it is good to explain why those answers work.

float xExponential = pow(xPingPong, 5.0);

GLSL is strongly typed. 1, 2, 3, etc. are considered int. GLSL pow function expects a float value. Thus, you need to convert your power to float. 1., 1.0, 1.f, 1.0f, etc. are treated as float values.

Hope this helps.

Abstraction answered 2/7 at 8:21 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewLongsufferance

© 2022 - 2024 — McMap. All rights reserved.