OpenCores
URL https://opencores.org/ocsvn/theia_gpu/theia_gpu/trunk

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_2.0/] [regressions/] [single_core/] [test_default_code1.vp] - Blame information for rev 218

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 218 diegovalve
#include "Utils.th"
2
 
3
 
4
#define CameraPosition          r51
5
#define ProjectionWindowScale   r52
6
#define ProjectionWindowMin     r53
7
#define RayDirection            r54
8
#define PrimitiveCount          r55
9
#define MaxPrimitives           r56
10
#define Pixel2DPosition         r57
11
#define Last_t                  r58
12
#define PixelColor              r59
13
#define PixelPosition           r60
14
#define InitialPosition         r61
15
#define Three                   r62
16
#define CurrentOutputPixel      r64
17
#define CurrentTextureColor     r65
18
#define V0                                              r68
19
#define V1                                              r69
20
#define V2                                              r60
21
#define TextureColor                    r61
22
#define LastColumn                              r62
23
#define Pixel2DFinalPosition    r63
24
 
25
#macro C = DotProduct( A, B )
26
        R47 = A * B;
27
        R47.x = R47.xxx + R47.yyy;
28
        C = R47.xxx + R47.zzz;
29
#endmacro
30
 
31
#macro C = CrossProduct( A, B )
32
        R47 = A.yzx * B.zxy;
33
        R48 = A.zxy * B.yzx;
34
        C = R47 - R48;
35
#endmacro
36
 
37
 
38
//Specifiy that the code is using scaled fixed point arithmetic by default
39
using fixed_point_arithmetic;
40
 
41
ProjectionWindowScale   = 0x0000147a;
42
 
43
Pixel2DPosition                 = 0;
44
ProjectionWindowMin             = 0xfff80000;
45
ProjectionWindowMin.z   = 0;
46
 
47
CameraPosition = (0,0x00040000,0x00020000);
48
MaxPrimitives  = 2;
49
PrimitiveCount = 2;
50
LastColumn = 10;
51
 
52
V1 = (0x00050000, 0xfffa0000, 0x00000000 );
53
 
54
V0 = (0xfffb0000, 0xfffa0000,0x00000000 );
55
 
56
V2 = (0x00050000, 0x00040000,0x00000000 );
57
 
58
 
59
//----------------------------------------------------------
60
function main()
61
 {
62
        vector Hit,AllDone;
63
        //Make sure GenerateRay is only called once
64
         if ( PrimitiveCount == MaxPrimitives )
65
         {
66
                 GenerateRay();
67
                 Hit = 0;
68
         }
69
        Hit = CalculateBaricentricIntersection();
70
        PrimitiveCount--;
71
         if ( PrimitiveCount != 0 )
72
         {
73
                exit;
74
         }
75
 
76
         if (Hit != 0)
77
         {
78
                TextureCalculation();
79
                PrePixelShader();
80
         }
81
 
82
        PixelShader();
83
        GenerateNextPixel();
84
        return 1;
85
         exit;
86
}
87
 
