source: trunk/Packages/bgrabitmap/perspectivescan2.inc

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 5.7 KB
Line 
1{$i bgrasse.inc}
2
3{$ifdef BGRASSE_AVAILABLE}{$asmmode intel}{$endif}
4 {$IFDEF PARAM_USESSE}
5 asm
6 {$IFDEF PARAM_USESHADER}
7 {$IFDEF cpux86_64}
8 mov rax, ShaderContext
9 movaps xmm2, [rax+32] //positionInvZ
10 movaps xmm3, [rax+48] //normalInvZ
11 {$ELSE}
12 mov eax, ShaderContext
13 movaps xmm2, [eax+32] //positionInvZ
14 movaps xmm3, [eax+48] //normalInvZ
15 {$ENDIF}
16 {$ENDIF}
17 {$IFNDEF PARAM_USESOLIDCOLOR}
18 xorps xmm5,xmm5
19 movlps xmm5, texPos
20 {$ENDIF}
21 end;
22 {$ENDIF}
23 for i := ix1 to ix2 do
24 begin
25 {$IFDEF PARAM_USESSE}
26 {$IFDEF PARAM_USEZBUFFER}
27 if InvZPos > pzbuffer^ then
28 begin
29 pzbuffer^ := InvZPos;
30 {$ENDIF}
31 asm
32 movss xmm4, InvZPos
33 rcpss xmm4,xmm4 //zPos
34 shufps xmm4,xmm4,0 //broadcast
35
36 {$IFDEF PARAM_USESHADER}
37 {$ifdef cpux86_64}
38 mov rax, ShaderContext
39 {$else}
40 mov eax, ShaderContext
41 {$endif}
42
43 mulps xmm2, xmm4 //positionInvZ*zPos (A)
44 mulps xmm3, xmm4 //normalInvZ*zPos
45 {$ifdef cpux86_64}
46 movaps [rax+0], xmm2 //(A) Position
47 {$else}
48 movaps [eax+0], xmm2 //(A) Position
49 {$endif}
50
51 //normalize
52 movaps xmm1, xmm3
53 mulps xmm3, xmm3
54
55 {$IFDEF PARAM_USESSE3}
56 haddps xmm3,xmm3
57 haddps xmm3,xmm3
58 {$ELSE}
59 //mix1
60 movaps xmm7, xmm3
61 shufps xmm7, xmm7, $4e
62 addps xmm3, xmm7
63 //mix2
64 movaps xmm7, xmm3
65 shufps xmm7, xmm7, $11
66 addps xmm3, xmm7
67 {$ENDIF}
68
69 xorps xmm7,xmm7
70 comiss xmm3,xmm7
71 jna @skipnormal
72
73 rsqrtps xmm3,xmm3
74 mulps xmm3, xmm1 //apply
75 @skipnormal:
76
77 {$ifdef cpux86_64}
78 movaps [rax+16], xmm3 //Normal
79 {$else}
80 movaps [eax+16], xmm3 //Normal
81 {$endif}
82 {$ENDIF}
83
84 {$IFNDEF PARAM_USESOLIDCOLOR}
85 mulps xmm5, xmm4
86 {$IFDEF PARAM_USEINTERPOLATION}
87 movlps texPosByZ, xmm5
88 {$ELSE}
89 cvtps2dq xmm1,xmm5
90 movlps intTexPos,xmm1
91 {$ENDIF}
92 {$ENDIF}
93 end;
94 {$ELSE}
95 {$IFDEF PARAM_USEZBUFFER}
96 if InvZPos > pzbuffer^ then
97 begin
98 pzbuffer^ := InvZPos;
99 {$ENDIF}
100 {$IFDEF PARAM_USESHADER}
101 zPos := 1/InvZPos;
102 with ShaderContext^ do
103 begin
104 Normal := NormalInvZ*zPos;
105 Normalize3D_128(Normal);
106 Position := PositionInvZ*zPos;
107 end;
108 {$ELSE}
109 {$IFNDEF PARAM_USESOLIDCOLOR}
110 zPos := 1/InvZPos;
111 {$ENDIF}
112 {$ENDIF}
113 {$ENDIF}
114 DrawPixelInlineWithAlphaCheck(pdest,
115 {$IFDEF PARAM_USESHADER} ShaderFunction(ShaderContext, {$ENDIF}
116 {$IFDEF PARAM_USELIGHTING} ApplyLightnessFast( {$ENDIF}
117 {$IFDEF PARAM_USESOLIDCOLOR}
118 solidColor
119 {$ELSE}
120 {$IFNDEF PARAM_USESSE}
121 {$IFDEF PARAM_USEINTERPOLATION}
122 scanAtFunc(texPos.x*zPos,texPos.y*zPos)
123 {$ELSE}
124 scanAtIntegerFunc(round(texPos.x*zPos),round(texPos.y*zPos))
125 {$ENDIF}
126 {$ELSE}
127 {$IFDEF PARAM_USEINTERPOLATION}
128 scanAtFunc(texPosByZ.x,texPosByZ.y)
129 {$ELSE}
130 scanAtIntegerFunc(intTexPos.x,intTexPos.y)
131 {$ENDIF}
132 {$ENDIF}
133 {$ENDIF}
134 {$IFDEF PARAM_USELIGHTING} ,light) {$ENDIF}
135 {$IFDEF PARAM_USESHADER} ) {$ENDIF}
136 );
137 {$IFDEF PARAM_USEZBUFFER}
138 end;
139 inc(pzbuffer);
140 {$ENDIF}
141
142 {$IFDEF PARAM_USESSE}
143 {$IFNDEF PARAM_USESOLIDCOLOR}
144 asm
145 movups xmm5, texPos
146 movups xmm1, texStep
147 end;
148 InvZPos += zStep;
149 asm
150 addps xmm5, xmm1
151 movlps texPos, xmm5
152 end;
153 {$ELSE}
154 InvZPos += zStep;
155 {$ENDIF}
156 {$ELSE}
157 {$IFNDEF PARAM_USESOLIDCOLOR}
158 texPos.x += texStep.x;
159 texPos.y += texStep.y;
160 {$ENDIF}
161 InvZPos += zStep;
162 {$ENDIF}
163
164 {$IFDEF PARAM_USESHADER}
165 {$IFDEF PARAM_USESSE}
166 {$ifdef cpux86_64}
167 asm
168 mov rax, ShaderContext
169 movaps xmm2, [rax+32] //PositionInvZ
170 movaps xmm1, [rax+64] //PositionStepInvZ
171 movaps xmm3, [rax+48] //NormalInvZ
172 movaps xmm0, [rax+80] //NormalStepInvZ
173 addps xmm2, xmm1
174 addps xmm3, xmm0
175 movaps [rax+32], xmm2
176 movaps [rax+48], xmm3
177 end;
178 {$else}
179 asm
180 mov eax, ShaderContext
181 movaps xmm2, [eax+32] //PositionInvZ
182 movaps xmm1, [eax+64] //PositionStepInvZ
183 movaps xmm3, [eax+48] //NormalInvZ
184 movaps xmm0, [eax+80] //NormalStepInvZ
185 addps xmm2, xmm1
186 addps xmm3, xmm0
187 movaps [eax+32], xmm2
188 movaps [eax+48], xmm3
189 end;
190 {$endif}
191 {$ELSE}
192 with ShaderContext^ do
193 begin
194 PositionInvZ += PositionStepInvZ;
195 NormalInvZ += NormalStepInvZ;
196 end;
197 {$ENDIF}
198 {$ENDIF}
199
200 {$IFDEF PARAM_USELIGHTING}
201 NextLight;
202 {$ENDIF}
203 inc(pdest);
204 end;
Note: See TracBrowser for help on using the repository browser.