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 229

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 229 diegovalve
//#define CurrentOutputPixel      r64
17
//#define CurrentTextureColor     r65
18 218 diegovalve
#define V0                                              r68
19
#define V1                                              r69
20
#define V2                                              r60
21 229 diegovalve
//#define TextureColor                  r61
22 218 diegovalve
#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 229 diegovalve
        Pixel2DFinalPosition.x = 255;
60
        Pixel2DFinalPosition.y = 255;
61
        Pixel2DFinalPosition.z = 255;
62
 
63 218 diegovalve
//----------------------------------------------------------
64
function main()
65
 {
66
        vector Hit,AllDone;
67 229 diegovalve
        vector CurrentOutputPixel = (0,1,2);
68
        vector CurrentTextureColor = (0xa,0xb,0xc);
69
 
70 218 diegovalve
        //Make sure GenerateRay is only called once
71
         if ( PrimitiveCount == MaxPrimitives )
72
         {
73
                 GenerateRay();
74
                 Hit = 0;
75
         }
76
        Hit = CalculateBaricentricIntersection();
77 229 diegovalve
 
78 218 diegovalve
        PrimitiveCount--;
79 229 diegovalve
         if ( PrimitiveCount == 0 )      {      exit;  }
80 218 diegovalve
 
81
         if (Hit != 0)
82
         {
83
                TextureCalculation();
84
                PrePixelShader();
85
         }
86
 
87 229 diegovalve
        PixelShader( CurrentOutputPixel, CurrentTextureColor );
88 218 diegovalve
        GenerateNextPixel();
89 229 diegovalve
 
90
         exit ;
91 218 diegovalve
}
92
 
