// //------------------------------------------------------------ // Copyright(c) 2009-2010 by Digital Media Professionals Inc. // All rights reserved. //------------------------------------------------------------ // This source code is the confidential and proprietary // of Digital Media Professionals Inc. //------------------------------------------------------------ // #include "Commonasm.h" // Input registers map #define aPosition v0 #define aNormal v1 // Output registers map #define vPosition o0 #define vQuaternion o1 #define vView o2 defi i0, 0, 0, 1 #pragma bind_symbol(aPosition.xyz,v0,v0) #pragma bind_symbol(aNormal.xyz,v1,v1) #pragma bind_symbol(uProjection,c0,c3) #pragma bind_symbol(uModelView,c4,c7) #pragma output_map ( position, o0 ) #pragma output_map ( quaternion, o1 ) #pragma output_map ( view, o2 ) l_position_view_quaternion: m4x4 TEMP_VIEW, dmp_position, dmp_local_to_view_matrix // m3x3 is not done on purpose to prevent stalls in the following add instructions. dp3 TEMP_NORM.z, dmp_normal, dmp_local_to_view_matrix[2] dp3 TEMP_NORM.x, dmp_normal, dmp_local_to_view_matrix[0] dp3 TEMP_NORM.y, dmp_normal, dmp_local_to_view_matrix[1] mov dmp_lrView, -TEMP_VIEW dp4 gl_Position.x, TEMP_VIEW, dmp_projection_matrix[0] add r4, TEMP_NORM.z, CONST_1 // n.z + 1.0 is in r4 // m4x4 is not done on purpose to prevent stalls in the following mul instructions . dp4 gl_Position.y, TEMP_VIEW, dmp_projection_matrix[1] mul r4, r4, CONST_HALF // 0.5*(n.z + 1.0) is in r4 dp4 gl_Position.z, TEMP_VIEW, dmp_projection_matrix[2] dp4 gl_Position.w, TEMP_VIEW, dmp_projection_matrix[3] cmp LEQ, LEQ, r4.x, CONST_0 // compare 0.5*(n.z + 1.0) with 0.0 mov dmp_lrQuat.w, CONST_0 // zero out quat.w component rsq r4, r4.x // 1/sqrt(0.5*(n.z + 1.0)) is in r4 mul r5, TEMP_NORM, CONST_HALF // 0.5*n is in r5 ifc 0, 1, COND_MODE_STA0 rcp dmp_lrQuat.z, r4.x // sqrt(0.5*(n.z + 1.0)) is in quat.z component mul dmp_lrQuat.xy, r5, r4 // 0.5*n*quat.z is in quat.xy else mov dmp_lrQuat.xyz, CONST_1_0 // zero out quat.w component endif nop ret nop main: call l_position_view_quaternion end endmain: