Procedural mesh not visible in CVS

Hi,

I have a problem with a procedural mesh in the latest CVS version (Panda3D-2010.10.28-6.exe)

This mesh (a colour filled planar polygon), that was visible with the same code in Panda-1.7.0, is now invisible, even in wireframe mode, though isHidden() returns False.

What is strange is that if I add another mesh (the Panda for example) reparented to the same parent as the procedural mesh, the latter becomes sometimes visible, sometimes invisible depending on the camera position (see attached picture), proving that everything is fine with that mesh (vertices, texcoords, etc.) When the mesh is not visible, one cannot see it neither in wireframe mode.

If I don’t add the Panda, the procedural mesh is never visible, whatever the camera position. Again, the procedural mesh is always visible in Panda-1.7.0

Anyone has an idea of what could be going on?

Thanks
-David

That is strange.

I don’t know if there are copies of old snapshot installers somewhere, but if they exist you should be able to narrow down when the problem was introduced by testing a few builds.

You could also try the PRC setting

fake-view-frustum-cull 1

to see if it is a problem with the object being culled. This would cause it to show up as red wireframe.

Whenever you have a problem with things that are sometimes one way, sometimes another way, according to camera position, it usually means you’ve got an issue with drawing order. If you don’t specify the drawing order of an object relative to the other objects in the scene, then Panda tries to order them according to how it can draw most efficiently.

Usually, the drawing order doesn’t matter much for the visual look of a scene, but sometimes it does. For instance, if you are playing games with depth write or depth test, then changing the drawing order can make an object suddenly appear behind or in front of another object–making it appear visible or invisible.

So, the short answer to your question is a question: are you rendering this object in any special modes?

David

Thanks for your answers

@teedee: I tried the

fake-view-frustum-cull 1

option, I didn’t see any red wireframe when the mesh is not visible.

I added a vertical position offset to the mesh so that there’s no ambiguity on drawing order, same thing happens:

So I doubt this is a culling/drawing order issue.
I don’t think I’m using any special mode for rendering.

Thanks
-David

A position offset has little to do with drawing order.

Is the code small enough to post here?

David

Yes you’re right.

Unfortunately I can’t post any code, it’s part of a big app and I can’t reproduce it on a simple case.

However I have new facts, that might perhaps help:

  • if I add the Panda without scaling it, I noticed that:
  • my mesh becomes visible as soon as the Panda is visible
  • as soon as the Panda goes out of the screen, my mesh disappears
    It’s as if my mesh visibility is linked to the fact that the Panda is in the view frustrum
  • I tried this on my mesh:
self.drawing.setBin("fixed", 50)
self.drawing.setDepthTest(False)
self.drawing.setDepthWrite(False)

It doesn’t change anything (knowing that no object has a value higher than 40 in the application).
Shouldn’t it invalidate the drawing order hypothesis?

  • If I set the same on the Panda instead of my mesh:
panda_mesh.setBin("fixed", 50)
panda_mesh.setDepthTest(False)
panda_mesh.setDepthWrite(False)

then my mesh is never visible, whatever the camera position is.

Hope this can raise new ideas.
Thanks

-David

Right, the behavior you describe, where the mesh visibility is tied to the visibility of some other object in the scene, is still consistent with the draw-order hypothesis. It happens this way because the presence of absence of other objects in the scene can change the sorting order of the remaining objects.

One way to invalidate this theory once and for all is to (temporarily) apply this:

render.setBin('unsorted', 0, 1000)

this will set the entire scene to draw in “unsorted” order, which is to say, fixed order according to the order the nodes appear in the scene graph. If this is a drawing-order problem, then the node should now either be 100% visible or 100% invisible–no more popping in and out according to view frustum.

If the object continues to pop in and out, then it is probably something else. One thing that happens occasionally to cause symptoms like this is a bug in Panda, where it doesn’t manage state properly, particularly when exotic things such as shaders or draw callbacks interfere with the state. I haven’t seen any such bugs in a while, not since version 1.6.2 at least. Which version of Panda are you using? Do you have the auto-shader enabled at any point in the scene?

Edit: ah, I see that you are using the latest CVS version. When you constructed the mesh, did you apply a color attribute to it, e.g.:

mesh.setAttrib(ColorAttrib.makeVertex())

This is necessary with procedurally-generated meshes when you specify the color on the vertices. It is easy to overlook this call, and if you do, the rendering behavior of the mesh is undefined.

David

The procedural mesh continues to pop in and out even with:

render.setBin('unsorted', 0, 1000)

Setting the color attribute doesn’t change anything neither. The way I’m setting the color of the mesh is:

mesh.setColor(random(), random(), random(), 0.5)
mesh.setTransparency(True)

However, the color thing might be an interesting clue, because I just noticed that the procedural mesh always pops in in white, whereas it should have a random color as written in the above code. I tried:

mesh.setColor(ColorAttrib.makeFlat((random(), random(), random(), 0.5)))

this doesn’t work either. Am I doing something wrong/forgetting something?

Also could there be something wrong with the mesh bounds?

Thanks
-David

That sounds like a fine way to set color on a model. Transparency does throw a wrench into the whole system, though. Does it still behave the same way if you don’t set transparency?

How are you generating the mesh in the first place? With direct calls to GeomVertexWriter etc., or through some other means?

There could, of course, be something wrong with the bounds; but that doesn’t sound like the symptom you’re describing. However, you can prove this with:

mesh.node().setBounds(OmniBoundingVolume())
mesh.node().setFinal(True)

which should disable any bounds check on your model.

What color is the clear color? Is it possible you’re just seeing through the model to a white background behind it?

You haven’t said yet whether you’re using a shader or not. Whenever there have been bugs in Panda of this nature before, it has always been the fault of the shader management code. Are you using shaders anywhere in your scene?

David

Yes it still behaves the same without the transparency.

The mesh is generated with direct calls to GeomVertexWriter for position, normal and texcoord.

No issue with the bounds.

I’m not sure to understand what you mean by “what is the clear color”.

I’m not using a shader on that procedural mesh. I’m using shaders for other objects like the terrain, I tried to run without any shader at all and it behaves the same.

If I try to apply a texture instead of a color to the procedural mesh, then I don’t have the pop in/out issue but I don’t see the texture, only this same white color as previously.

What is really strange is that this exact same code works later on in the workflow. Have a look at that picture:

The coloured surfaces where generated with the exact same code, the only difference is that some other operations were executed before.

It’s as if there was some init stuff missing for the first surface, that’s done later, but I don’t manage to find what.

Thanks
-David

Well, I admit I’m baffled. I think I’d need to get my hands on a bit of code that reproduces this in order to understand it better. How much can you reduce the code and still produce this behavior?

David