Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by alextelford · Oct 03, 2012 at 01:59 AM · shadercustomspecular

Specular problem

Hi, I am having a little trouble with my shader. The problem is that my specular map (stored in the mainTex alpha) has no effect, and the shinyness slider also has no effect. I thought that it because the vertex overlay blend mode is a heavy effect, but I removed a lot of code and still got the same problem (you can see the simpler code below it)

If you have any advice at all it is much appreciated. I'm sure I am just missing something simple.

Here is the code: shader "Custom/constructTex" { Properties{ _MainTex("Diffuse Texture", 2D) = "white"{} _BumpMap("NormalSpec Texture", 2D) = "bump" {} _vertStrength("Vert Color Strength",Range(0.0,1.0)) = 1.0 _Shininess ("Shininess", Range (0.03, 1)) = 0.5 } SubShader{ Tags { "RenderType" = "Opaque"}

         CGPROGRAM
         #pragma surface surf SpecularLight vertex:vert
         sampler2D _MainTex;
         sampler2D _BumpMap;
         half _vertStrength;
         half _Shininess;
         
         //**Lighting Model
         half4 LightingSpecularLight (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten){
             half3 h = normalize (lightDir + viewDir);
             half diff = max (0, dot (s.Normal, lightDir));
             float nh = max (0, dot (s.Normal, h));
             float spec = pow (nh, 48.0);
             half4 c;
             c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2);
             c.a = s.Alpha;
             return c;
         }
         struct Input{
             float2 uv_MainTex;
             float3 vertColors;
         };
         
         void vert (inout appdata_full v, out Input o) {
             o.vertColors = v.color.rgb;
         }
         void surf (Input IN, inout SurfaceOutput o) {
             half4 tex = tex2D (_MainTex, IN.uv_MainTex);
             //**Here we multiply colors less than 0.5, add colors over, and colors in the middle are hue only. Sort of like a more advanced overlay blend.
             if(IN.vertColors.r+IN.vertColors.g+IN.vertColors.b>1.5){
                 tex.rgb = lerp(tex.rgb,clamp(tex.rgb+(2*IN.vertColors.rgb)-1,0.0,1.0),_vertStrength);
             }else{
                 tex.rgb = lerp(tex.rgb,tex.rgb*(2*IN.vertColors.rgb),_vertStrength);
             }
             half4 normalMap = tex2D (_BumpMap, IN.uv_MainTex);
             o.Albedo = tex.rgb;
             o.Normal = UnpackNormal (normalMap);
             o.Specular = tex.rgb;
             o.Gloss = tex.a;
         }
         ENDCG
     }
     Fallback "Diffuse"
 }

//////////////////////////////////////////////////////////////////////////

//Simplified code

 shader "Custom/constructTex"
 {
     Properties{
         _MainTex("Diffuse Texture", 2D) = "white"{}
         _BumpMap("NormalSpec Texture", 2D) = "bump" {}
         _Shininess ("Shininess", Range (0.03, 1)) = 0.5
     }
     SubShader{
         Tags { "RenderType" = "Opaque"}
         
         CGPROGRAM
         #pragma surface surf SimpleSpecular
         sampler2D _MainTex;
         sampler2D _BumpMap;
         half _Shininess;
         half4 LightingSimpleSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
             half3 h = normalize (lightDir + viewDir);
 
             half diff = max (0, dot (s.Normal, lightDir));
 
             float nh = max (0, dot (s.Normal, h));
             float spec = pow (nh, 48.0);
 
             half4 c;
             c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2);
             c.a = s.Alpha;
             return c;
         }
         
         struct Input{
             float2 uv_MainTex;
         };
         
         void surf (Input IN, inout SurfaceOutput o) {
             half4 tex = tex2D (_MainTex, IN.uv_MainTex);
             
             half4 normalMap = tex2D (_BumpMap, IN.uv_MainTex);
             o.Albedo = tex.rgb;
             o.Normal = UnpackNormal (normalMap);
             o.Specular = tex.rgb;
             o.Gloss = tex.a;
         }
         ENDCG
     }
     Fallback "Diffuse"
 }
 
 //////////////////////////////////////
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image alextelford · Oct 03, 2012 at 06:34 PM 0
Share

Anyone at all? I'm sure I've just missed a space or something but I can't see it :/

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ohlin · Dec 10, 2014 at 01:05 PM

This is old. but you want a specular color in the properties. to go along with your bump map and specular strength slider.

         _SpecColor ("Specular Color", Color) = (1,1,1,1)
         _SpecPower ("Shinyness", Range(0,1))=0.5

and I just put this for gloss and specular and it worked for me (changed color with reaction to light sources) but Im not using a normal map...so that part idk.

             o.Specular = _SpecPower;
             o.Gloss = 1.0;

well i hope that was a helpful nudge to whom ever next finds this.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make an unlit shader use spec and normal maps? 2 Answers

Glass Shader with Strumpy Shader Editor 1 Answer

About shader! 0 Answers

Transparent/Specular Shader - I want alpha to control spec, not transparency 1 Answer

Why does specular highlight ignore vertex position? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges