• 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 Pendo826 · Jan 29, 2015 at 02:20 PM · shadersramp

Error:incorrect number of arguments to numeric-type constructor

Hey guys, Im following the book "Unity Shaders and Effects Cookbook" and im coming up with the following error. I took the source code from the book files and im getting this error which is either a misprint or something completely oblivious to me. So i checked the unity website and the code is the exact same. This is leaving me clueless. Can anyone tell me the problem.

 Shader "CookbookShaders/Chapter1/RampDiffuse" 
 {
     Properties 
     {
         _EmissiveColor ("Emissive Color", Color) = (1,1,1,1)
         _AmbientColor  ("Ambient Color", Color) = (1,1,1,1)
         _MySliderValue ("This is a Slider", Range(0,10)) = 2.5
         _RampTex ("Ramp Texture", 2D) = "white"{}
     }
     
     SubShader 
     {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf BasicDiffuse
 
         float4 _EmissiveColor;
         float4 _AmbientColor;
         float _MySliderValue;
         sampler2D _RampTex;
         
         inline float4 LightingBasicDiffuse (SurfaceOutput s, fixed3 lightDir, fixed atten)
         {
             float difLight = dot (s.Normal, lightDir);
             float hLambert = difLight * 0.5 + 0.5;
             float3 ramp = tex2D (_RampTex, float2(hLambert)).rgb; //This is //the line with the error
             
             float4 col;
             col.rgb = s.Albedo * _LightColor0.rgb * (ramp);
             col.a = s.Alpha;
             return col;
         }
 
         struct Input 
         {
             float2 uv_MainTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o) 
         {
             float4 c;
             c =  pow((_EmissiveColor + _AmbientColor), _MySliderValue);
             
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         
         ENDCG
     } 
     
     FallBack "Diffuse"
 }

Comment
Add comment · Show 6
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 Bonfire-Boy · Jan 29, 2015 at 02:46 PM 0
Share

So what kind of thing do you think 'rgb' is? You're trying to set a float (single value) to a 3-valued colour. Why not post a link to the page where you say you've found the exact same code? I suspect it's actually doing something like x.Albedo = y.rgb or x.rgb = y.rgb

avatar image Pendo826 · Jan 29, 2015 at 02:51 PM 0
Share

@Bonfire Boy, It was actually a book ive gotten this code from... Its also on the unity website if you scroll down the page http://docs.unity3d.com/$$anonymous$$anual/SL-SurfaceShaderLightingExamples.html

avatar image Bonfire-Boy · Jan 29, 2015 at 03:17 PM 0
Share

@Pendo826 Yes it was the website you mentioned in the OP that I was referring to. Which shader there contains the exact same code?

I see things like

half3 x = y.rbg

(half3 is a 3-valued vector, not just a single-valued float, so this works).

avatar image Pendo826 · Jan 29, 2015 at 09:51 PM 0
Share

@Bonfire Boy Apologies for the misunderstanding... half3 ramp = tex2D (_Ramp, float2(diff)).rgb; This line is very similar to the line im getting the error from. The parameter diff is also very similar to the value hLambert used in this scenario.

avatar image Pendo826 · Jan 29, 2015 at 10:04 PM 0
Share

@Bonfire Boy Although i found my answer, i appreciate your interest in this post.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Pendo826 · Jan 30, 2015 at 03:39 AM

I figured out the problem and it was a typo in the book. float3 ramp = tex2D (_RampTex, float2(hLambert)).rgb; does not contain the correct arguments and was very hard for me to see due to my lack of knowlegde of shaders. However difLight must be a paramter in this statement. float3 ramp = tex2D (_RampTex, float2(hLambert, difLight)).rgb; Like so.

Comment
Add comment · Show 1 · 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
avatar image infinite360VR · Jul 01, 2016 at 01:59 PM 0
Share

I guess it is float2(hLambert,hLambert) ins$$anonymous$$d of float2(hLambert, difLight). I just looked at explanation in the book and it only talks about hLambert. $$anonymous$$oreover you cannot get (0,0) and (1,1) if you use both hLambert and difLight as float hLambert = difLight * 0.5 + 0.5; assures that both variable would never have same value. Please correct me if I am wrong.

avatar image
3

Answer by paledust · Mar 31, 2015 at 02:27 AM

It's because the float2(parameter_1,parameter_2),but "float2(diff)" only receive one parameter. I don't know if it's because the new version of unity or just something I missed, but I really realise the float2(diff) before in the old version, if you just use float2(hLambert,hLambert), it can also be done.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Lighting Artifact from Strumpy Ramp Shader 1 Answer

A way to fade in/out entire rooms with varied materials and shaders? 0 Answers

Do double-sided shaders work in windows phone 8? 0 Answers

Shadows have a mind of their own 1 Answer

Alpha texture overlaying opaque texture, both with colors? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges