Created
June 4, 2015 18:07
-
-
Save catchouli/a90c5815fc74a7188345 to your computer and use it in GitHub Desktop.
interpolate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec3 interpolate(vec3 tri[3], vec3 vals[3], vec3 intersection) | |
{ | |
// Calculate barycentric coordinates | |
float one_over_tri_area = 2.0f / length(cross(tri[1] - tri[0], tri[2] - tri[1])); | |
float u = 0.5f * one_over_tri_area * length(cross(tri[1] - intersection, tri[2] - intersection)); | |
float v = 0.5f * one_over_tri_area * length(cross(tri[0] - intersection, tri[2] - intersection)); | |
float w = 0.5f * one_over_tri_area * length(cross(tri[0] - intersection, tri[1] - intersection)); | |
return vals[0] * u + vals[1] * v + vals[2] * w; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment