|
xor eax,eax Home Fireworks SparcZ Win32 asm Kunthrandum Linkz page Guestbook Misc... About me XXXXXXXX 3982 |
2D Light effect used in Fireworks There is only one light source is used in current version of Fireworks, considering speed. Because Light requires floating point operations. And it is live lighting ie.calculated lighting on every frame, not sprite kind of. More than one colored Light sources can be programmed in by using the latest Intel SSE or AMD 3DNow! instruction sets. Unfortunately my hardware does not support them. Hmmm...(50Hz, 12dB) ![]()
Code for Light without DirectX... :)
Light_Flash3 PROC x1:DWORD, y1:DWORD, lum:DWORD, src:DWORD, des:DWORD
LOCAL mx:DWORD, my:DWORD, x2:DWORD, y2:DWORD, tff:DWORD
mov eax,lum
shr eax,1 ; Light_Flash: dynamic 2D lighting routine
mov lum,eax ; does not uses any pre-computed data
mov tff,255 ; ie. pure light frum tha melting cpu core :)
mov eax,maxx
mov mx,eax
mov eax,maxy
dec eax
mov my,eax
mov esi,src
mov edi,des
xor eax,eax
mov y2,eax
ylp3: ; 2x2 instead of per pixel lighting
xor eax,eax ; half the quality, but higher speed
mov x2,eax
xlp3:
mov eax,y2
sub eax,y1
imul eax
mov ebx,x2
sub ebx,x1
imul ebx,ebx
add eax,ebx
mov edx,lum
imul edx,edx
xor ebx,ebx
cmp eax,edx
ja @F ; jump to end causes time waves
push eax
fild dword ptr[esp]
fsqrt
fidiv lum ; this code is -different-
fld1
fsubrp st(1),st(0)
fmul st(0),st(0) ; curve
fmul st(0),st(0) ; curve
fimul tff
fistp dword ptr[esp]
pop ebx
imul ebx,01010101h
@@:
mov eax,y2
imul maxx
add eax,x2
lea eax,[eax+eax*2]
mov edx,maxx
lea edx,[edx+edx*2]
add edx,eax
movd MM2,ebx ; simply add with saturation
movq MM0,[esi+eax] ; gamma correction is against this code
psllq MM2,32
movq MM1,[esi+edx]
movd MM3,ebx
por MM2,MM3
paddusb MM0,MM2
movd [edi+eax],MM0
paddusb MM1,MM2
psrlq MM0,32
movd [edi+edx],MM1
movd ebx,MM0
psrlq MM1,32
mov [edi+eax+4],bx
movd ecx,MM1
mov [edi+edx+4],cx
emms
@@:
mov eax,x2
add eax,2
mov x2,eax
cmp eax,mx
jbe xlp3
mov eax,y2
add eax,2
mov y2,eax
cmp eax,my
jbe ylp3
ret
Light_Flash3 ENDP
Fireworks full source code [MASM32] |