• 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 /
  • Help Room /
avatar image
0
Question by gangafinti · Dec 07, 2015 at 11:37 PM · cg

Shader error : incorrect number of arguments to numeric-type constructor

Hi guys, I was implementing a lightmap into my shader and then I got this error and I can't figure out what it means. Does any one know how I can fix this? It started happening since I added the light map in.

Shader error in 'Custom/HauntedHouseShader': incorrect number of arguments to numeric-type constructor at line 84 (on d3d11)

This is my code:

 Shader "Custom/HauntedHouseShader" {
     Properties {
         _Texture ("Diffuse", 2D) = "white"{}
         _Color ("Color", Color) = (0,0,0,1)
         _TilingX ("TilingX", float) = 1
         _TilingZ ("TilingZ", float) = 1
     
         
     }
     SubShader {
     
         Pass{
          Tags { "LightMode" = "ForwardBase"}
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #pragma target 3.0
          #include "UnityCG.cginc"
         
         float4 _Color;
         sampler2D _Texture;
         float _TilingX;
         float _TilingZ;
         
          sampler2D unity_Lightmap;
       float4 unity_LightmapST;
 
         
         float4 _LightColor0;
             
         struct VertexOutput
         {
             float4 pos : SV_POSITION;
             float4 posWorld : TEXCOORD1;
             float4 tex : TEXCOORD0;
             float3 normalDir : TEXCOORD2;
             float2 tex2 : TEXCOORD3;
         };
         
         struct VertexInput
         {
             float4 vertex : POSITION;
             float3 normal : NORMAL;
             float4 texcoord : TEXCOORD0;
         };
         
         struct FragmentOutput
         {
             float4 color : COLOR;
         };
 
         VertexOutput vert (VertexInput i)
         {
             VertexOutput VOUT;
             VOUT.tex = i.texcoord;
             VOUT.pos = mul(UNITY_MATRIX_MVP,i.vertex);
             VOUT.posWorld = mul(_Object2World,i.vertex);
             VOUT.normalDir = normalize( mul(float4(i.normal,0.0),_World2Object).xyz);
             VOUT.tex2 =  i.texcoord.xy * unity_LightmapST.xy + unity_LightmapST.zw;
             return VOUT;
         }
         
         FragmentOutput frag(VertexOutput v) 
         {
             FragmentOutput FOUT;
             float3 lightDir;
             float atten;
             
             if(_WorldSpaceLightPos0.w == 0.0){
                 atten = 1;
                 lightDir = normalize(_WorldSpaceLightPos0.xyz);
             }else
             {
                 float3 fragmentToLightSource = _WorldSpaceLightPos0.xyz - v.posWorld.xyz;
                 float dist = length(fragmentToLightSource);
                 atten = 1.0/dist;
                 lightDir = normalize(fragmentToLightSource);
             }
             
             float3 lightMap = float3(DecodeLightmap(tex2D(unity_Lightmap, v.tex2.xy)),0.0);
             
             float3 normalDir = v.normalDir;
             float4 tex = tex2D(_Texture, float4(v.posWorld.x * _TilingX,v.posWorld.z * _TilingZ,0.0,0.0));
             float3 diffuseReflection = atten * _LightColor0.xyz * saturate(dot(normalDir, lightDir));
             
             float3 lightFinal = UNITY_LIGHTMODEL_AMBIENT.xyz + diffuseReflection;
             
             float4 col = float4(tex.xyz * lightFinal * _Color + lightMap,0.0);
             FOUT.color = col;
             return FOUT;
         }
         ENDCG
         }
         Pass{
          Tags { "LightMode" = "ForwardAdd"}
          Blend One One
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #pragma target 3.0
         
         float4 _Color;
         sampler2D _Texture;
         float _TilingX;
         float _TilingZ;
 
         
         float4 _LightColor0;
             
         struct VertexOutput
         {
             float4 pos : SV_POSITION;
             float4 posWorld : TEXCOORD1;
             float4 tex : TEXCOORD0;
             float3 normalDir : TEXCOORD2;
             
         };
         
         struct VertexInput
         {
             float4 vertex : POSITION;
             float3 normal : NORMAL;
             float4 texcoord : TEXCOORD0;
             float4 tangent : TANGENT;
         };
         
         struct FragmentOutput
         {
             float4 color : COLOR;
         };
 
         VertexOutput vert (VertexInput i)
         {
             VertexOutput VOUT;
             VOUT.tex = i.texcoord;
             VOUT.pos = mul(UNITY_MATRIX_MVP,i.vertex);
             VOUT.posWorld = mul(_Object2World,i.vertex);
             VOUT.normalDir = normalize( mul(float4(i.normal,0.0),_World2Object).xyz);
             return VOUT;
         }
         
         FragmentOutput frag(VertexOutput v) 
         {
             FragmentOutput FOUT;
             float3 lightDir;
             float atten;
             
             if(_WorldSpaceLightPos0.w == 0.0){
                 atten = 1;
                 lightDir = normalize(_WorldSpaceLightPos0.xyz);
             }else
             {
                 float3 fragmentToLightSource = _WorldSpaceLightPos0.xyz - v.posWorld.xyz;
                 float dist = length(fragmentToLightSource);
                 atten = 1.0/dist;
                 lightDir = normalize(fragmentToLightSource);
             }
             
             float3 normalDir = v.normalDir;
             float4 tex = tex2D(_Texture, float4(v.posWorld.x * _TilingX,v.posWorld.z * _TilingZ,0.0,0.0));
             float3 diffuseReflection = atten * _LightColor0.xyz * saturate(dot(normalDir, lightDir));
             
             float3 lightFinal = UNITY_LIGHTMODEL_AMBIENT.xyz + diffuseReflection;
             
             float4 col = float4(tex.xyz * lightFinal * _Color ,0.0);
             FOUT.color = col;
             return FOUT;
         }
         ENDCG
         }
         
     } 
     FallBack "Diffuse"
 }

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

33 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Invalid #include directive 1 Answer

Exporting graphically created shaders in Visual Studio to Unity. [.glsl to .shader] 0 Answers

Shaders are horrible. Why does the shader of one object affect the shader of the other object??? 0 Answers

Does adding more material properties slow down a shader? 0 Answers

Tint a UI sprite with a gradient 0 Answers


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