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
2
Question by sovalopivia · Apr 10, 2015 at 10:51 PM · unity 5shaderunity5cg

Unity5 v Unity4 Shader array errors

in a CG shader with 4.6 the following methods for declaring arrays work, but in Unity 5.0 I am now getting either errors, or a black shader, and "upgrades" preventing compilation on various platforms. All the following variations previously worked, but now produce bad results.

 float2[2] array;
 
 float2[] array;
 
 float2[2] array = 
 {
     float2(1,  0),
     float2(0,  1),
 };
 
 float2[] array = 
 {
     float2(1,  0),
     float2(0,  1),
 };
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
2
Best Answer

Answer by sovalopivia · Apr 11, 2015 at 11:45 AM

It appears that array syntax is slightly different now. This is likely because D3D9 shader compiler was switched from Cg 2.2 to HLSL.

After a brief look at HLSL Syntax arrays are declared and initialised slightly differently. In CG in 4.6 you would declare an array in this format.

 float[2] array;

 float2[] array;
  
 float2[2] array = 
 {
     float2(1,  0),
     float2(0,  1),
 };
 
 float2[] array = 
 {
     float2(1,  0),
     float2(0,  1),
 };

in Unity 5.0 it now has to be declared like so.

 float array[2];

 // NOT ALLOWED! Array needs a length
 float2 array[];

 
 float2 array[2] = 
 {
     float2(1,  0),
     float2(0,  1),
 };
 
 float2 array[] = 
 {
     float2(1,  0),
     float2(0,  1),
 };
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 Beks_Omega · Aug 03, 2017 at 05:20 PM 1
Share

For anyone in the future if you're getting errors try declaring the array without the comma after the last float in the array:

     float2  _array[2] = 
     { 
         float2(0, 0),
         float2(.5, .5) //no comma
     };

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

19 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

Related Questions

Unity5 CG Shader get model position. 1 Answer

Unity 5 upgrade broke lightmapped shader 1 Answer

Transparent shader disappears with multiple objects 1 Answer

How to compare colors in Shaders? 2 Answers

Render object with different shader depending on the camera 2 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