Hello,
I am currently working on a custom shader that is meant to resemble a soap bubble. It is a surface shader and for some reason specularity is not working at all.
I created a variable (_SpecPower) and tried plugging it in to both o.Specular and o.Gloss. But when I drag the slider, nothing happens. I have also tried plugging in a specular map but still no success.
Any help would be greatly appreciated.
Thank you,
Alex
–
Mod posting user’s comment into their question…
–
Thanks for your response. Here are some snippets of the code that I can post.
For the surface type I have: #pragma surface surf BlinnPhong alpha
As a workaround, I plugged specular into the Emission slot:
o.Emission = spec*_SpecIntensity*_SpecularColor*_MasterOpacity*_BubbleBrightness;
Here is the code I used to calculate the appropriate lighting information for specular:
half3 h = normalize(IN.lightDir + IN.viewDir); half diff = max (0, dot (o.Normal, IN.lightDir)); float nh = max (0, dot (o.Normal, h)); float spec = pow (nh, 40.0)*_SpecPower;
This seems to work but I would still like to get it working using o.Specular or o.Gloss if possible. Right now, nothing happens when I plug into those slots. I even tried using Fallback “Specular” like you suggested. I know it’s not much code to go off of, but if you have any more suggestions I would appreciate it.
Thank you, Alex
With the shader code it would be easier to help, are you sure you are using a Lighting model that supports specular (#pragma surface surf BlinnPhong) ?
You can try to add this in the properties:
_SpecColor("Specular Color", Color) = (1,1,1,1)
and at the end of your shader:
FallBack "Specular"
Edit:
Start from a shader already working the way you want or try to compare it with yours to see what you are missing, you can get unity’s builtin shaders here: Download Archive
In ‘DefaultResourcesExtra’ folder ‘Alpha-Glossy.shader’ or ‘Alpha-BumpSpec.shader’ should be a good starting point in this case.
You can also check “Simple Specular” custom lighting model on this page: Unity - Manual: Surface Shader lighting examples