Unittest Geometric functions TODO : add tests for faceforward, reflect and refract
1 // dot 2 vec2 v2 = vec2( 1.0f, 3.0f ); 3 assert( dot( v2, vec2( 2.0f, 2.0f )) == 8.0f ); 4 5 vec3 v3 = vec3( 1.0f, 3.0f, 5.0f ); 6 assert( dot( v3, vec3( 2.0f, 2.0f, 2.0f )) == 18.0f ); 7 8 vec4 v4 = vec4( 1.0f, 3.0f, 5.0f, 7.0f ); 9 assert( dot( v4, vec4( 2.0f, 2.0f, 2.0f, 2.0f )) == 32.0f ); 10 11 vec3 v3_1 = vec3( 1.0f, 2.0f, -3.0f ); 12 vec3 v3_2 = vec3( 1.0f, 3.0f, 2.0f ); 13 14 assert( dot( v3_1, v3_2 ) == 1.0f ); 15 assert( dot( v3_1, v3_2 ) == dot( v3_2, v3_1 )); 16 assert( v3_1 * v3_2 == v3_1 * v3_2 ); 17 assert( v3_1 * v3_2 == vec3( 1.0f, 6.0f, -6.0f )); 18 19 // cross 20 assert( cross( v3_1, v3_2 ).data == [ 13.0f, -5.0f, 1.0f ] ); 21 assert( cross( v3_2, v3_1 ).data == [ -13.0f, 5.0f, -1.0f ] ); 22 23 // normalize 24 assert( normalize( vec2( 1 )) == [ 1.0f / sqrt( 2.0f ), 1.0f / sqrt( 2.0f ) ] ); 25 assert( vec3( 1 ).normalize == [ 1.0f / sqrt( 3.0f ), 1.0f / sqrt( 3.0f ), 1.0f / sqrt( 3.0f ) ] ); 26 assert( normalize( vec4( 1 )) == [ 0.5, 0.5, 0.5, 0.5 ] ); 27 28 // length 29 assert( length( v2 ) == sqrt( 10.0f )); 30 assert( v3.length == sqrt( 35.0f )); 31 assert( length( v4 ) == sqrt( 84.0f )); 32 33 // distance 34 assert( distance( vec2( 0.0f, 0.0f ), vec2( 0.0f, 10.0f )) == 10.0 );
For the incident vector I and surface normal N, and the ratio of indices of refraction eta, return the refraction vector The input parameters for the incident vector I and the surface normal N must already be normalized