# Why does invoking glm::refract function return NaN?

At the present time, I make a simple raytracing project and I encounter an issue : When I invoking the glm::refract function, it returns me a vec3 with "NaN" values. However, my input data seems to be correct (2 normalized vec3 and my refractive-index is 1.0). Have you got an idea of the problem ? This function is not so well documented.

EDIT :

Very strange, if my refractive index is 1.0f it's working well actually :

glm::vec3 view = glm::vec3(0.191318035, -0.0721754059, 0.978870869);
glm::vec3 normal = glm::vec3(-0.151046738, -0.988510013, -0.00574064208);
float refractIndex = 1.0f;
glm::vec3 output = glm::refract(view, normal, refractIndex);


However, if I invoke the function and passing a refractive index of 1.10000002f for example (my program seems to approximate values and I don't know why...), it doesn't work => returns vec3 with "NaN" values. Like below :

glm::vec3 view = glm::vec3(0.191318035, -0.0721754059, 0.978870869);
glm::vec3 normal = glm::vec3(-0.151046738, -0.988510013, -0.00574064208);
float refractIndex = 1.10000002f;
glm::vec3 output = glm::refract(view, normal, refractIndex);


EDIT 2 :

More weird : If I try with a refractive-index of 1.1f it doesn't work. Same error.

• "For the incident vector I and surface normal N, and the ratio of indices of refraction eta, return the refraction vector. " Should eta be less than 1.0 then? – mythos Mar 14 '16 at 14:44
• I copied your code,1.1 results in NaN, 1.0f results in: (0.202443779, 0.000635907054, 0.979293704). I'm using: #include <glm/detail/func_geometric.hpp> – mythos Mar 14 '16 at 14:51
• @sakul_ca Indeed if I try with eta=0.9 for instance there is no "NaN" error. : It returns me vec3(x=0.243222654,y=0.399932772,z=0.883683562). I noticed that it never works if my refractive-index is more than 1.0 ! Even with eta=1.001 it returns me NaN values. – Ant0nin Mar 14 '16 at 14:56
• @sakul_ca If I try with eta=1.0 I have the same output vector as your. Could it be a bug from the library ? – Ant0nin Mar 14 '16 at 14:58