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 MainframePT · Feb 28, 2014 at 12:14 PM · c#shaderarraylist

Possible shader interference when updating matrix

Greetings,

I'm currently facing a problem regarding updating values of several arrays inside a list. The basic setup is the following: a List containing 2 arrays each comprised of 16 float numbers. Earlier I had a problem problem regarding the update of the each array: whenever I update one, it also instantly affects ALL other arrays present in the list, something that I didn't want to happen. Now the problem is somewhat similar except the update earlier mentioned doesn't happen instantly, i.e.:

  1. The matrix present in matrixList[0] is updated with calculated values;

  2. matrixList[1] remains unchanged;

  3. Swap to matrixList[1] to update her with new calculated values. It copies the values from matrixList[0] instead of the new calculated values.

The code is as follows (for a matter of simplicity I omitted most of the code, however I can post more if needed):

 enter code herepublic class Homography : MonoBehaviour {
 
             public float[] matrix;
             public const int arraySize = 16;
             public List<float[]> matrixList;
             
             void Start () {
                 InitMatrixList();
             }
             
             void InitMatrixList(){
                 
                 int numPlanes = manager.numExistPlanes;
                 matrixList = new List<float[]>();
                 for(int i = 0; i <= numPlanes; i++){
                     matrixList.Add(new float[16]);
                 }
             }
             
             void LateUpdate () {
                 
                 planeMatrixNum = manager.activePlaneNum;
                 matrix = matrixList[planeMatrixNum-1]; 
                 FindHomography(ref source, ref destination, ref matrix);
                 
                 meshMaterial.SetVector("matrixRow_1", new Vector4(matrix[0], matrix[4], matrix[8], matrix[12]));
                 meshMaterial.SetVector("matrixRow_2", new Vector4(matrix[1], matrix[5], matrix[9], matrix[13]));
                 meshMaterial.SetVector("matrixRow_3", new Vector4(matrix[2], matrix[6], matrix[10], matrix[14]));
                 meshMaterial.SetVector("matrixRow_4", new Vector4(matrix[3], matrix[7], matrix[11], matrix[15]));
                 
             }
             
 }

About the desired process flow of this application:

  1. GameObject 1 is selected in the scene and has its position changed;

  2. matrixList[0] is selected and updated with new values based on the GO1 position changes;

  3. GameObject 2 is selected in the scene and has its position changed;

  4. matrixList[1] is selected and updated with new values based on the GO2 position changes;

This script (Homography.cs) is attached one gameobject only. However the changes done to each of the Matrix present in the matrixList affect other gameobjects. Through debugging I notice he does save the matrix values for GameObject 1, however the same does not happen for GameObject 2, he just copies the values obtained from the matrix of GameObject 1 and applies them to his own matrix.

Also I don't really know if it's relevant since I have very limited experience but these matrix values (matrixRow_X) are used within a shader (not written by me).

EDIT: Used an old version of the code by mistake. Also added more info.

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
0

Answer by whydoidoit · Feb 28, 2014 at 12:17 PM

You are putting the same matrix array into each slot - you mean to do this I think:

 void InitMatrixList(){
  
     int numPlanes = manager.numExistPlanes;
     matrixList = new List<float[]>();
     for(int i = 0; i <= numPlanes; i++){
        matrixList.Add(new float[16]);
     }
 }

But I'm not sure how any of that would refer to your matrix variable (the one you were repeatedly adding). No chance the shader is doing this - wish it could :)

Comment
Add comment · Show 4 · 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 MainframePT · Feb 28, 2014 at 12:28 PM 0
Share

$$anonymous$$y bad! I wrongly copied the code from my earlier post, so it wasn't updated with that change. The problem I'm currently facing happens while using that exact same code you posted.

avatar image whydoidoit · Feb 28, 2014 at 12:30 PM 0
Share

You are only doing this once right? this script is only on one object - because otherwise you'd need it in some pre rendering function not LateUpdate or all of the variables will be overwritten.

avatar image whydoidoit · Feb 28, 2014 at 12:36 PM 0
Share

You are passing matrix to FindHomography as a ref parameter which indicates that this function might actually create and return a new matrix. If it does so then you are not storing that matrix and ought to add:

      matrixList[plane$$anonymous$$atrixNum-1] = matrix;
avatar image MainframePT · Feb 28, 2014 at 12:57 PM 0
Share

Through debugging he is storing and receiving the proper matrix values. Problem only occurs when I move to another matrix index. Also, decided to add quite a few more information to the original post.

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

21 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

Related Questions

Inventory System wont work 2 Answers

C# Enemy list for player to attack 2D 1 Answer

How to select an Game Object from an Item List 0 Answers

Problem with List not filling using add method in a foreach loop 1 Answer

How to modify array values? 1 Answer


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