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 Lightstream · Jun 25, 2015 at 06:34 PM · texturealphadrawingspikes

In game paint brush with spreading. LoadRawTextureData() issues.

Hi everybody. This is my first question here ! My english is poor and forgive me for my typos/misspelling.

First of all, take a look on the result i want :

alt text

This is close to the final result, and the shader part is not merged yet, but that's a good visual to show what i want. The problem is : my CPU is totally overloaded. It looks smooth, but it's not when i have a great amount of points.

I'm going explain how i proceeded. It's a 2D game with sprites.

  • When the game start, i create a texture from scratch, same size of the sprite it's on.

  • Then when Input.MouseButtonDown, i cast a Ray and if it hits the sprite, i start a function which create a cricle.

  • When a circle is drawn, the function will draw the same circle next frame with radius +1 until it reaches the bounds of the sprite.

What am i using?

I create my texture like that :

 texture = new Texture2D(spriteWidth, spriteHeight, TextureFormat.Alpha8, false);
 
 filling = new byte[spriteWidth * spriteHeight];
 
 for(int i=0; i<filling.Length ; i++){
     filling[i] = 0x00;
 }
 
 // Load data into the texture and upload it to the GPU.
 texture.LoadRawTextureData(filling);
 texture.Apply();
 
 // Assign texture to renderer's material.
 targetRenderer.material.mainTexture = texture;

I'm using a byte array to stock alpha (alpha8 texture) to minimize useless data.

But i read something that said actually, references are created in my array so it uses 4bytes to create a reference (same like pointers in c++, doesnt it?) to read the 1byte i've created? It sounds stupid. Is this true?

On a second hand, i've got spikes in the profiler when i apply my changes :

I've got an algotithm to get the pixels on texture to change inspired from this where i use C# part

It works well except the part where i apply changes on my texture. I'm doing like this :

     public void RefreshAndApplyTexture()
     {
         texture.LoadRawTextureData(filling);
         texture.Apply();
         targetRenderer.material.mainTexture = texture;
     }

It looks like LoadRawTextureData() burning my CPU everytime it's called because it had to refresh my whole array of pixels (around 1 million entries for 1k texture). I call it every frame i have to draw a cicle, for each point which draw a circle (with 10 origin points, it will be called 10 times). I don't know how to deal with this and i assume that i've reached c# limits... Or i'm just using the wrong way to do it.

Can you tell me how you would process for something like that?

This is my profiler : alt text

And by the way, i think my 1 million entry array makes my garbage collector mad, using around 6ms every spike...

Thank you for reading this and i hope you will be able to help me.

gifbrush.gif (441.7 kB)
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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Draw Semi-transparent texture. 1 Answer

When doing two passes on different alphas, shader gets overwritten. 0 Answers

How can I draw an array of data (640x480) very fast ? 5 Answers

render Alpha only on another Alpha 0 Answers

Best practices : alpha channel and atlas 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