Skip to content

glm_vec4_refract #1221

Open
Open
@gottfriedleibniz

Description

@gottfriedleibniz

glm_vec4_refract incorrectly computes k. Per GLSL:

k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))

Stepping through the function:

glm_vec4 const dot0 = glm_vec4_dot(N, I);                  // dot(N, I)
glm_vec4 const mul0 = _mm_mul_ps(eta, eta);                // eta * eta
glm_vec4 const mul1 = _mm_mul_ps(dot0, dot0);              // dot(N, I) * dot(N, I)
glm_vec4 const sub0 = _mm_sub_ps(_mm_set1_ps(1.0f), mul0); // 1.0 - eta * eta
glm_vec4 const sub1 = _mm_sub_ps(_mm_set1_ps(1.0f), mul1); // 1.0 - dot(N, I) * dot(N, I)
glm_vec4 const mul2 = _mm_mul_ps(sub0, sub1);              // k = (1.0 - eta * eta) * (1.0 - dot(N, I) * dot(N, I))

Which is incorrect. Additionally, the _mm_movemask_ps logic is confusing (_mm_cmplt_ss only sets the lowest element while _mm_movemask_ps creates a mask from all four elements).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions