1// ---------------------------------------------------------------------------
2//  Project:  NintendoWare
3//  File:     lyt_PaneShader.vsh
4//
5//  Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6//
7//  These coded instructions, statements, and computer programs contain proprietary
8//  information of Nintendo and/or its licensed developers and are protected by
9//  national and international copyright laws. They may not be disclosed to third
10//  parties or copied or duplicated in any form, in whole or in part, without the
11//  prior written consent of Nintendo.
12//
13//  The content herein is highly confidential and should be handled accordingly.
14//
15//  $Revision: 31311 $
16// ---------------------------------------------------------------------------
17
18// Input registers map
19
20#pragma bind_symbol(aVertexIndex,   v0, v0)
21
22// Constant values
23
24#pragma bind_symbol(uProjection,    c0, c3)
25#pragma bind_symbol(uModelView,     c4, c6)
26#pragma bind_symbol(uTransform,     c7, c7)
27#pragma bind_symbol(uTexMtx0,       c8, c9)
28#pragma bind_symbol(uTexMtx1,       c10, c11)
29#pragma bind_symbol(uTexMtx2,       c12, c13)
30#pragma bind_symbol(uColor,         c14, c14)
31#pragma bind_symbol(uFrameSpec,     c15, c15)
32#pragma bind_symbol(uVertexColor,   c16, c19)
33#pragma bind_symbol(uVertexTexCoord0, c20, c23)
34#pragma bind_symbol(uVertexTexCoord1, c24, c27)
35#pragma bind_symbol(uVertexTexCoord2, c28, c31)
36#pragma bind_symbol(uRcpTexSize0,   c32, c32)
37
38// Output registers map
39
40#pragma output_map(position,    o0)
41#pragma output_map(color,       o1)
42#pragma output_map(texture0,    o2.xy)
43#pragma output_map(texture1,    o3.xy)
44#pragma output_map(texture2,    o4.xy)
45
46#define aVertexIndex            v0
47
48#define uProjection             c0
49#define uModelView              c4
50#define uTransform              c7
51#define uTexMtx0                c8
52#define uTexMtx1                c10
53#define uTexMtx2                c12
54#define uColor                  c14
55#define uFrameSpec              c15
56#define uVertexColor            c16
57#define uVertexTexCoord0        c20
58#define uVertexTexCoord1        c24
59#define uVertexTexCoord2        c28
60#define uRcpTexSize0            c32
61
62#define vPosition               o0
63#define vColor                  o1
64#define vTexCoord0              o2
65#define vTexCoord1              o3
66#define vTexCoord2              o4
67
68#define CONST                   c95
69def     CONST,                  0.0, 0.5, 1.0, 255
70#define CONST_0                 CONST.x
71#define CONST_1_2               CONST.y
72#define CONST_1                 CONST.z
73#define CONST_255               CONST.w
74#define CONST_0_0_0_1           CONST.xxxz
75
76#define CONST2                  c94
77def     CONST2,                 1, -1, 0, 2
78
79#define CMP_EQ 0
80#define CMP_NE 1
81#define CMP_LT 2
82#define CMP_LE 3
83#define CMP_GT 4
84#define CMP_GE 5
85
86#define ifc_0_or_1(c0, c1)      ifc c0, c1, 0
87#define ifc_0_and_1(c0, c1)     ifc c0, c1, 1
88#define ifc_0(c0)               ifc c0,  0, 2
89#define ifc_1(c1)               ifc  0, c1, 3
90
91#define aPosition               r0
92#define aColor                  r1
93#define aTexCoord0              r2
94#define aTexCoord1              r3
95#define aTexCoord2              r4
96#define aFrameSpec              r5
97#define aTexScale               r6
98
99#define tmp0                    r15
100#define tmp1                    r14
101
102main:
103    // aPosition = [ aVertexIndex.x, - aVertexIndex.y, 0, 1 ]
104    mul     aPosition, aVertexIndex, CONST2.xyzz
105    mov     aPosition.zw, CONST2.zzzx
106
107    // if (IsConstVertex(uFrameSpec)) {
108    //   aTexCoord[0,1,2] = [ aVertex.x, aVertex.y, 0, 1 ]
109    //   aColor = 255
110    // } else {
111    //   i = 1 * aVertex.x + 2 * aVertex.y
112    //   aTexCoord[0,1,2] = uVertexTexCoord[0,1,2][i]
113    //   aColor = uVertexColor[i]
114    // }
115    mov     aFrameSpec, uFrameSpec
116    mul     aFrameSpec.xy, aFrameSpec.x, CONST_1_2
117    flr     aFrameSpec.x, aFrameSpec
118    cmp     CMP_GT, CMP_GT, aFrameSpec.y, aFrameSpec.x
119    ifc_0(1)
120        mov     aTexCoord0, aVertexIndex
121        mov     aTexCoord0.zw, CONST2.zzzx
122        mov     aTexCoord1, aTexCoord0
123        mov     aTexCoord2, aTexCoord0
124        mov     aColor, CONST_255
125    else
126        dp3     tmp0, aVertexIndex, CONST2.xwz
127        mova    a0.xy, tmp0
128        mov     aTexCoord0, uVertexTexCoord0[a0.x]
129        mov     aTexCoord1, uVertexTexCoord1[a0.x]
130        mov     aTexCoord2, uVertexTexCoord2[a0.x]
131        mov     aColor, uVertexColor[a0.x]
132    endif
133
134    // POSITION TRANSFORM
135    mov     tmp0, uTransform
136    mad     aPosition.xy, aPosition.xy, tmp0.xy, tmp0.zw
137    dp4     tmp0.x, aPosition, uModelView[0]
138    dp4     tmp0.y, aPosition, uModelView[1]
139    dp4     tmp0.z, aPosition, uModelView[2]
140    mov     tmp0.w, aPosition.w
141    m4x4    vPosition, tmp0, uProjection
142
143    // GLOBAL COLOR
144    mul     vColor, aColor, uColor
145
146    // TEXCOORD0 FRAME TRANSFORM
147    // if (IsFrame(uFrameSpec)) {
148    mul     aFrameSpec.xy, aFrameSpec.x, CONST_1_2
149    flr     aFrameSpec.x, aFrameSpec
150    cmp     CMP_GT, CMP_GT, aFrameSpec.y, aFrameSpec.x
151    ifc_0(1)
152
153        // texSize = uFrameSpec.zw
154        // if (IsSwap(uFrameSpec)) {
155        //   aTexScale = polySize * uRcpTexSize0.yx
156        // } else {
157        //   aTexScale = polySize * uRcpTexSize0.xy
158        // }
159        mul     aFrameSpec.xy, aFrameSpec.x, CONST_1_2
160        flr     aFrameSpec.x, aFrameSpec
161        mov     tmp1, aFrameSpec
162        cmp     CMP_GT, CMP_GT, aFrameSpec.y, aFrameSpec.x
163        mov     aTexScale, uTransform
164        ifc_0(1)
165            mul     aTexScale, aTexScale, uRcpTexSize0.yx
166        else
167            mul     aTexScale, aTexScale, uRcpTexSize0.xy
168        endif
169
170        // aTexCoord[0,1,2] *= texScale
171        mul     aTexCoord0.xy, aTexCoord0, aTexScale
172        mul     aTexCoord1.xy, aTexCoord1, aTexScale
173        mul     aTexCoord2.xy, aTexCoord2, aTexScale
174
175        // if (IsRight(uFrameSpec)) {
176        //   aTexCoord[0,1,2].x += 1 - texScale.x
177        // }
178        mul     aFrameSpec.xy, aFrameSpec.x, CONST_1_2
179        flr     aFrameSpec.x, aFrameSpec
180        cmp     CMP_GT, CMP_GT, aFrameSpec.y, aFrameSpec.x
181        add     aTexScale, CONST_1, -aTexScale
182        ifc_0(1)
183            add aTexCoord0.x, aTexCoord0, aTexScale
184            add aTexCoord1.x, aTexCoord1, aTexScale
185            add aTexCoord2.x, aTexCoord2, aTexScale
186        endif
187
188        // if (IsBottom(uFrameSpec)) {
189        //   aTexCoord[0,1,2].y += 1 - texScale.y
190        // }
191        mul     aFrameSpec.xy, aFrameSpec.x, CONST_1_2
192        flr     aFrameSpec.x, aFrameSpec
193        cmp     CMP_GT, CMP_GT, aFrameSpec.y, aFrameSpec.x
194        ifc_0(1)
195            add aTexCoord0.y, aTexCoord0, aTexScale
196            add aTexCoord1.y, aTexCoord1, aTexScale
197            add aTexCoord2.y, aTexCoord2, aTexScale
198        endif
199
200        // if (IsHorizontalFlip(uFrameSpec)) {
201        //   aTexCoord[0,1,2].x = 1 - aTexCoord[0,1,2].x
202        // }
203        mul     aFrameSpec.xy, aFrameSpec.x, CONST_1_2
204        flr     aFrameSpec.x, aFrameSpec
205        cmp     CMP_GT, CMP_GT, aFrameSpec.y, aFrameSpec.x
206        ifc_0(1)
207            add aTexCoord0.x, CONST_1, -aTexCoord0
208            add aTexCoord1.x, CONST_1, -aTexCoord1
209            add aTexCoord2.x, CONST_1, -aTexCoord2
210        endif
211
212        // if (IsVerticalFlip(uFrameSpec)) {
213        //   aTexCoord[0,1,2].y = 1 - aTexCoord[0,1,2].y
214        // }
215        mul     aFrameSpec.xy, aFrameSpec.x, CONST_1_2
216        flr     aFrameSpec.x, aFrameSpec
217        cmp     CMP_GT, CMP_GT, aFrameSpec.y, aFrameSpec.x
218        ifc_0(1)
219            add aTexCoord0.y, CONST_1, -aTexCoord0
220            add aTexCoord1.y, CONST_1, -aTexCoord1
221            add aTexCoord2.y, CONST_1, -aTexCoord2
222        endif
223
224        // if (IsSwap(uFrameSpec)) {
225        //   aTexCoord[0,1,2].xy = aTexCoord[0,1,2].yx
226        // }
227        cmp     CMP_GT, CMP_GT, tmp1.y, tmp1.x
228        ifc_0(1)
229            mov     aTexCoord0, aTexCoord0.yxzw
230            mov     aTexCoord1, aTexCoord1.yxzw
231            mov     aTexCoord2, aTexCoord2.yxzw
232        endif
233
234    nop
235    endif
236
237    // TEXCOORD TRANSFORM
238    dp4     vTexCoord0.xz, aTexCoord0, uTexMtx0[0]
239    dp4     vTexCoord0.yw, aTexCoord0, uTexMtx0[1]
240    dp4     vTexCoord1.xz, aTexCoord1, uTexMtx1[0]
241    dp4     vTexCoord1.yw, aTexCoord1, uTexMtx1[1]
242    dp4     vTexCoord2.xz, aTexCoord2, uTexMtx2[0]
243    dp4     vTexCoord2.yw, aTexCoord2, uTexMtx2[1]
244    end
245endmain:
246