CullState and Milkshape + MD2 problems

I’m testing milkshape models in a model loader I wrote. I’m toggling the a cull state set on rootNode on and off (with CS_BACK), and it doesn’t seem to be doing anything… the amount of polygons stay the same and the frame rate doesn’t change. I’m updating the renderstate after I do so… so I don’t know what the problem is. Isn’t turning on the cullstate supposed to raise the FPS? Maybe I’m misunderstanding what it’s used for?



Edit: new problem found with md2 models (see a few posts down)

The number of polygons aren’t going to change, you are still rendering the same number of polys, just not the back side of them. On most modern cards you aren’t going to notice that large of a framerate difference until there are a bunch of polygons on screen.

Alright, thanks for the info :slight_smile:

To see what I am talking about… leave the cullstate OFF then go into the middle of your model.

You’ll see the model from the inside, now turn the cullstate on.

Ok, now I see why I wasn’t noticing any difference. The cullstate seems to work on 3DS and MD2 models, but it seems to always be on for milkshape models. I just tried it with one of my own and the “run” model that comes with jME.

Hmmm interesting. It’s simply a GL state being set, no reason it shouldn’t be set for MS files too. I’ll play around with it.

Oh, I just noticed something else. CullState.CS_BACK doesn’t work very well with MD2 models, at least not Dr. Freak. Turn it on and look at him… he’s scarier than usual :). If you go around him with the camera his head will look like it’s turning around (like in The Exorcist). There are also other visual problems with him… just try it for yourself.



Edit: Here’s an image from TestModelClones:

Just running through all model types and CullState works as expected, including Milkshape (I used run model and the pick test).



Perhaps you are just expecting something different? This is a direct translation of glCullFace.



http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc01_9yxx.asp



Each triangle is tested, if the normal of the triangle is negative it is not rendered. However, you don’t notice a reduction in triangles in the display because this occurs after it triangles are sent to the card for rendering.



You are seeing odd things with the Dr. Freak model because you set it to cull the triangles with the positive normal. Meaning, you are only seeing the inside of the model, not the outside.



The normals are determined by the winding of the triangle. Because OpenGL is a right handed coordinate system, the triangles should have a counter-clockwise winding. So, typically you would cull the back side. Culling the front side might be useful in instances where the modeler built a model with a clockwise winding (for DirectX or something).



I hope that helps explain it somewhat.

Yes that does help, but I just added this to TestModelClones:

CullState cs = display.getRenderer().createCullState();
cs.setCullMode(CullState.CS_BACK);
cs.setEnabled(true);
rootNode.setRenderState(cs);


So it should cull the back of Dr. Freak, not the front. It culls the other models fine. :?
So it should cull the back of Dr. Freak, not the front. It culls the other models fine.


is answered:

The normals are determined by the winding of the triangle. Because OpenGL is a right handed coordinate system, the triangles should have a counter-clockwise winding. So, typically you would cull the back side. Culling the front side might be useful in instances where the modeler built a model with a clockwise winding (for DirectX or something).


Dr. Freak was written by a third party, you don't always know what winding you are going to get if you aren't controlling the models. In the case of the clone test you'd set cull state to BACK for the milkshape and 3ds models, but FRONT for dr. Freak.

Oh hehe… that makes sense, I just wasn’t sure if that was the case. Thanks!