Ok.. The flares also need to be downloaded, I have attached them. Some of the flares are remmed out, because I wanted more speed. This was by Van-B so he might help you to fix it...
function lensflare(sunobj,offset,qual)
` sunobj=the suns object number
` offset=the starting object number for the flares
` qual=the quality of the occlusion test 1=best...3=worst
` Amount of flares (Should be the same as defined in lensdata)
amount=9
lensdata:
` Format: image file,size,distance from centre of sun (negative values are above sun)
` The first flare data is for the volumetric effect
data "flares\L_Flare9.bmp",30,0
data "flares\L_Flare2.bmp",100,5
`data "flares\L_Flare5.bmp",40,10
data "flares\L_Flare6.bmp",50,17
data "flares\L_Flare7.bmp",70,30
`data "flares\L_Flare8.bmp",40,22
`data "flares\L_Flare1.bmp",30,35
data "flares\L_Flare3.bmp",90,40
data "flares\L_Flare4.bmp",120,50
`data "flares\L_Flare5.bmp",20,65
data "flares\L_Flare0.bmp",50,90
data "flares\L_Flare3.bmp",70,-5
`data "flares\L_Flare5.bmp",30,-15
data "flares\L_Flare0.bmp",40,-25
`data "flares\L_Flare1.bmp",20,-45
` Create lensflare objects if they don't exist
if object exist(offset)=0
restore lensdata
for lens=0 to amount-1
read bmp$,size,lensdist(lens)
make object plain offset+lens,size,size
`SET OBJECT Object Number, Wireframe, Transparency, Cull, Filter, Light, Fog, Ambient
set object offset+lens,1,1,1,1,1,1,1
set object ambient offset+lens,1
`set object diffuse offset+lens,rgb(50,50,150)
set object emissive offset+lens,rgb(150,150,150)
`set object specular offset+lens,rgb(2,2,2),75
load image bmp$,offset+lens
texture object offset+lens,offset+lens
position object offset+lens,0,0,500+lens
ghost object on offset+lens
fade object offset+lens,99.9
lock object on offset+lens
` Due to some kind of perspective distortion
` the following is necessary
if screen width()=640
lensdist(lens)=lensdist(lens)-5
endif
next lens
endif
` Control the lensflares
if object in screen(sunobj) = 1
` Retrieve info about the center of the sun
` to see if it is fully visible
lightx=object screen X(sunobj)
lighty=object screen Y(sunobj)
if qual=1
visible=point(lightx+10,lighty)+point(lightx,lighty)+point(lightx-10,lighty)
visible=(visible+point(lightx,lighty+10)+point(lightx,lighty-10))/5
else
if qual=2
visible=(point(lightx+10,lighty)+point(lightx,lighty)+point(lightx-10,lighty))/3
else
visible=point(lightx,lighty)
endif
endif
v#=(((rgbr(visible)+rgbg(visible)+rgbb(visible))/3.0)/256.0)
` Just some stuff, don't worry
screenx=screen width()/2
screeny=screen height()/2
light3dx=lightx-screenx
light3dy=screeny-lighty
step3dx#=(screenx-lightx)/20.0
step3dy#=(lighty-screeny)/20.0
` Calculate how far the sun is from the centre of the screen
distfromcentre#=SQRT(((screenx-lightx)^2)+(screeny-lighty)^2)
IF distfromcentre#>screenx then distfromcentre#=screenx
IF distfromcentre#<0 then distfromcentre#=0
` Unremark this if you want a more Power#ful blinding effect
` Notice this takes quite a lot of Power# out of some graphics cards
` Brighten the screen when the sun is closer to the centre of the screen
`r=155+(((screenx-distfromcentre#)/4)*v#)
`g=155+(((screenx-distfromcentre#)/4.2)*v#)
`b=155+(((screenx-distfromcentre#)/4.5)*v#)
`SET GAMMA r,g,b
` Scale the volumetric effect
size=((100+((screenx-distfromcentre#)/4))*60)*(v#)
scale object offset,size,size,size
` Position all the flares and hide them if the sun is too occluded
for lens=0 to amount-1
position object offset+lens,light3dx+(step3dx#*lensdist(lens)),light3dy+(step3dy#*lensdist(lens)),500
if v#<0.2
hide object offset+lens
else
show object offset+lens
endif
next lens
else
` Hide the lensflares if the sun is not on the screen
for lens=0 to amount-1
hide object offset+lens
next lens
rem inserted new sync
`sync
` Unremark this if you want a more Power#ful blinding effect
` Notice this takes quite a lot of Power# out of some graphics cards
rem set gamma 255,255,255
ENDIF
endfunction
