Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Endico · Oct 26, 2016 at 08:00 PM · shadersplanet

Unity 5 Shader problems

Hi guys i upgraded to unity 5 bringing about a problems in my shader.

"incorrect number of arguments to numeric constructor at line 85 d3dx9"

Not having any sufficient shader knowledge i pray you guys will be able to help out. Cheers.

 Shader "DiffusePlanet11" {
    Properties {
       _Color ("Diffuse Material Color", Color) = (1,1,1,1)
       
           _MainTex ("Base (RGB)", 2D) = "white" {}
         _ColorShift ("Color Shift", Vector) = (1,1,1)
         _PlanetPos ("Planet Position", Vector) = (0,0,0)
         
         _DetailTex ("Detail Texture", 2D) = "black" {}
         
         _BlendThreshold ("Blending Threshold", float) = 0
         
         _ChangePoint ("Change at this distance", Float) = 0.002
         
         _MultTest ("Test Multiplier", float ) =  1
    }
    SubShader {
       Pass {    
        
          Tags { "LightMode" = "ForwardBase" } 
            // pass for first light source
  
          CGPROGRAM
  
          #pragma vertex vert  
          #pragma fragment frag 
          #pragma fragmentoption ARB_fog_exp2
                  #pragma target 3.0
 
          uniform float4 _Color; // define shader property for shaders
          sampler2D _MainTex;
          sampler2D _DetailTex;
          uniform sampler2D _DetailTex2;
          float _ChangePoint;
          float _BlendThreshold;
          uniform float _MultTest;
          uniform float fInnerRadius;
          
          float CoastalMax = -0.005;
          float MidMax = 0.000;
          float HighMax = 0.005;
             
         uniform float3 _PlanetPos;
  
          // The following built-in uniforms (apart from _LightColor0) 
          // are defined in "UnityCG.cginc", which could be #included 
           // w = 1/scale; see _World2Object
          
           // inverse model matrix 
             // (all but the bottom-right element have to be scaled 
             // with unity_Scale.w if scaling is important) 
           
             // position or direction of light source
          uniform float4 _LightColor0; 
             // color of light source (from "Lighting.cginc")
  
          struct vertexInput {
             float4 vertex : POSITION;
             float3 normal : NORMAL;
             float4 texcoord : TEXCOORD0;
          };
          struct vertexOutput {
             float4 pos : SV_POSITION;
             float4 col : COLOR;
             float2 uv : TEXCOORD0;
             float3 vertpos : TEXCOORD1;
             
             
          };
  
          vertexOutput vert(vertexInput input) 
          {
             vertexOutput output;
             float3 v3Pos = (mul(unity_ObjectToWorld, input.vertex).xyz) - _PlanetPos;
  
             float4x4 modelMatrix = unity_ObjectToWorld;
             float4x4 modelMatrixInverse = unity_WorldToObject; 
                // multiplication with unity_Scale.w is unnecessary 
                // because we normalize transformed vectors
  
             float3 normalDirection = normalize(float3(
                mul(float4(input.normal, 0.0), modelMatrixInverse)));
             //normalDirection = normalize(input.normal) 
             float3 lightDirection = normalize(
                float3(_WorldSpaceLightPos0));
  
             float3 diffuseReflection = 
                float3(_LightColor0) * float3(_Color)
                * max(0.0, dot(normalDirection, lightDirection));
  
             output.col = float4(diffuseReflection, 1.0);
             output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
             output.vertpos = v3Pos;
             output.uv = input.texcoord;
             return output;
          }
  
          float4 frag(vertexOutput input) : COLOR
          {
                  input.uv = input.uv * _MultTest;
                 _BlendThreshold = 0.1;
                 float3 vertp = input.vertpos.xyz;
                 float _length = length(vertp);
                 float disp = (_length - fInnerRadius)/fInnerRadius;
                 half3 texel = tex2D(_MainTex, input.uv).rgb;
                 half3 lowercol = float3(0.84,0.757,0.42);
                 half3 uppercol = float3(0.6,0.7,0.1882352941176471);
                 half3 highercol = float3(0.9,0.9,1);
                 
                   _ChangePoint = fInnerRadius * (1 + (CoastalMax));
                   //lowercol = float3(0.2,0.2,0.6);
                   //uppercol = float3(0.0,0.2,0.0);
                 
               
                
                     
                 
                 
                 float startBlending = _ChangePoint - _BlendThreshold;
                  float endBlending = _ChangePoint + _BlendThreshold;
                  
                  float startBlending2 = _ChangePoint + 0.7 - _BlendThreshold;
                  float endBlending2 = _ChangePoint + 0.7 - _BlendThreshold;
  
                  float curDistance = _length;
                  float changeFactor = saturate((curDistance - startBlending) / (_BlendThreshold * 2));
                  float changeFactor2 = saturate((curDistance - startBlending2) / (_BlendThreshold * 2));
                  
                 
                 if (disp < 0)
                 {
                     texel = float3(1,0.2,0.2);
                 }
                 if (disp > 0.007)
                 {
                     texel = float3(1,1,1);
                 }
                 half3 ttexel = lerp(lowercol, uppercol, changeFactor);
                 texel = lerp(ttexel, highercol, changeFactor2);
                 half3 texel2 = tex2D(_DetailTex, input.uv).rgb;
                 
                 half3 tex1hold = tex2D(_DetailTex, input.uv).rgb;
                 half3 tex2hold = tex2D(_DetailTex2, input.uv).rgb;
                 texel2 = lerp(tex1hold, tex2hold, changeFactor);
                 
                 texel = texel + (texel2);
                  float3 col = input.col;
                  return half4(texel*col,1.0);
          
          
             return input.col;
          }
  
          ENDCG
       }
  
       
    }
    // The definition of a fallback shader should be commented out 
    // during development:
    // Fallback "Diffuse"
 }
