Tipp: How to fix that EntityVisible Bug

Blitz3D Forums/Blitz3D Programming/Tipp: How to fix that EntityVisible Bug

jfk EO-11110(Posted 2004) [#1]
Well, I hope it's really a bug and not only some mistake in my code.

however. In my game I am using light-flare sprites. they become visible whenever the player can see the lightbulb and turn off as soon as the lightbulb is hidden somehow.

Now it happens oftenly (you might remember the csp demo 1&2) that such a light flare sprite was flashing even when there was a wall or something between the light and the player. (seen on diffrent videocards)

This only happend ON THE SCREEN BORDER. So if you want to make shure this two guys (EntityInView and EntityVisible) work correctly, then you need to filter it this way:

if entityinview(bulb,camera)
 if entityvisible(camera,bulb)
  dummy=cameraproject camera,entityx(bulb),entityy(bulb),entityz(bulb)
  x=projectedx()
  y=projectedy()
  if x>0 and y>0 and x<graphicswidth()-1 and y< graphicsheight()-1 then
   showentity flare ; ok, it is really visible
  endif
 endif
endif



Ross C(Posted 2004) [#2]
Thanks :) I did notice that in your secret of manes game. Wasn't that big a deal i didn't think, cause the rest of it was very nice :)


jfk EO-11110(Posted 2004) [#3]
really? but i thought this wouldn't happen anymore in the secret of manes demo since I added said filter?... well it happened only 1 out of 100 times compared with the older demos without that filter. at least on my machine. Are you shure you are not confusing the demo versions?


sswift(Posted 2004) [#4]
Why not fade the lens flare in or out over the course of 250 milliseconds instead of simply turning it on or off instantly? Then it wouldn't be so harsh turning on instantly when the center of a light source comes into view, and it would solve your problem.


jfk EO-11110(Posted 2004) [#5]
this might work for things coming in view, but it looks unrealistic for lights which are already in the middle of the screen imho.

I was thinking about this. I will probably do it this way, fade it in when something is near the screen border. and turn it on quickly when it is only flashing in the middle of the screen.

But there is still the question why does EntityVisible act like this.


*(Posted 2004) [#6]
FYI EntityVisible works for me ok (for Hunted's coronas) I dont know about entities that are 'offset' from their center tho. I would recommend a fade speed of .1 per renderworld this gives a nice 'Unreal' style corona fade.


jfk EO-11110(Posted 2004) [#7]
Ok, as I said, I am not shure if this is only a mistake in my code, so maybe the title was probably a bad choice. Well, I decided to turn on the flares when they are near the camera range. Since I project their Screen coords anyway, I can also turn them on when they are somehow near EntityInView. This way I can completely replace the EntityInView Command (where x and y are the projected coords):
if x>-200 and y>-200 and x<graphicswidth()+200 and y< graphicsheight()+200 then

This is only possible cause ProjectedX() is capable of negative values for offscreen coords.
But "200" should be a variable that is screen resolution dependent.


Ross C(Posted 2004) [#8]
Pretty sure entityvisible on uses centre position. I had to give up using it for occulsion because of this. EntityInView, in regard to sprites, works funny. Have you tried increasing the entityradius for the sprite?


jfk EO-11110(Posted 2004) [#9]
No, but I'll try that, thanks for the tip. I didnt define a radius at all since I don't use them for collision. I just tested offscreen projected coords and that works pretty good as well btw.

EDIT - oops: I use it with the lightbulb mesh - to decide if I got to hide the flare sprite - not visa versa.


Ross C(Posted 2004) [#10]
Any joy ? :)