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 MD_Reptile · Feb 10, 2014 at 09:23 AM · 2dtexture2dsetpixelssetpixelapply

Fastest rendering of 2D world with lots of changes to screen every frame?

If you have a texture, let's say 1024 * 1024, and your constantly changing pixels (getpixel setpixel apply) because on almost every update there are changes to draw - what's the most optimal technique to render that efficiently?

I looked into something involving render texture, and in not sure how that applies in this situation because that seems more for rendering a cameras view? What I've been trying is just having a quad with a camera, both setup to be full screen, but find the performance too sluggish for mobile use, which I have little optimization elsewhere, but bottleneck seems to be in apply() of textures rapidly... Who has suggestions? Must be better ways to handle this stuff? Any experts on 2D pixel level changes rapidly updating in unity? :)

Comment
Add comment · Show 9
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 Benproductions1 · Feb 10, 2014 at 09:30 AM 0
Share

There is no fast way of changing a texture entity as you describe it. Every change causes the entire texture to be loaded from the graphics card back into RA$$anonymous$$ and then back again. This is a very expensive process.

It would be better if you described what you want to accomplish, because most of the time, standard rendering techniques are much much faster.

avatar image MD_Reptile · Feb 10, 2014 at 10:44 PM 0
Share

Well basically I am doing dynamic terrain, that is able to be broken up and added to, so pixels can be removed or added to the ground, as well as a layer of "dynamic" pixels which can move around such as the player and projectiles. These work, but just bog down my old dual core notebook a bit, and thats when I do several setpixel() and at the end of that an apply() during updates. Basically I could do things like keep all the information in color arrays ins$$anonymous$$d of actual textures, if there were only some other way to get the color/alpha info directly drawn to screen (on mobile as well) that I can edit on the fly (a LOT) and have changes happen very quickly to keep the action going (think cortex command or liero)

I can only think of one other way to handle it - and its ugly and bad I know it - which would be lots of 1x1 quads, each with renderer color set to match an array of my colors - but my bet is that would be more costly than just two "texture2d"s and alot of apply and such. Who knows maybe that might perform better since there would be no loading unloading of texture info, but would mean that 1024 x 1024 = 1,048,576 quads with 100+ changing each frame from "removing" and "adding" pixels all over...

avatar image xt-xylophone · Feb 10, 2014 at 10:49 PM 0
Share

So ins$$anonymous$$d of a camera looking at a moving game world, your camera is looking at a texture, which is changing like your game would?

avatar image MD_Reptile · Feb 10, 2014 at 11:09 PM 1
Share

well yes, setup as "pixel-perfect" camera looking at 1024x1024 texture (for testing purposes i am using the square, later will be a pot rect)

Here is what it is, just a heavily re-coded version of this project, which I posted a few months back:

http://forum.unity3d.com/threads/198919-Destructible-Pixel-Terrain-Open-Source

Which was a port of a Java/Processing project, and as of right now I have been doing a ton of work on it without updating anything in that thread, so it is way way out of date - but gives you an idea whats I am trying to do here.... hope that helps explain my setup

avatar image Benproductions1 · Feb 11, 2014 at 06:20 AM 0
Share

A way you could avoid any CPU work would be to use a render texture and then evaluate changes using a shader (like a post-effect)

Show more comments

3 Replies

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

Answer by MD_Reptile · Nov 30, 2014 at 02:30 AM

A proper answer for this problem is to use smaller textures tiled to represent the overall texture, and only update (Apply() after setpixels) any tiles which have been changed. I ended up writing my own editor script which does this slicing and re-assigning automatically for me - saving me tons of effort and time, then I had to write methods that consider the "cells" of each section of the overall image and grabs pixels from there, and sets pixels from there. Good luck anybody trying to take this on!

PS Do not even think about trying to using little 1x1 quads as your representation of your world - works horribly.

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
avatar image
-3

Answer by unimechanic · Feb 21, 2014 at 09:17 PM

This question became a discussion, consider using Unity Forums which is a great place to discuss ideas. Adding this answer to remove it from the Unanswered view and give more relevance to other questions requiring attention. Thanks for your comprehension, Unity Support.

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
avatar image
0

Answer by luniac · Nov 30, 2014 at 02:53 AM

It sounds like you want tilemaps like terraria or something... i believe 2Dtoolkit has a tilemap part to their plugin and it's pretty fleshed out and optimized. Maybe that's what you're looking for.

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 MD_Reptile · Nov 30, 2014 at 04:53 AM 0
Share

Well perhaps similar, but at per pixel destruction detail. I have solved this problem but thanks for your answer.

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

22 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 avatar image

Related Questions

Texture2D update every frame - The right method 4 Answers

Drawing a solid circle onto texture 2 Answers

Best Method for Setting Mass Numbers of Pixels (SetPixel, SetPixels) 2 Answers

Translate a pixel using SetPixel on a Texture2D? 1 Answer

SetPixels/Apply: Texture2D resets on restart 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