1 | {$i bgrasse.inc}
|
---|
2 |
|
---|
3 | var
|
---|
4 | //loop variables
|
---|
5 | pdest: PBGRAPixel;
|
---|
6 | i: LongInt;
|
---|
7 |
|
---|
8 | InvXLen: single; //inverse of horizontal length in pixels
|
---|
9 | t: single; //initial horizontal position in [0..1]
|
---|
10 | {$IFNDEF PARAM_USESOLIDCOLOR}
|
---|
11 | texPosByZ: TPointF;
|
---|
12 | intTexPos: packed record
|
---|
13 | x,y: integer;
|
---|
14 | end;
|
---|
15 | texPos: TPoint3D_128; //texture start position
|
---|
16 | {$ENDIF}
|
---|
17 | InvZPos: single; //Z: depth start position
|
---|
18 |
|
---|
19 | {$IFNDEF PARAM_USESOLIDCOLOR}
|
---|
20 | texStep: TPoint3D_128; //texture step
|
---|
21 | {$ENDIF}
|
---|
22 | zStep: single; //depth step
|
---|
23 |
|
---|
24 | {$IFNDEF PARAM_USESOLIDCOLOR}
|
---|
25 | texVect: TPointF; //texture vector between start and end of line
|
---|
26 | {$ENDIF}
|
---|
27 | zLen: single; //depth difference
|
---|
28 | {$IFDEF PARAM_USESHADER}
|
---|
29 | tempVect3D: TPoint3D_128;
|
---|
30 | {$ENDIF}
|
---|
31 |
|
---|
32 | {$IFNDEF PARAM_USESOLIDCOLOR}
|
---|
33 | {$DEFINE PARAM_USEZPOS}
|
---|
34 | {$ENDIF}
|
---|
35 | {$IFDEF PARAM_USESHADER}
|
---|
36 | {$DEFINE PARAM_USEZPOS}
|
---|
37 | {$ENDIF}
|
---|
38 |
|
---|
39 | {$IFDEF PARAM_USEZPOS}
|
---|
40 | zPos: single;
|
---|
41 | {$ENDIF}
|
---|
42 |
|
---|
43 | {$IFDEF PARAM_USEZBUFFER}
|
---|
44 | pzbuffer: PSingle;
|
---|
45 | {$ENDIF}
|
---|
46 |
|
---|
47 | {$IFDEF PARAM_USELIGHTING}
|
---|
48 | light,lightStep,lightDiff,lightAcc,lightMod: word;
|
---|
49 | lightLen: integer;
|
---|
50 |
|
---|
51 | procedure NextLight; inline;
|
---|
52 | begin
|
---|
53 | light := (light+lightStep) and 65535;
|
---|
54 | inc(lightAcc,lightDiff);
|
---|
55 | if lightAcc >= lightMod then
|
---|
56 | begin
|
---|
57 | dec(lightAcc,lightMod);
|
---|
58 | light := (light + 1) and 65535;
|
---|
59 | end;
|
---|
60 | end;
|
---|
61 | {$ENDIF}
|
---|
62 |
|
---|
63 | begin
|
---|
64 | InvXLen := 1/(info2.interX - info1.interX);
|
---|
65 | t := ((ix1+0.5)-info1.interX)*InvXLen;
|
---|
66 |
|
---|
67 | {$IFNDEF PARAM_USESOLIDCOLOR}
|
---|
68 | texVect := info2.texCoordDivByZ-info1.texCoordDivByZ;
|
---|
69 | texPos := Point3D_128(info1.texCoordDivByZ + texVect*t);
|
---|
70 | texStep := Point3D_128(texVect*InvXLen);
|
---|
71 | {$ENDIF}
|
---|
72 | zLen := info2.coordInvZ-info1.coordInvZ;
|
---|
73 | InvZPos := info1.coordInvZ+t*zLen;
|
---|
74 | zStep := zLen*InvXLen;
|
---|
75 |
|
---|
76 | {$IFDEF PARAM_USESHADER}
|
---|
77 | tempVect3D := info2.Position3D - info1.Position3D;
|
---|
78 | ShaderContext^.PositionInvZ := info1.Position3D + tempVect3D*t;
|
---|
79 | ShaderContext^.PositionStepInvZ := tempVect3D*InvXLen;
|
---|
80 |
|
---|
81 | tempVect3D := info2.Normal3D - info1.Normal3D;
|
---|
82 | ShaderContext^.NormalInvZ := info1.Normal3D + tempVect3D*t;
|
---|
83 | ShaderContext^.NormalStepInvZ := tempVect3D*InvXLen;
|
---|
84 | {$endif}
|
---|
85 |
|
---|
86 | pdest := bmp.ScanLine[yb]+ix1;
|
---|
87 | {$IFDEF PARAM_USEZBUFFER}
|
---|
88 | pzbuffer := zbuffer + yb*bmp.Width + ix1;
|
---|
89 | {$ENDIF}
|
---|
90 |
|
---|
91 | {$IFDEF PARAM_USELIGHTING}
|
---|
92 | if ix2 = ix1 then
|
---|
93 | begin
|
---|
94 | light := (info1.lightness+info2.lightness) div 2;
|
---|
95 | lightStep := 0;
|
---|
96 | lightDiff := 0;
|
---|
97 | lightMod := 1;
|
---|
98 | end
|
---|
99 | else
|
---|
100 | begin
|
---|
101 | light := info1.lightness;
|
---|
102 | lightLen := info2.lightness-info1.lightness;
|
---|
103 | if lightLen >= 0 then
|
---|
104 | begin
|
---|
105 | lightStep := lightLen div (ix2-ix1);
|
---|
106 | lightMod := ix2-ix1;
|
---|
107 | lightDiff := lightLen - lightStep*(ix2-ix1);
|
---|
108 | end else
|
---|
109 | begin
|
---|
110 | lightStep := (-lightLen+(ix2-ix1-1)) div (ix2-ix1);
|
---|
111 | lightMod := ix2-ix1;
|
---|
112 | lightDiff := lightLen + lightStep*(ix2-ix1);
|
---|
113 | lightStep := 65536 - lightStep;
|
---|
114 | end;
|
---|
115 | end;
|
---|
116 | lightAcc := lightDiff div 2;
|
---|
117 | {$ENDIF}
|
---|
118 |
|
---|
119 | {$IFDEF BGRASSE_AVAILABLE}
|
---|
120 | if UseSSE then
|
---|
121 | begin
|
---|
122 | {$DEFINE PARAM_USESSE}
|
---|
123 | if UseSSE3 then
|
---|
124 | begin
|
---|
125 | {$DEFINE PARAM_USESSE3}
|
---|
126 | if WithInterpolation then
|
---|
127 | begin
|
---|
128 | {$DEFINE PARAM_USEINTERPOLATION}
|
---|
129 | {$i perspectivescan2.inc}
|
---|
130 | {$UNDEF PARAM_USEINTERPOLATION}
|
---|
131 | end else
|
---|
132 | begin
|
---|
133 | {$i perspectivescan2.inc}
|
---|
134 | end;
|
---|
135 | {$UNDEF PARAM_USESSE3}
|
---|
136 | end else
|
---|
137 | begin
|
---|
138 | if WithInterpolation then
|
---|
139 | begin
|
---|
140 | {$DEFINE PARAM_USEINTERPOLATION}
|
---|
141 | {$i perspectivescan2.inc}
|
---|
142 | {$UNDEF PARAM_USEINTERPOLATION}
|
---|
143 | end else
|
---|
144 | begin
|
---|
145 | {$i perspectivescan2.inc}
|
---|
146 | end;
|
---|
147 | end;
|
---|
148 | {$UNDEF PARAM_USESSE}
|
---|
149 | end else
|
---|
150 | {$ENDIF}
|
---|
151 | begin
|
---|
152 | if WithInterpolation then
|
---|
153 | begin
|
---|
154 | {$DEFINE PARAM_USEINTERPOLATION}
|
---|
155 | {$i perspectivescan2.inc}
|
---|
156 | {$UNDEF PARAM_USEINTERPOLATION}
|
---|
157 | end else
|
---|
158 | begin
|
---|
159 | {$i perspectivescan2.inc}
|
---|
160 | end;
|
---|
161 | end;
|
---|
162 | end;
|
---|
163 | {$undef PARAM_USELIGHTING}
|
---|
164 | {$undef PARAM_USESHADER}
|
---|
165 | {$undef PARAM_USESOLIDCOLOR}
|
---|
166 | {$undef PARAM_USEZBUFFER}
|
---|
167 | {$undef PARAM_USEZPOS}
|
---|