- Home /
How do I enable backface culling for sprites?
In my game, I'm using a 3D cube for the menu screen that rotates. On each side of the cube, I'm using sprite renderers for icons. The problem is that when the cube rotates, the sprites on the back of the cube are obscuring the camera. I tried writing a custom shader to do it, but I keep getting the error:
"Material uses a fixed function shader. It is not compatible with SpriteRenderer."
How do I do this?
@robertbu, I don't want to use planes because while creating the menu, I discovered that each plane is 121 vertices. This is completely ridiculous when it's just a single square. And if I create the mesh manually, it'll be difficult to align everything properly. Sprites are obviously just the best choice.
@DaemonR: Not a plane, a quad. In the past there only was the plane mesh which has, as you have discovered, 121 vertices. Now there's a quad mesh with only 4 vertices.
Can anyone link to a tutorial or instructions for taking the shader source files and doing this? I've found loads of people asking about this same 1 sided sprite renderer issue, but no written solution anywhere.
Would be very grateful.
Cheers
Answer by VesuvianPrime · Aug 02, 2014 at 11:22 PM
Hey DaemonR
The problem isn't with the geometry but with the shader itself.
Is there a particular reason why you're using the sprite shader in this case?
If you absolutely must use sprite shader, your best bet is to download the shader source: Shaders source
From there you can simply enable backface culling in your new shader.
I stated that I had tried using my own shader, but Unity rejected it. Thanks for the link though. Editing the original script will most likely fix the problem.
Sorry, it's late. I'm sure simply enabling/disabling a feature in the existing source will be 1000x easier than writing a shader from scratch.
Your answer
Follow this Question
Related Questions
I want to walk into a cube ! 2 Answers
Unity Backface Culling 3 Answers
Is mesh rendered if backface culling? 1 Answer