Annoying Cull Bug

BlitzMax Forums/MiniB3D Module/Annoying Cull Bug

Streaksy(Posted 2016) [#1]
Has anyone else had this problem? Entities (meshes), especially if their entity scale is a bit low, vanish when the camera gets close. I've tried changing the camera near range to like .01 and the far range to something small like 100 and it still happens. I've searched the code for autofade incase that was doing something weird but it's not anywhere.

It seems to happen when the entity is within (.5 divided by entityscale) radius of the camera. Something like that.

Big static map geometry whose entity position is origin (0,0,0) are unaffected. It's just the small dynamic objects that vanish when they get close.

I don't know what else to try. ;/


Zethrax(Posted 2016) [#2]
I've had that problem with some animated third-party models. I suspect whichever pivot/bone is used as the reference for the culling is placed outside the visibility area.

Try iterating the parent-child hierarchy and placing some text at the position of the bone in 3D space. This will tell you if the model needs to be edited - either by you, or by the creator if it is a defective product you've bought.

I'll write some code for this after work tonight and post it here. I need it for a model I'm using for a project anyway.


Streaksy(Posted 2016) [#3]
No bones involved. It's all stuff made with CreateMesh or CreateSphere/whatever. I haven't actually tried an animated model but I imagine it would be the same.


Streaksy(Posted 2016) [#4]
And by the way, it's does it when the mesh has no parent entity.


Streaksy(Posted 2016) [#5]
OKAAAAAAAYYYYYYY I found a solution. And it's weird.

I noticed that it didn't happen to vertex-lightmapped meshes.... so I tried setting the entities' FX to 2 (vertex colours) instead of default (0 I guess) and it stopped happening. :O

It's not the only weird bug only I seem to have. It takes a few seconds for fog to kick in. I even do a timed render loop without Flip before the program starts, just to get it out the way. The time it takes to kick-in is very random so it still kinda messes with the experience.

Thanks for replying anyways. I think I have a workaround.


Streaksy(Posted 2016) [#6]
Nope it's still happening in some cases. Egh. Sigh. A good 20% of this is finding bug workarounds.


Zethrax(Posted 2016) [#7]
Can you post some example code that reproduces the problem? Otherwise all I can give you is guesses.


Streaksy(Posted 2016) [#8]
Not without posting 1.5mb of complex bmx files and 60 mb of media that it needs to run. I was just hoping someone had come accross it and had an idea of why it happens.

But like... in this project, if I create a few basic meshes (spheres or whatever), just for testing purposes, and move the camera close to them, they vanish.

CreateCamera
CreateSphere
PositionCamera
Renderworld
Flip

It's all you need for it to happen. But mainly in this project, and I've pored through the code trying to work out why... tinkering with camera range, doing searches for "autofade" and stuff.

I wonder if it's actually related to that fog bug? Okay... this project is a game engine and map editor, and each map has two states - editing and finalised (lightmapped etc). In finalised state fog is enabled and small objects are vertex lightmapped, hence vertex colours (fx2), and they are much less likely to disappear.

Anyway, if it hasn't happened to anyone else I don't think I can fix it. I've always gotten weird and unique bugs. ;/


Zethrax(Posted 2016) [#9]
Could you make a video of the problem then and upload to Youtube or somewhere similar. The free version of Fraps ( http://www.fraps.com/download.php ) would probably work for this.

Only idea I've got right now is that it's a near camera range clipping thing, but it sounds like you've got enough experience to have eliminated that as a possibility.


Streaksy(Posted 2016) [#10]
Yeah and the geometry doesn't progressively Z-out as it comes within the camera's near-radius - the whole object is either drawn or invisible. I could fraps it for you but there's really nothing to see that I haven't said. ;/ So strange. It's okay though I'll have to live with it. It's one of those things. Thanks for all the replies.


grable(Posted 2016) [#11]
If it only happens when the mesh/surface has alpha, then its probably the entity alpha ordering that is messing up.

There is code for this spread all over, but the gist of it is in:
TGlobal.bmx:TGlobal.RenderCamera()
TMesh.bmx:TMesh.Alpha()
TEntity.bmx:TEntity.EntityListAdd()

Try printing some messages in RenderCamera() and see if your entity really is within the frustrum and if alpha_order is set to some unreasonable value.


angros47(Posted 2016) [#12]
Does it affect MiniB3d or OpenB3d? Or both?


Streaksy(Posted 2016) [#13]
Never tried OpenB3D...

The entities alphas are 1, and their textures are loaded without the alpha flag... but I'll get some frustrum feedback. Worth knowing.


Streaksy(Posted 2016) [#14]
Hello again.

Great news! Fog doesn't work at all anymore. WHAT IS GOING ON???


Streaksy(Posted 2016) [#15]
Agh help :P

I do two types of render depending on light conditions. A lot to explain, but really the only thing that changes is the entityfx (vertex colour mode or normal), and existence of light entities.

Now... on one render fog is ignored. On the other, fog is drawn. Here's the mad thing. I've tried setting the entityfx to 0 and creating a dummy light on the second render (the render that fog doesn't work) and it still doesn't work.

And earlier in the project, it DID work in that mode. I've tried adding the following RIGHT BEFORE the RenderWorld.

LightFogMode cam,1
LightFogRange cam,.1,3
LightFogColor cam,250,0,0
EntityFX mesh,0

So... I can't work out what other conditions could be causing fog to be ignored.

I even tried creating an untouched sphere before renderworld and freeing it after, to see if it was a property of the mesh that causes the fog to not work, but that test mesh was unfogged aswell.


So... the ONLY difference between the two renders that I know of is that the WORKING one is rendering to an image while the BROKEN one is just doing the normal screen render. Yes, it uses a tweak of the MiniB3D code, but even when I replace all my stuff with normal renderworld, same result. So. Question is... anyone know any conditions that could be preventing fog? Cheers.


EDIT:
I have found that fog kicks in after several renders if there is tons of geometry. Mental. So, I've finally found a workaround involving 4 seconds of rendering a ton of randomised geometry at the start of the program. The REALLY mad thing is it only works if there is a "Flip". Annoying, but there you go. Once it's rendered I have to clear the screen before the flip.