Hello, I am making a game that involves a character going into stealth. When in stealth, the character is semi-transparent, but is undetected by AI, yada, yada, yada.
This shader does not take Unity’s Depth of Field camera shader into account.
At times, my character’s hood is more transparent than my character’s face (depending on the angle), which allows the player to see my character’s face.
I have attached two images that better describe my situation. If anyone knows how to fix this, I am willing to pay for the help.
Do you have multiple meshes/submeshes? If not, it can only be because of ColorMask 0 not working, which a couple people told me was a problem, on Windows – I don’t know if this bug has been fixed yet. If so, then put your hood into an earlier queue than your head.
Also, this method is inefficient if you’re just going to have the same alpha value over the whole mesh, like the wiki shows (not the best example). Do you actually need the alpha channel UV mapped, or will a single value suffice?
Unfortunately, I don’t know how to help you with depth of field.
I do have multiple meshes – I believe 4: cape, body, face, swords. I must admit I am a tad bit lost, but I think I will only need one single value. The entire character just needs to be semi-transparent – I’m not trying to do anything too fancy!
Out of curiosity, would you (or anyone else) know if it’s Unity’s D.O.F. shader that would need tweaking, or the transparent shader that would need tweaking?
Thanks for all the help. I sincerely appreciate you taking your time to help out!
In that case, you need to use two materials on each. It shouldn’t be any slower; you’ll still use the same number of passes; you just need to utilize different queues, and a shader can only be in one.
Make a single material from this shader, and use that material on each of the meshes:
I was browsing through the DepthOfField.js script I am using for my camera (Unity Pro only), and I came across this:
// we use the alpha channel for storing the COC
// which also means, that unfortunately, alpha based
// image effects such as sun shafts, bloom or glow
// won’t work if placed after the DOF image effect
Does this mean that my alpha shader is happening AFTER the DepthOfField script is run? If so, is there a way to change this?
I don’t know. Find out if depth of field has anything to do with rendering queues or the alpha already written to the screen. We can easily modify those shaders to deal with either.
The depth of field shader uses the Z buffer to determine what to blur. Because it is a postprocess, it can only “see” the front-most depth for any given pixel. Because your character is drawn with Z writing enabled, those pixels are considered in focus. If your character did not write to the Z buffer, his pixels would be considered part of the background, and blurred heavily.
What you want in this situation is actually to composite your character after the DOF effect. This would mean writing an image effect that came afterwards, and rendered your character in a separate buffer. That would probably work quite well, assuming your character is always in focus, but it means learning about image effects and compositing with shaders.
Wow, that sounds a little too complex for me (as I said before, I barely know syntax for shaders!)
Jessy, is there a way to combine the Vertex Lit with RGB with a bump map? My character has a normal map for his armor, which I would like to use. If it is complicated, though, then I’d rather not fix what is not broken.
It’s a Diff-Tex, NormMap, Alpha-Slider, pretty easy.
Please give a response, if it fits your need - i’m quite new into coding. But for me this one helped.
Would be great to hear if it works for chars as well.
Basically I have some objects with UV alpha (it has to be so) and I need depth of field on the full scene. Find more details in the post.
Any help is very much appreciated!!
Thank you
You sort of answered your own question in the post there; ZWrite Off
That means your shader doesn’t write to your zbuffer, so Unity won’t know it’s in the Z buffer in order to blur it.
You can try adding a pass before (or after - if you want to see bits of your character through other bits of your character) your current pass that reads;
Pass {
ColorMask 0
}
That pass will write to the ZBuffer but nothing else.
Hi Farfarer,
thank you very much for your answer. Unfortunately the Cutout doesn’t work for me. I really need the alpha to be smooth and based on UV mapping. I tried also to add the pass you suggest but I had really weird “shuttered” transparencies.
The shader I shared in the post is not the only one doing this. Most of the Transparent built in shaders do the same thing.
Any futher ideas?