x


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!

more ▼

asked Jun 04 '10 at 06:34 PM

afuzzyllama gravatar image

afuzzyllama
13 2 3 9

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. Maybe there is something with the glstate/ObjSpaceLightDir/ObjSpaceViewDir in my scene/project/unity?

Jun 04 '10 at 07:35 PM afuzzyllama

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.

Jun 04 '10 at 08:43 PM afuzzyllama
(comments are locked)
10|3000 characters needed characters left

6 answers: sort voted first

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.

more ▼

answered Jun 29 '10 at 06:09 PM

skovacs1 gravatar image

skovacs1
10k 11 25 91

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 ^^

Jun 30 '10 at 12:36 PM afuzzyllama
(comments are locked)
10|3000 characters needed characters left

This is still an issue as of 3.5.2f2.

more ▼

answered Jun 01 '12 at 09:21 PM

dyamanoha gravatar image

dyamanoha
-3 1 1 3

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 23 '11 at 08:31 PM

Hendrys gravatar image

Hendrys
104 7 8 11

Solved: I Used a SetTexture statement,

SetTexture [_MainTex] { Combine texture * primary DOUBLE, texture * primary }

I declared a _MainTex property also, it worked.

Apr 23 '11 at 08:51 PM Hendrys
(comments are locked)
10|3000 characters needed characters left

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?

more ▼

answered Sep 15 '12 at 05:49 PM

impossible gravatar image

impossible
31 2 2 4

(comments are locked)
10|3000 characters needed characters left

Does adding "SeparateSpecular On" help?

more ▼

answered Jun 08 '10 at 08:43 AM

Aras gravatar image

Aras ♦♦
1.6k 7 26

Unfortunately no. It seems when I set the texture it works... otherwise it just does a diffuse shader.

Jun 09 '10 at 05:28 AM afuzzyllama
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1666
x79
x34
x9

asked: Jun 04 '10 at 06:34 PM

Seen: 1939 times

Last Updated: Sep 15 '12 at 05:49 PM