0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ "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? \$\endgroup\$ – mythos Mar 14 '16 at 14:44
  • \$\begingroup\$ 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> \$\endgroup\$ – mythos Mar 14 '16 at 14:51
  • \$\begingroup\$ @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. \$\endgroup\$ – Ant0nin Mar 14 '16 at 14:56
  • \$\begingroup\$ @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 ? \$\endgroup\$ – Ant0nin Mar 14 '16 at 14:58
0
\$\begingroup\$

The refrative index must be within the range [-1.0f, 1.0f] inclusively.

\$\endgroup\$
  • \$\begingroup\$ Yes you're almost right => "eta specifies the ratio of indices of refraction" n1/n2 with n1 the first refractive-index and n2 the second refractive-index. Thanks a lot for your help ! \$\endgroup\$ – Ant0nin Mar 14 '16 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.