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#define aTexCoord       v2
17
18// Output registers map
19#define vPosition       o0
20#define vQuaternion     o1
21#define vView           o2
22#define vTexCoord0      o3
23
24#pragma bind_symbol( aPosition.xyzw,  v0, v0 )
25#pragma bind_symbol( aNormal.xyz,     v1, v1 )
26#pragma bind_symbol( aTexCoord.xy,    v2, v2 )
27
28#pragma bind_symbol( uProjection, c0, c3 )
29#pragma bind_symbol( uModelView, c4, c7 )
30
31#pragma output_map ( position, o0 )
32#pragma output_map ( quaternion, o1 )
33#pragma output_map ( view, o2 )
34#pragma output_map ( texture0, o3.xy )
35
36
37l_position_view_quaternion:
38
39    m4x4    TEMP_VIEW,          dmp_position,       dmp_local_to_view_matrix    // Generate the model view matrix.
40    mov     dmp_lrView,         -TEMP_VIEW                                      // Outputs view vector.
41
42    m3x3    TEMP_NORM.xyz,      dmp_normal,         dmp_local_to_view_matrix    // Inner product of normal and view.
43    m4x4    gl_Position,        TEMP_VIEW,          dmp_projection_matrix       // Model view projection.
44
45    // Quaternion.
46    add     r4,                 TEMP_NORM.z,        CONST_1
47    mul     r4,                 r4,                 CONST_HALF
48    mov     dmp_lrQuat.w,       CONST_0
49    rsq     r4,                 r4.x
50    mul     r5,                 TEMP_NORM,          CONST_HALF
51    cmp     EQ, EQ,             TEMP_NORM.z,        -CONST_1
52    ifc 0, 1, COND_MODE_STA0
53        rcp     dmp_lrQuat.z,   r4.x
54        mul     dmp_lrQuat.xy,   r5,                 r4
55    else
56        mov    dmp_lrQuat.xyz, CONST_1_0
57    endif
58    nop
59    ret
60    nop
61
62main:
63    call    l_position_view_quaternion
64    mov     gl_TexCoord0,       aTexCoord
65
66    end
67endmain:
68