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
1
Question by MountDoomTeam · Sep 06, 2012 at 01:27 PM · instantiatecolorgetpixel

Using GetPixel to instantiate blocks of different pixel colors

Code help needed please!

I instantiate cube prefabs that have a colorful texture, i want to use material.SetTextureScale to zoom the entire texture to one pixel, and then use GetPixel to offset the material color to different pixels for different cubes.

is it possible with this instantiation? please help me with the code!

 var bullitPrefab : Transform;
 function Update ()
 { 
 
          if(Input.GetButton("Fire1")) 
       { 
       var bullit = Instantiate(bullitPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
       bullit.rigidbody.AddForce(transform.forward *8000);
       }
 
 }    

P.S. i already tried material.color, material.SetTextureOffset,sharedMaterial.SetTextureOffset, mainTextureOffset, etc to color instances without extra draw calls, they dont work! i get 1024 draw calls.

It's for procedural graphics(see pics), here's what i am doing, i simply cant set colors efficiently in unity, it's taken me hours and days of trying!!! learning very slowly :z

http://i45.tinypic.com/fci53o.jpg alt text

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 MountDoomTeam · Sep 06, 2012 at 02:32 PM 0
Share

Hi, SetTextureOffset works vaguely to make objects of different colors - But it seems to always invoke a new copy of the texture, so if i do 1000'ds of instantiations for some procedural work SetTextureOffset does 1000ds of draw calls!!! i just want the same but with batch working!

avatar image Fattie · Sep 06, 2012 at 02:34 PM 0
Share

that just sounds weird, i offset texture all the time w/ no woes! sorry can't help

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ThermalFusion · Sep 06, 2012 at 08:39 PM

You could use a vertex colored material, and set each models vertex colors to a specific color, this should let them batch, although may be very slow.

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 MountDoomTeam · Sep 07, 2012 at 08:15 PM 0
Share

Thanks ThermalFusion, I'd like to learn that trick although i have to figure out the right vertex colored shader, whether i have to copy the vertex lit one to my own version in resources, which commands will set the vertex colors from the reference, it will take me another 10 hours of newbie fumbling! i wish there was a working example of these things on the forums ;D. well i asked a guy for an example file in the unity forum that he did to find the max batch number of 15999, maybe he saw me struggling! i only took an hour and a bit to understand the solution you mention i think i would need another 10 15 hours by myself! :\

avatar image ThermalFusion · Sep 07, 2012 at 09:48 PM 0
Share

First off you would need a proper shader, this should do the trick: http://wiki.unity3d.com/index.php/VertexColor Then you would need to edit the meshes of the gameobjects ins$$anonymous$$d of the materials. http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$esh.html Then this page should tell you how to change the colors: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$esh-colors.html

avatar image ThermalFusion · Sep 07, 2012 at 09:54 PM 0
Share

I must also point this out to you before you dive too far into it: http://docs.unity3d.com/Documentation/$$anonymous$$anual/DrawCallBatching.html The dynamic batching doesn't do wonders, for example there's the 900 vertex attribute limit, and probably important for you, the scale limitations is probably also of importance to you.

avatar image MountDoomTeam · Sep 08, 2012 at 09:59 AM 0
Share

Thanks ThermalFusion that info is very welcome, it save so much fumbling in the dark. i'll also do a performance comparison with coloring by offsetting the UVs some day.

found an amazing code to do uv offset ins$$anonymous$$d of a texture trick, nice it works with most shaders. and you can set palettes from pics to use as colorpalettes. the code is 4 lines somewherein this website.

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

Combination of Instance and random in a network game 2 Answers

How to get pixel color from MovieTexture? 2 Answers

How to instantiate a prefab and change its color? 5 Answers

Instantiated prefab color change 2 Answers

Compare getPixel() to a Color 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