- Home /
Ojbect with Unity's default Toon Light/outlined Shader drawing black when seen from inside?
Hello all, Unity's got a great community here and hope I could find some help from you. I've got a C# script that turns anything that comes between the camera and the player transparent. I have a list of objects and I raycast from the camera to the player to see if anything comes in sight, and if something does then turn it transparent by saving the mat, colour and the shader and change it with Transparent shader/mat/etc then save it in the list. When the object is "out of sight" by raycast test, it restores the original settings then pops out of the list. It's a bit different than what's suggested here: http://answers.unity3d.com/questions/44815/make-object-transparent-when-between-camera-and-pl.html but it worked and it's basically the same idea.
Well, it worked well when I was using any other shaders than the toon shader. This is where I am having a problem: I am using single sided objects and when my camera's placed inside the object, the object isn't drawn with other shaders so I didn't have to worry about the object. With the toon shaders however, when the camera's inside the object, the object is rendered black.
The object is still going transparent if the object is placed between the camera and the player, but I just have no idea why the backside of the object is rendered black. I tried to use a double sided object and when camera's placed inside the object it was actually rendering the backside of the object so I didn't think the Physics.raycast is picking up the object from inside. I came across this: http://forum.unity3d.com/threads/43621-Raycast-from-inside-Collider-is-inconsistent but I am still not sure about it.
I also tried disabling Culling/enabling different culling sides(front/back) in the toon shaders themselves but that basically messed up the scene... Currently I am putting the objects on a layer that pushes the camera away so the camera doesn't go through the object but then again there's no need for the original script since camera's always pushed by the object when it comes in sight.
Does anyone know what's happening here? Also is there any way to solve this problem and make the object transparent when the camera's placed inside of the object while the shader's rendering the backside for no apparent reason? Is this a shader specific problem at all? I am thinking of putting a collider around the camera and see if it's colliding with any object with OnCollisionEnter/OnTriggerEnter calls and if it is then make the object transparent, but that will make walls I have (boundaries of game world) transparent as well unless I use tags/layers and that's a lot of work too...Any help would be appreciated, thank you!
It seems that the "outline" part of toon shader is rendering things black from even inside of the object. For now I've implemented what I described in the last paragragh and it works so I will just leave it at that but I'd really love to know if someone comes up with a shader solution :)