- Home /
Shader alpha setting being ignored?
Hey folks, got a shader problem that im not sure of the cause.
We have some items in a project that have the possibility of being alive or dead remains, for the live object we use a texture with the alpha channel for specularity (we did try to move the spec to the alpha of the normal map using the shader found here http://pastebin.com/GDHBMYDN, but for reasons that I cant work out this only seemed to supply general specular, irrespective of the map (this was tested by embedding various words into the alpha channel and looking for them in the highlights...they were not found).
Anyway the dead remains use the same texture with a shader that essentially just has a saturation and tint control. (http://pastebin.com/fvWqQx3P) The problem is, that regardless of my setting the alpha to 1 in that shader, and targeting the opaque render type, unity renders the object as semi transparent using the Alpha chanel of the main texture as an alpha map.
Would anyone be able to take a look at either of these shaders and tell me what I'm doing wrong with them? If the first one can be fixed then we'll just move the spec to the normal, But if the second can be fixed then that will probably help in the long run as its likely an issue that will arise in the future.
Any information / help is appreciated, thanks folks.
Answer by Owen-Reynolds · Oct 16, 2013 at 05:14 PM
For the second shader, you're telling it to use the main texture alpha:
result.a = 1;
return lerp(result, tex, _Saturation);
Lerp means blend, so it blends result
alpha of 1 with whatever the texture has (based on Saturation. More visible texture = more alpha.) Just set alpha to 1 afterwards:
result = lerp(result, tex, _Saturation);
result.a=1;
return result;
Alternatively, seem like you could just delete the line Blend SrcAlpha...
and then there would be no transparency, so alpha wouldn't matter anyway.
For the first shader, ummm... does BlinnPhong even use a spec map? You might look at the builtin specMap shader to see how it works.
Oh man how did I miss that! of course moving the lerp up like that does the job.
As for the first shader, I'm not entirely sure what the lighting function for BlinnPhong does, I guess I made the assumption that setting the value for specular would be the value that got used, unless BlinnPhong ignores the per pixel specular value that gets assigned and just does its own thing. I guess I'll just have to find some more time to dig into that one.
Thanks for the fresh eyes.