- Home /
Specular property isn't working in ShaderLab
I'm working through the Unity Shader presentation, but I'm running into a problem. With the following code I only get a diffuse output, when I should be getting a specular one:
Shader "Tutorial/Ambient Diffuse Specular" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _SpecColor ("Spec Color", Color) = (1,1,1,0) _Shininess ("Shininess", Range (0.1, 1)) = 0.7 }
SubShader { Pass { Material { Diffuse [_Color] Ambient [_Color] Shininess [_Shininess] Specular [_SpecColor] } Lighting On } } }
I'm pretty sure this code is right, and I'm running a Nvida 9000 series card so I don't think the shader ability of the card is to blame. Is there some setting I'm not thinking about that wouldn't allow for specular output to be rendered?
Thanks!
After playing around with this a little more, I have found that the specularity is actually enlarged on the back half but when I start to move the object out of the center it goes away. When I bring the object to the edge of the camera view... the specularity shows up and enlarges quickly. $$anonymous$$aybe there is something with the glstate/ObjSpaceLightDir/ObjSpaceViewDir in my scene/project/unity?
I don't know if this is the solution but when I set the texture and then made it none the specularity effect started to happen.
I am also having this problem.
Specifically, I would like to have no texture work done for certain geometry on the GPU, but I need vertex-only specular for that geometry.
Is there a workaround that does not include a SetTexture command?
Answer by skovacs1 · Jun 29, 2010 at 06:09 PM
Hey, you're right. I never noticed. wtf?
I just ran some tests - lots of them. It appears that like yourself, in my copy of Unity 2.6 Pro on Windows at the time of this writing, none of the ShaderLab-based-shaders seem to do specular without a SetTexture call multiplying the primary. This should be corrected. I have confirmed that all of the built-in VertexLit shaders have such a SetTexture call, which is why they all work.
If you're looking to do it without the need for a texture in the shader, I looked at the built-in "Specular" shader and without the texture stuff, it looks like:
SubShader { Pass { Tags {"LightMode" = "Vertex"} Lighting On Material { Ambient [_Color] Diffuse [_Color] Specular [_SpecColor] Shininess [_Shininess] } SeparateSpecular On
CGPROGRAM #pragma fragment frag #pragma fragmentoption ARB_fog_exp2 #pragma fragmentoption ARB_precision_hint_fastest
include "UnityCG.cginc"
uniform sampler2D _MainTex;
half4 frag (v2f_vertex_lit i) : COLOR { return VertexLight( i, _MainTex ); } ENDCG }
//Pixel Lights...
So, to answer your question(?), ShaderLab does not seem to be applying the specular component without a texture anymore. If you don't want a texture in your shader, you seem to need the above CGShader to perform the vertex lighting calculations. This was not how it used to be as per the Unite08 course you seem to have gotten your shader from and given Aras' above answer, it doesn't seem like it was intended to be this way.
That was the conclusion I made after awhile. I guess you apply the texture then for a quick fix... otherwise hope they fix it in 3.0 ^^
I'm Using now Unity3.3. But it seems we have the same problem. When i Use the exact code you posted (the one on the Unite 08 presentation). I still don't get the Specular color applied. Why is that?, is there a solution that doesn't require me to write a vertex program?, please Help.
Cheers.
Solved: I Used a SetTexture statement,
SetTexture [_$$anonymous$$ainTex] { Combine texture primary DOUBLE, texture primary }
I declared a _$$anonymous$$ainTex property also, it worked.
Answer by Murcho · Jun 05, 2010 at 03:36 AM
Without getting in and testing it myself, the first thing that pops out to me is that your alpha value for the _SpecColor property is set to 0. This could possibly be masking out the entire specular effect.
Even when setting the alpha to 1 it doesn't change anything. I just can't get ShaderLab or any other shaders to work properly in Unity =/
Answer by Aras · Jun 08, 2010 at 08:43 AM
Does adding "SeparateSpecular On" help?
Unfortunately no. It seems when I set the texture it works... otherwise it just does a diffuse shader.
Your answer
![](https://koobas.hobune.stream/wayback/20220613051445im_/https://answers.unity.com/themes/thub/images/avi.jpg)