With the new surface shading model, it appears that the Albedo color is being overridden by Alpha. While I can understand that the diffuse color of glass (or any other transparent material) will be less perceptible as the transparency increases, this shouldn’t be happening with the specular highlight… yet it is. In my perfect digital world I should be able to make, say, a glass sphere completely transparent, yet still reflective and with a nice shiny specular highlight on it. Regardless of how transparent an object is, if it’s shiny then that specular highlight should not diminish, as that is a function of the specularity and glossiness of the material, not its transparency.
This issue seems to be happening for both BlinnPhong and Lambert lighting functions. My workaround will be to build a custom forward rendering multipass shader, but I would sure love to use the elegance of the new Surface Shader system. Am I doing something wrong, or is this an “undocumented feature” of the new 3.x deferred lighting pipeline? Thanks!
Mark
(Please pardon me if this has been posted elsewhere. I’ve searched for this but haven’t run across anything definitively similar.)
Perhaps I should have framed the above post more in terms of a question…
Is there a way to prevent the specular highlight from diminishing when increasing the transparency of a material using Surface Shaders? Am I just misunderstanding the architecture of the rendering pipeline, or is this a render error?
It seems like it SHOULD be:
(color - alpha) + specular
but instead it appears to be doing this:
(color + specular) - alpha
Thanks again, and let me know if this thread belongs in another part of the forum or if this has already been addressed elsewhere.
Well, that’s sorta my question, Slin: how can I write such a surface shader? I think this shouldn’t be too hard with passes, but with surface shaders - where all the pass compositing is happening behind the scenes - how do I do that?
Is there a way with surface shaders to “re-order” the rendering of the alpha to happen before the specular highlight is added?
I don’t think you can do this with surface shaders. The only control over blending you have is by adding the alpha keyword to the surface pragma, and then setting the alpha to whatever you want. From there, your source factor will always be SrcAlpha, so you can’t add more light than you obscure.
you are wrong on “it should be shiny independent of alpha”. Unity inbuilt shaders that provide spec support use the color alpha channel for the spec power mask unless they offer a distinct texture so the less alpha the texture has, the less specular power is there.
I hear you guys, and I think you’re both correct as far as the Surface Shader framework is concerned. Dreamora, you mentioned the built-in shaders’ usage of a texutre’s alpha channel for the spec map, which I think makes sense probably in most cases where the user might want to cut out certain areas so that there’s no specularity where’s there’s also no texture (as referenced here: Unity - Manual: Transparent Specular). But how then does one create a glass sphere with a nice bright highlight on it?
What I’m having a hard time with is how to accurately depict a shiny surface that’s also highly transparent. Maybe surface shaders are not the answer, but surely what I’m asking for isn’t that far fetched, is it? Physically speaking, this sort of phenomenon is quite common (in real life any glass or clear plastic does this)… I guess I’ve just assumed therefor that this would be relatively straightforward in Unity. But that’s what I get for assuming, right?
Any other ideas? How can we make transparent objects look really shiny?
Just add the specularity to the alphachannel and not just to the color channels…
You don´t need several passes for this. Your problem seems to be that you think about the fixed function pipeline and not about real shaders. You can basicly mix stuff together and set the transparacy in whatever way you want (in just one pass actually, Unity will however mess with a pass per light and such crap…).
Thanks Slin, but I’m having a hard time understanding your suggestion. To make this simple, let’s assume there are no textures applied to the material, only the following:
solid color for o.Albedo
float for o.Gloss
range for o.Shininess
range for o.Alpha
No matter how I mix specular and main color in the shader functions, when I lower the range for Alpha, the Gloss strength also lowers.
How can we keep Gloss the same regardless of Alpha level?
That would give you alpha blended highlights as opposed to additive ones. Light reflected from glass doesn’t block any transmitted light. Your suggestion would result in dirty-looking highlights.
Pre-multiplied alpha blending is the solution here, and surface shaders don’t support it.
Incidentally, I thought the same thing, Slin, and tried it earlier, but Daniel is right: all that happens is the Gloss and Alpha values are simply added together to provide the final transparency level. If either value is reduced, it reduces the overall opacity of the object, but only as far as the other value. Basically this means that in order to now make something 100% transparent, you have to lower both Gloss and Alpha. But it does nothing to keep the value of the specular highlight bright.
Here’s a sample shader to illustrate (basically a modified version of Unity 3’s built-in Transparent Specular shader):
While I don’t disagree with you, Daniel, as you are likely correct, I find it very odd. This is Unity’s “new and improved” lighting pipeline – yet it doesn’t support something as straightforward and common as shiny transparent objects? Just seems like Aras and the other big unity brains would have thought of and accounted for this.
I can’t help but feel like this is more a limitation of my own understanding and experience than a limitation of the deferred lighting pipe.
I spoke with Aras this evening and he agreed that it is not possible to accomplish in a surface shader at the moment. The easiest way to do it would be to disassemble a surface shader and make the blending changes manually.
This isn’t a limitation of the deferred renderer, however, as transparent objects need to be rendered in a forward pass anyway.
Well, I guess that settles it, then… since the Jedi himself has spoken. Thanks for the update and advice, Daniel. I guess I’ll do my best at writing a multipass shader to get the kind of specular control I’m after. If I can get it working properly I’ll post it here.
I think this is what you are after LumenArtisan? Not perfect on the specular blend but it should be close.
The version you see is a single pass version of the free shader. The first pass in the free shader was a Zprime pass so it didn’t contribute to any lighting anyway. Its possible to comment out the Zprime pass from the shaders on the asset store.
Hey brn, I’ve taken a look at your videos and read about your shaders here in the forum and on the Asset Store and I think these will work nicely. Thanks for the tip!