Comment
Add comment · Show 2
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 Endico · Oct 30, 2016 at 02:27 PM 0
Share

@Namey5 problem shifted to line 88. im quite puzzled when tinkering after reading up on shaders i changed the error to "incorrect number of arguments to numeric type constructor" ideas on line 88 problem?

avatar image tanoshimi Endico · Oct 30, 2016 at 05:39 PM 0
Share

Please don't post comments as answers. And when asking follow-up questions, please provide a full problem description. What is line 88 now?

All the issues you've described have the same root cause - you're supplying a 4-element vector in the constructor of a 3-element vector. If you only want the first three parameters (e.g. RGB ins$$anonymous$$d of RGBA, or XYZ ins$$anonymous$$d of XYZW) then you need to explicitly state this.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Oct 26, 2016 at 08:06 PM

Not sure what you're trying to do with:

 float3 lightDirection = normalize(float3(_WorldSpaceLightPos0));

Try this instead:

 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
Comment
Add comment · Show 7 · 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 Endico · Oct 27, 2016 at 06:53 PM 0
Share

thanks but no change on line 86

avatar image tanoshimi Endico · Oct 27, 2016 at 08:17 PM 1
Share

Well you didn't say there was a problem on line 86 as well! That looks like it should be:

              float3 diffuseReflection = _LightColor0.rgb * _Color.rgb * max(0.0, dot(normalDirection, lightDirection));
avatar image Namey5 tanoshimi · Oct 29, 2016 at 01:29 AM 1
Share

It's the exact same problem. You are casting a float4 (so 4 arguments) to a float3 (3 arguments). Just change it from;

              float3 normalDirection = normalize(float3(mul(float4(input.normal, 0.0), model$$anonymous$$atrixInverse)));

to

              float3 normalDirection = normalize (mul(float4 (input.normal, 0.0), model$$anonymous$$atrixInverse));
Show more comments
avatar image
0

Answer by Endico · Oct 27, 2016 at 06:48 PM

thanks but no change on line 86

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Water foam shader that works on planet water 2 Answers

Simple planet atmosphere 0 Answers

Uniform face colour flat shading using Shader Graph 0 Answers

GPU Procedural planets: How to convert grayscale highmap to normal map and use it as normal map on the GPU? 0 Answers

Water shader for planet with animated foam on shores 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