- Home /
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"
}
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
@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
@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).
@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.
@Bonfire Boy Although i found my answer, i appreciate your interest in this post.
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.
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.
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.
Answer by EssencyStudios · Apr 12, 2021 at 09:13 PM
If you have this error with VFX graph try turning off scaling by velocity and that should fix it :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613181858im_/https://answers.unity.com/themes/thub/images/avi.jpg)