88
//----------------------------------------------------------
89
function GenerateRay()
90
{
91
                vector UnnormalizedDirection, tmp;
92
 
93
                UnnormalizedDirection = (ProjectionWindowMin + Pixel2DPosition * ProjectionWindowScale  ) - CameraPosition;
94
                tmp = UnnormalizedDirection * UnnormalizedDirection;            //tmp = (x^2,y^2,z^2)
95
                RayDirection = UnnormalizedDirection / sqrt( tmp.xxx + tmp.yyy + tmp.zzz );
96
 
97
 
98
         return ;
99
 
100
}
101
//---------------------------------------------------------------------
102
function CalculateBaricentricIntersection()
103
{
104
        vector E1,E2,T,P,Q,H;
105
        vector Delta,t;
106
 
107
        PixelColor = 0;
108
        T.y = 1;
109
        E1 = V1 - V0;
110
        E2 = V2 - V0;
111
        T = CameraPosition - V0;
112
        P = CrossProduct( RayDirection, E2 );
113
        Q = CrossProduct( T, E1 );
114
        H.x = DotProduct(Q,E2);
115
        H.y = DotProduct(P,T);
116
        H.z = DotProduct( Q, RayDirection );
117
        Delta = DotProduct( P, E1 );
118
        t = H / Delta;
119
 
120
        vector ExpectedResult = (0x000e8f71, 0xffffcccd, 0xffff999a);
121
        if ( t != ExpectedResult)
122
        {
123
                R66 = 0xdead;
124
        } else {
125
                R66 = 0xaced;
126
        }
127
 
128
         if (t.yyy >= 0)
129
         {
130
                 E2.y = E1.zzz + E1;
131
                 if (E2.yyy > T.yyy)
132
                 { return 0; }
133
 
134
         } else {
135
                 return 0;
136
        }
137
 
138
        return 1;
139
}
140
//---------------------------------------------------------------------
141
function PixelShader()
142
{
143
        //This does nothing because IO is not yet implemented
144
        //I = { `OMWRITE ,`OREG_PIXEL_COLOR ,`CREG_CURRENT_OUTPUT_PIXEL ,`CREG_TEXTURE_COLOR };
145
        return ;
146
}
147
//---------------------------------------------------------------------
148
function GenerateNextPixel()
149
{
150
         PrimitiveCount = MaxPrimitives;
151
         TextureColor = 0;
152
         CurrentOutputPixel += 3;
153
 
154
 
155
         if (Pixel2DPosition.xxx >= LastColumn.xxx )
156
         {
157
                 Pixel2DPosition.x++;
158
                 return 0;
159
         } else {
160
                 Pixel2DPosition.x = 0;
161
                 Pixel2DPosition.y++;
162
                 if (Pixel2DPosition.yyy == Pixel2DFinalPosition.yyy)
163
                 {
164
                         return 1;
165
                 } else {
166
                         return 0;
167
                 }
168
 
169
         }
170
}
171
//---------------------------------------------------------------------
172
//Do this calculation only if this triangle is the one closest to the camera
173
function TextureCalculation()
174
{
175
        // vector uv_coordinate, fuv, uv1, uv2;
176
        // vector w1,w2,w3,w4;
177
 
178
        // //u_coordinate = U0 + last_u * (U1 - U0) + last_v * (U2 - U0);
179
        // //v_coordinate = V0 + last_u * (V1 - V0) + last_v * (V2 - V0);
180
        // uv_coordinate = UV0 + last_uv.xxx * (UV1 - UV0) + last_uv.yyy * (UV2 - UV0);
181
 
182
        // //fu = (u_coordinate) * gTexture.mWidth
183
        // //fv = (v_coordinate) * gTexture.mWidth
184
        // fuv.x  = (uv_coordinate) * gTextureSize.xxx;
185
 
186
        // //u1 = ((int)fu) % gTexture.mWidth
187
        // //v1 = ((int)fv) % gTexture.mHeight
188
        // uv1 = integer( fuv ) %  gTextureSize;
189
 
190
        // //u2 = (u1 + 1 ) % gTexture.mWidth
191
        // //v2 = (v2 + 1 ) % gTexture.mHeight
192
        // uv2 = (uv1 + 1) % gTextureSize;
193
 
194
        // //Cool now we should store the values in the appropiate registers
195
        // //TextureOutputCoord1.x = u1 + v1 * gTexture.mWidth
196
        // //TextureOutputCoord1.y = u2 + v1 * gTexture.mWidth
197
        // //TextureOutputCoord1.z = 0
198
        // //TextureOutputCoord2.x = u1 + v2 * gTexture.mWidth
199
        // //TextureOutputCoord2.y = u2 + v2 * gTexture.mWidth
200
        // //TextureOutputCoord2.z = 0
201
 
202
        // TextureOutputCoord1.x = uv1.xxx + uv1.yyy * gTextureSize.xxx;
203
        // TextureOutputCoord1.y = uv2.xxx + uv1.yyy * gTextureSize.xxx;
204
        // TextureOutputCoord1.z = 0;
205
 
206
        // TextureOutputCoord2.x = uv1.xxx + uv2.yyy * gTextureSize.xxx;
207
        // TextureOutputCoord2.y = uv2.xxx + uv2.yyy * gTextureSize.xxx;
208
        // TextureOutputCoord2.z = 0;
209
 
210
        // //Cool now get the weights
211
        // //w1.xyz = (1 - fracu) * (1 - fracv)
212
        // //w2.xyz = fracu * (1 - fracv)
213
        // //w3.xyz = (1 - fracu) * fracv
214
        // //w4.xyz = fracu *  fracv
215
        // vector ones = (1,1,1);
216
        // vector fracuv;
217
 
218
        // fracuv = fraction( fuv );
219
 
220
        // w1 = ones - fracuv;
221
        // w2 = fracuv * w1.yxz;
222
        // w3 = w2.yyy;
223
        // w2 = w2.xxx;
224
        // w4 = fracuv.xxx * fracuv.yyy;
225
 
226
        // //All done, let's get out of here
227
        return ;
228
 
229
}
230
//---------------------------------------------------------------------
231
function PrePixelShader()
232
{
233
        return ;
234
}
235
//---------------------------------------------------------------------

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.