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