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 · Jan 04, 2013 at 03:58 AM · shaderlightingdx11

Unity 4 shader error

Hey guys, I am currently working on a bunch of shaders and there is one thing I have not been able to work out. When dealing with directional lights I use:

 float3 directionalPos = mul(_World2Object, _WorldSpaceLightPos0).xyz;
 output.lightDirection = mul(rotation, directionalPos);

and when using point lights: float3 pointPos = float3(_WorldSpaceLightPos0 - mul(_Object2World, input.vertex).xyz); output.lightDirection = mul(rotation, pointPos);

This works perfectly fine on my netbook which is locked to shader model 1, but on my main computer the point lights throw the errors:

Shader warning in 'Custom/normalTest': Program 'vert', incorrect number of arguments to numeric-type constructor (compiling for d3d11) at line 33 Shader warning in 'Custom/normalTest': No subshaders can run on this graphics card

Removing mul(_Object2World, input.vertex).xyz); removed the problem but then my point lights will not work.

I've spent a good few days trying to solve this and am a little lost, Does anyone have any idea as to the problem? or if you have a sample non surface shader that works with dx11 mode I can figure it out from there.

Much appreciated, here is the the current testing code:

 Shader "Custom/normalTest" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _BumpMap ("Bump", 2D) = "bump" {}
         _Color ("Diffuse Material Color", Color) = (1,1,1,1) 
     }
     SubShader {
         Tags { "RenderType"="Opaque"  }
         LOD 200
  
         Pass {
              Tags { "LightMode" = "ForwardBase" }  //for first light
  
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
              
              uniform float4 _Color;
             uniform float4 _LightColor0; //only variable not built in
  
             sampler2D _MainTex;
             sampler2D _BumpMap;
             float4 _MainTex_ST; //_ST for tiling
             float4 _BumpMap_ST;
  
             struct vertexInput
             {
                 float4 vertex : POSITION;
                 float3 normal : NORMAL;
                 float4 texcoord : TEXCOORD0;
                 float4 tangent : TANGENT;
  
             }; 
  
             struct vertexOutput
             {
                 float4 pos : POSITION;
                 float4 tex : TEXCOORD0;
                 float4 posWorld : TEXCOORD2;
                 float3 lightDirection : TEXCOORD3;
  
             };
  
             vertexOutput vert (vertexInput input)
             {
                 
                 vertexOutput output;
                 float3 binormal = cross( input.normal, input.tangent.xyz ) * input.tangent.w; //calculate binormal (perpendicular to tangent)
                 float3x3 rotation = float3x3( input.tangent.xyz, binormal, input.normal ); //convert objectspace to screenspace
                 float3 directionalPos = mul(_World2Object, _WorldSpaceLightPos0).xyz; //object space position of dir light
                 
                 //comment out this line for working shader, but require for point lights
                 float3 pointPos  = float3(_WorldSpaceLightPos0 - mul(_Object2World, input.vertex).xyz);//object space position of point light
                 
                 //lerp commented out for working shader
                 //float3 objSpaceLightPos = float3(lerp(directionalPos.xyz,pointPos.xyz,_WorldSpaceLightPos0.w));//determine which light to use (directional.w=0)
                 
                 output.lightDirection = mul(rotation, pointPos); //pointPos for point, directionalPos for directional lights
                 output.pos = mul( UNITY_MATRIX_MVP, input.vertex); 
                 output.tex = input.texcoord;  
                 return output;
             }
  
             float4 frag(vertexOutput input) : COLOR  
             { 
                 float4 c = tex2D (_MainTex,  _MainTex_ST.xy * input.tex.xy + _MainTex_ST.zw);  
                 
                 float4 n =  tex2D (_BumpMap, _BumpMap_ST.xy * input.tex.xy + _BumpMap_ST.zw); 
                 fixed3 unpackedNormal;
                 unpackedNormal.xy = n.wy * 2 - 1;
                 unpackedNormal.z = sqrt(1 - unpackedNormal.x*unpackedNormal.x - unpackedNormal.y * unpackedNormal.y);
  
                 float3 lightColor = UNITY_LIGHTMODEL_AMBIENT.xyz;
  
                 float diff = saturate (dot (unpackedNormal, normalize(input.lightDirection)));   
                 lightColor += _LightColor0.rgb * (diff); 
                 c.rgb = lightColor * c.rgb * 2;
                 return c;
  
             } 
  
             ENDCG
         }
     }
    //FallBack "Diffuse"
     }

Thanks for any assistance :)

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

1 Reply

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

Answer by cgcookie · Jan 05, 2013 at 05:11 AM

incorrect number of arguments to numeric-type constructor This means that you are converting from float4 to float3 without specifying which variables to keep. For example: float3(_WorldSpaceLightPos0.xyz) will work because we tell unity to drop the w component. It's something that comes up when writing shaders for directX 11 Also make sure you update to the latest version of unity.

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

8 People are following this question.

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

Related Questions

How To Replicate the Untitled Goose Game Art Style? 0 Answers

Inverted Normals in Player, correct in Editor? 1 Answer

How can I add lighting to curved shader? 0 Answers

Creating a lighting shader 0 Answers

Make Sprite-Diffuse shader work on mesh renderer? 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