What I've found works well is storing the pixels for your lightmap in an array. You then "draw" your shadows to the lightmap array, blur the pixels as many times as you need, then WPF the pixels to your texture. Here is the piece of code that I use to do this:
I'm not sure that this is the best way but if I only update my lightmap every 2-3 frames and the texture isn't too big it's pretty fast even with a lot of blurring passes. Plus, it looks really nice!
For n=0 To LMBlur ;number of blur operations to apply For y=1 To LMscrH-2 ;height of lightmap array For x=1 To LMscrW-2 ;width of lightmap array c=LMbuffer(x,y) If (c And $FFFFFF) > 0 c1=LMbuffer(x-1,y) c2=LMbuffer(x+1,y) c3=LMbuffer(x,y+1) c4=LMbuffer(x,y-1) r=c Shr 16 And $FF : g=c Shr 8 And $FF : b=c And $FF rl=c1 Shr 16 And $FF : gl=c1 Shr 8 And $FF : bl=c1 And $FF rr=c2 Shr 16 And $FF : gr=c2 Shr 8 And $FF : br=c2 And $FF rd=c3 Shr 16 And $FF : gd=c3 Shr 8 And $FF : bd=c3 And $FF ru=c4 Shr 16 And $FF : gu=c4 Shr 8 And $FF : bu=c4 And $FF rd=((r Shl 1)+(rl+rr+rd+ru) Shr 1)Shr 2 gr=((g Shl 1)+(gl+gr+gd+gu) Shr 1)Shr 2 bl=((b Shl 1)+(bl+br+bd+bu) Shr 1)Shr 2 LMbuffer(x,y)=(((rd Shl 8)+gr) Shl 8)+bl EndIf Next Next Next buf=TextureBuffer(LMtex) LockBuffer buf For y=0 To LMscrH-1 For x=0 To LMscrW-1 xx=lmbox+x : yy=lmboy+y If xx<LMtexW And YY<LMtexH WritePixelFast lmbox+x,lmboy+y,LMbuffer(x,y),buf EndIf Next Next UnlockBuffer buf
I'm not sure that this is the best way but if I only update my lightmap every 2-3 frames and the texture isn't too big it's pretty fast even with a lot of blurring passes. Plus, it looks really nice!