93
//----------------------------------------------------------
94
function GenerateRay()
95
{
96
                vector UnnormalizedDirection, tmp;
97
 
98
                UnnormalizedDirection = (ProjectionWindowMin + Pixel2DPosition * ProjectionWindowScale  ) - CameraPosition;
99
                tmp = UnnormalizedDirection * UnnormalizedDirection;            //tmp = (x^2,y^2,z^2)
100
                RayDirection = UnnormalizedDirection / sqrt( tmp.xxx + tmp.yyy + tmp.zzz );
101
 
102
 
103
         return ;
104
 
105
}
106
//---------------------------------------------------------------------
107
function CalculateBaricentricIntersection()
108
{
109
        vector E1,E2,T,P,Q,H;
110
        vector Delta,t;
111
 
112
        PixelColor = 0;
113
        T.y = 1;
114
        E1 = V1 - V0;
115
        E2 = V2 - V0;
116
        T = CameraPosition - V0;
117
        P = CrossProduct( RayDirection, E2 );
118
        Q = CrossProduct( T, E1 );
119
        H.x = DotProduct(Q,E2);
120
        H.y = DotProduct(P,T);
121
        H.z = DotProduct( Q, RayDirection );
122
        Delta = DotProduct( P, E1 );
123
        t = H / Delta;
124
 
125
        vector ExpectedResult = (0x000e8f71, 0xffffcccd, 0xffff999a);
126
        if ( t != ExpectedResult)
127
        {
128
                R66 = 0xdead;
129 229 diegovalve
                exit ;
130 218 diegovalve
        } else {
131
                R66 = 0xaced;
132
        }
133
 
134
         if (t.yyy >= 0)
135
         {
136
                 E2.y = E1.zzz + E1;
137
                 if (E2.yyy > T.yyy)
138
                 { return 0; }
139
 
140
         } else {
141
                 return 0;
142
        }
143
 
144
        return 1;
145
}
146
//---------------------------------------------------------------------
147 229 diegovalve
function PixelShader( CurrentOutputPixel, CurrentTextureColor )
148 218 diegovalve
{
149 229 diegovalve
        //CurrentOutputPixel = CurrentTextureColor;  // What the hell?????
150
        out[ CurrentOutputPixel ] = CurrentTextureColor.xyz;
151 218 diegovalve
        return ;
152
}
153
//---------------------------------------------------------------------
154 229 diegovalve
function GenerateNextPixel( CurrentOutputPixel, CurrentTextureColor )
155 218 diegovalve
{
156
         PrimitiveCount = MaxPrimitives;
157 229 diegovalve
         CurrentTextureColor = 0;
158 218 diegovalve
         CurrentOutputPixel += 3;
159
 
160
 
161
         if (Pixel2DPosition.xxx >= LastColumn.xxx )
162
         {
163
                 Pixel2DPosition.x++;
164
                 return 0;
165
         } else {
166
                 Pixel2DPosition.x = 0;
167
                 Pixel2DPosition.y++;
168
                 if (Pixel2DPosition.yyy == Pixel2DFinalPosition.yyy)
169
                 {
170
                         return 1;
171
                 } else {
172
                         return 0;
173
                 }
174
 
175
         }
176
}
177
//---------------------------------------------------------------------
178
//Do this calculation only if this triangle is the one closest to the camera
179
function TextureCalculation()
180
{
181
        // vector uv_coordinate, fuv, uv1, uv2;
182
        // vector w1,w2,w3,w4;
183
 
184
        // //u_coordinate = U0 + last_u * (U1 - U0) + last_v * (U2 - U0);
185
        // //v_coordinate = V0 + last_u * (V1 - V0) + last_v * (V2 - V0);
186
        // uv_coordinate = UV0 + last_uv.xxx * (UV1 - UV0) + last_uv.yyy * (UV2 - UV0);
187
 
188
        // //fu = (u_coordinate) * gTexture.mWidth
189
        // //fv = (v_coordinate) * gTexture.mWidth
190
        // fuv.x  = (uv_coordinate) * gTextureSize.xxx;
191
 
192
        // //u1 = ((int)fu) % gTexture.mWidth
193
        // //v1 = ((int)fv) % gTexture.mHeight
194
        // uv1 = integer( fuv ) %  gTextureSize;
195
 
196
        // //u2 = (u1 + 1 ) % gTexture.mWidth
197
        // //v2 = (v2 + 1 ) % gTexture.mHeight
198
        // uv2 = (uv1 + 1) % gTextureSize;
199
 
200
        // //Cool now we should store the values in the appropiate registers
201
        // //TextureOutputCoord1.x = u1 + v1 * gTexture.mWidth
202
        // //TextureOutputCoord1.y = u2 + v1 * gTexture.mWidth
203
        // //TextureOutputCoord1.z = 0
204
        // //TextureOutputCoord2.x = u1 + v2 * gTexture.mWidth
205
        // //TextureOutputCoord2.y = u2 + v2 * gTexture.mWidth
206
        // //TextureOutputCoord2.z = 0
207
 
208
        // TextureOutputCoord1.x = uv1.xxx + uv1.yyy * gTextureSize.xxx;
209
        // TextureOutputCoord1.y = uv2.xxx + uv1.yyy * gTextureSize.xxx;
210
        // TextureOutputCoord1.z = 0;
211
 
212
        // TextureOutputCoord2.x = uv1.xxx + uv2.yyy * gTextureSize.xxx;
213
        // TextureOutputCoord2.y = uv2.xxx + uv2.yyy * gTextureSize.xxx;
214
        // TextureOutputCoord2.z = 0;
215
 
216
        // //Cool now get the weights
217
        // //w1.xyz = (1 - fracu) * (1 - fracv)
218
        // //w2.xyz = fracu * (1 - fracv)
219
        // //w3.xyz = (1 - fracu) * fracv
220
        // //w4.xyz = fracu *  fracv
221
        // vector ones = (1,1,1);
222
        // vector fracuv;
223
 
224
        // fracuv = fraction( fuv );
225
 
226
        // w1 = ones - fracuv;
227
        // w2 = fracuv * w1.yxz;
228
        // w3 = w2.yyy;
229
        // w2 = w2.xxx;
230
        // w4 = fracuv.xxx * fracuv.yyy;
231
 
232
        // //All done, let's get out of here
233
        return ;
234
 
235
}
236
//---------------------------------------------------------------------
237
function PrePixelShader()
238
{
239
        return ;
240
}
241
//---------------------------------------------------------------------

powered by: WebSVN 2.1.0

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