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#define vTexCoord o3 22 23#pragma bind_symbol(aPosition.xyz,v0,v0) 24#pragma bind_symbol(aNormal.xyz,v1,v1) 25 26#pragma bind_symbol(uProjection,c0,c3) 27#pragma bind_symbol(uModelView,c4,c7) 28#pragma bind_symbol(uWorld,c8,c11) 29 30#pragma output_map ( position, o0 ) 31#pragma output_map ( quaternion, o1 ) 32#pragma output_map ( view, o2 ) 33#pragma output_map ( texture0, o3.xy ) 34#pragma output_map ( texture0w, o3.z ) 35 36l_position_view_quaternion_reflection: 37 m4x4 TEMP_VIEW, dmp_position, dmp_local_to_view_matrix 38 39 m3x3 TEMP_NORM.xyz, dmp_normal, dmp_local_to_view_matrix 40 41 mov dmp_lrView, -TEMP_VIEW 42 43 dp3 TEMP0, -TEMP_VIEW, TEMP_NORM 44 dp4 gl_Position.x, TEMP_VIEW, dmp_projection_matrix[0] 45 add r4, TEMP_NORM.z, CONST_1 // n.z + 1.0 is in r4 46 // m4x4 is not done on purpose to prevent stalls in the following mul instructions . 47 dp4 gl_Position.y, TEMP_VIEW, dmp_projection_matrix[1] 48 mul r4, r4, CONST_HALF // 0.5*(n.z + 1.0) is in r4 49 dp4 gl_Position.z, TEMP_VIEW, dmp_projection_matrix[2] 50 51 add TEMP0, TEMP0, TEMP0 52 53 dp4 gl_Position.w, TEMP_VIEW, dmp_projection_matrix[3] 54 cmp LEQ, LEQ, r4.x, CONST_0 // compare 0.5*(n.z + 1.0) with 0.0 55 56 mad TEMP0, TEMP0, TEMP_NORM, TEMP_VIEW 57 58 mov dmp_lrQuat.w, CONST_0 // zero out quat.w component 59 60 rsq r4, r4.x // 1/sqrt(0.5*(n.z + 1.0)) is in r4 61 mul r5, TEMP_NORM, CONST_HALF // 0.5*n is in r5 62 ifc 0, 1, COND_MODE_STA0 63 rcp dmp_lrQuat.z, r4.x // sqrt(0.5*(n.z + 1.0)) is in quat.z component 64 mul dmp_lrQuat.xy, r5, r4 // 0.5*n*quat.z is in quat.xy 65 else 66 mov dmp_lrQuat.xyz, CONST_1_0 // zero out quat.w component 67 endif 68 69 m3x3 gl_TexCoord0.xyz, TEMP0, dmp_local_to_world_matrix 70 mov gl_TexCoord0.w, CONST_0 71 ret 72 nop 73 74main: 75 call l_position_view_quaternion_reflection 76 end 77endmain: 78