Controlling Culling

How can I enable / disable culling for a specific GameObject in my scene?

I imagine that there is a central place where I can set renderstates before a particular object is drawn.

Yes, this is probably a stupid question, and I am going to look through MonoBehavior. But I thought I would ask incase someone has a quick answer.

Thanks,

Jerry

Do you want to deactivate it or just not draw it?

Thanks JRavey.

I want to control the culling (along with other renderstates. . .like I would if I were using DirectX or OpenGL).

It seems that I should be using OnRenderObject.

But I do not see anything to actually set the renderstates.

Additionally, I guess I should be using Graphics.DrawMesh to actually draw the object.

Is this correct?

Well, you could start with disabling the renderer and see how that works for you.

backface culling is handled through materials.

culling otherwise does not exist unless you own pro and use umbra (does not exist means it uses only frustum culling). you would work with the renderer or gameobject itself if you want to control whats being rendered

The question I think is why do you want to draw something that is not rendered on any camera? Maybe there is an easier way than trying to override the built in optimizations.

It’s easy to deactivate and not draw something, but it’s likely going to be frustrating to pass something to the graphics card that gets culled out.

I have a model where parts of it are a plane. I want both sides of the plane to be rendered.

I don’t see how to access the culling from Material though:

Setting renderstates is a fundamental feature of both API’s (DirectX and OpenGL).

Is it a model or it is a plane? If it is a model, it should have both faces showing before being imported into Unity. If its a plane from the editor, it is only one-sided.

You can create a shader with the appropriate culling parameters

Use Cull Back | Front | Off

This would require a custom shader for that object (don’t apply it to objects that need to be backfaced culled or you will be putting a lot of extra pressure on the GPU). To bypass the custom shader idea you just need to export the model as double sided. I suggest exporting as double sided.

It is a model that uses planes too.

If you have a 3D modelling program of any kind, it is trivial to create your own custom Plane model that you can use instead of the built in. If not you can get Blender for free. This would allow you to export your planes as double sided and have it rendered appropriately. It is significantly safer and cleaner than trying to custom shade individual objects and meshes that need to not be backface culled (you want to change states in the middle of a draw call as infrequently as possible).

Ntero thanks for that useful link. It will come in handy shortly.

I am hoping though that for this particular case I can just set the correct state before rendering. It would make life a lot easier. If I have to change shaders everywhere I want to change states. . .then I have a lot of work ahead of me :smile:

Point taken Ntreo. I’m curious though. . .how would you handle a screen door?

Do you know anything about Maya? Do you know how to tell Maya to convert planes to double-sided polygons?

I’m used to Max, but I know in Max it is Material → Basic Material Properties → 2 Sided

Google tells me it’s in something called Texture Properties with the same name (2-Sided), but I’ve got no way to guarantee that.

I wish we were using Max :slight_smile:

It seems that it is well suited for games. My sons are studying Animation, etc. at school and Maya is what they are using. Hence we are too. . .

Yeah, Maya has always succeeded in confusing me, although I guess it just depends on what you learn on.