Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vague documentation with glm::refract #806

Closed
tigert1998 opened this issue Aug 19, 2018 · 4 comments
Closed

Vague documentation with glm::refract #806

tigert1998 opened this issue Aug 19, 2018 · 4 comments
Assignees
Milestone

Comments

@tigert1998
Copy link

tigert1998 commented Aug 19, 2018

Documentation with glm::refract doesn't describe what will be returned when full reflection happened. Actually, it refers to GLSL refract man page while the official man page indicates that the result vector will be vec3(0).

I found a little bug with my project and debugged it for about an hour. At last, I found that the reason is that glm returned vec3(nan, nan, nan) which is different from GLSL.

This really confused me and I hope that we can make documentation more precise if possible.

@Groovounet
Copy link
Member

Groovounet commented Aug 19, 2018

Hi,
Your bug report is a little vague. :p What's missing in the documentation of refract?
What do you mean by "full reflection"? That 'eta' is 0 or I and N collinear? I guess I could add an assert for that to catch it.

@Groovounet
Copy link
Member

I can't manage to reproduce the issue, would you share a code where the issue happen?

@Groovounet Groovounet self-assigned this Aug 19, 2018
@tigert1998
Copy link
Author

Sorry, my bad!

#include <iostream>
#include <string>
#include <glm/glm.hpp>
#include <glm/geometric.hpp>
#include <glm/gtc/constants.hpp>

using namespace glm;
using std::string;

void PrintVec3(string name, vec3 v, int tabs) {
    while (tabs--) printf("\t");
    printf("%s = (%.3f, %.3f, %.3f)\n", name.c_str(), v[0], v[1], v[2]);
}

int main() {
    float eta = 1.5;
    vec3 n(0, 1, 0);
    PrintVec3("N", n, 0);
    for (double outer_theta = 0; outer_theta < pi<double>() / 2; outer_theta += 0.1) {
        puts("{");
        vec3 i(sin(outer_theta), cos(outer_theta), 0);
        i = -normalize(i);
        PrintVec3("I", i, 1);
        auto o = refract(i, n, eta);
        PrintVec3("O", o, 1);
        puts("}");
    }
    return 0;
}

And that gives the following output:

N = (0.000, 1.000, 0.000)
{
	I = (-0.000, -1.000, -0.000)
	O = (0.000, -1.000, 0.000)
}
{
	I = (-0.100, -0.995, -0.000)
	O = (-0.150, -0.989, 0.000)
}
{
	I = (-0.199, -0.980, -0.000)
	O = (-0.298, -0.955, 0.000)
}
{
	I = (-0.296, -0.955, -0.000)
	O = (-0.443, -0.896, 0.000)
}
{
	I = (-0.389, -0.921, -0.000)
	O = (-0.584, -0.812, 0.000)
}
{
	I = (-0.479, -0.878, -0.000)
	O = (-0.719, -0.695, 0.000)
}
{
	I = (-0.565, -0.825, -0.000)
	O = (-0.847, -0.532, 0.000)
}
{
	I = (-0.644, -0.765, -0.000)
	O = (-0.966, -0.257, 0.000)
}
{
	I = (-0.717, -0.697, -0.000)
	O = (nan, nan, nan)
}
{
	I = (-0.783, -0.622, -0.000)
	O = (nan, nan, nan)
}
{
	I = (-0.841, -0.540, -0.000)
	O = (nan, nan, nan)
}
{
	I = (-0.891, -0.454, -0.000)
	O = (nan, nan, nan)
}
{
	I = (-0.932, -0.362, -0.000)
	O = (nan, nan, nan)
}
{
	I = (-0.964, -0.267, -0.000)
	O = (nan, nan, nan)
}
{
	I = (-0.985, -0.170, -0.000)
	O = (nan, nan, nan)
}
{
	I = (-0.997, -0.071, -0.000)
	O = (nan, nan, nan)
}

@Groovounet Groovounet added this to the GLM 0.9.9 milestone Aug 27, 2018
@Groovounet
Copy link
Member

This issue is resolved in master branch for GLM 0.9.9.1.

Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants