1// 2//------------------------------------------------------------ 3// Copyright(c) 2009-2010 by Digital Media Professionals Inc. 4// All rights reserved. 5//------------------------------------------------------------ 6// This source code is the confidential and proprietary 7// of Digital Media Professionals Inc. 8//------------------------------------------------------------ 9// 10 11#include "Commonasm.h" 12 13// Input registers map 14#define aPosition v0 15#define aNormal v1 16 17// Output registers map 18#define vPosition o0 19#define vQuaternion o1 20#define vView o2 21 22defi i0, 0, 0, 1 23 24#pragma bind_symbol(aPosition.xyz,v0,v0) 25#pragma bind_symbol(aNormal.xyz,v1,v1) 26 27#pragma bind_symbol(uProjection,c0,c3) 28#pragma bind_symbol(uModelView,c4,c7) 29 30#pragma output_map ( position, o0 ) 31#pragma output_map ( quaternion, o1 ) 32#pragma output_map ( view, o2 ) 33 34l_position_view_quaternion: 35 m4x4 TEMP_VIEW, dmp_position, dmp_local_to_view_matrix 36 // m3x3 is not done on purpose to prevent stalls in the following add instructions . 37 dp3 TEMP_NORM.z, dmp_normal, dmp_local_to_view_matrix[2] 38 dp3 TEMP_NORM.x, dmp_normal, dmp_local_to_view_matrix[0] 39 dp3 TEMP_NORM.y, dmp_normal, dmp_local_to_view_matrix[1] 40 mov dmp_lrView, -TEMP_VIEW 41 dp4 gl_Position.x, TEMP_VIEW, dmp_projection_matrix[0] 42 add r4, TEMP_NORM.z, CONST_1 // n.z + 1.0 is in r4 43 // m4x4 is not done on purpose to prevent stalls in the following mul instructions . 44 dp4 gl_Position.y, TEMP_VIEW, dmp_projection_matrix[1] 45 mul r4, r4, CONST_HALF // 0.5*(n.z + 1.0) is in r4 46 dp4 gl_Position.z, TEMP_VIEW, dmp_projection_matrix[2] 47 dp4 gl_Position.w, TEMP_VIEW, dmp_projection_matrix[3] 48 cmp LEQ, LEQ, r4.x, CONST_0 // compare 0.5*(n.z + 1.0) with 0.0 49 mov dmp_lrQuat.w, CONST_0 // zero out quat.w component 50 rsq r4, r4.x // 1/sqrt(0.5*(n.z + 1.0)) is in r4 51 mul r5, TEMP_NORM, CONST_HALF // 0.5*n is in r5 52 ifc 0, 1, COND_MODE_STA0 53 rcp dmp_lrQuat.z, r4.x // sqrt(0.5*(n.z + 1.0)) is in quat.z component 54 mul dmp_lrQuat.xy, r5, r4 // 0.5*n*quat.z is in quat.xy 55 else 56 mov dmp_lrQuat.xyz, CONST_1_0 // zero out quat.w component 57 endif 58 nop 59 ret 60 nop 61 62main: 63 call l_position_view_quaternion 64 end 65endmain: 66 67