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 TheAmishPirate · Feb 08, 2013 at 10:48 PM · texture2dgetpixels

GetPixels returning skewed results on DXT5 Texture

I'm making a 2D game in Unity, and I'm trying to use Texture2D.getPixels with a DXT5 compressed texture in order to make a spritesheet. It isn't coming out quite right.

Here's the original texture:

Original texture, do not steal

And here's what it looks like after using getPixels() to grab all of its colors, and write it into a new Texture:

And now it's all skewed up

Any ideas as to why this might now be working? I've tried this with uncompressed images, and it's worked just fine. It's clearly grabbing the colors, but the resulting image is transformed somehow.

If you need more information, let me know.

EDIT:

I'm using a modified third party tool to create spritesheets and sprite animations in the editor. The sprites are grabbed from the spritesheet at runtime...which may be the solution to the main memory problem. If the actual animation frames aren't needed after making the spritesheet, then I may not need to keep the textures in the editor. I'll try that later and let you know if that works. I don't know offhand if the tool needs the textures to remain in the editor after the spritesheet is built.

Back to the problem at hand: That one line of code is executed in the editor at development time. The texture I'm using is a NPOT .png, resolution 625x226.

The target platform for the game is PC, hypothetically XBox if we can get it done enough. I don't think this matters too much, as we need the textures at development time.

whoops.png (41.7 kB)
beacon neutral blue 6.png (45.2 kB)
Comment
Add comment · Show 1
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 TheAmishPirate · Feb 09, 2013 at 03:08 AM 0
Share

Here's the line where I actually do the GetPixels() call:

 _dest.SetPixels(x, y, num5, num6, _src.GetPixels(num3, (_src.height - num4) - num6, num5, num6));

Where: _dest is the destination texture, a spritesheet much larger than the source sprite

x and y are the location in the spritesheet where the source texture will be imported

num5 is the actual width of the sprite (not counting transparent pixels)

num6 is the actual height of the sprite (not counting transparent pixels)

_src is the source texture that contains the sprite

num3 is the x-location of the upper-right corner of the sprite in the source texture

num4 is the y-location of the upper-right corner of the sprite in the source texture

EDIT: The texture is on Advanced import settings

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Gizmoi · Feb 08, 2013 at 11:49 PM

Have you tried making it it non-power of 2 in the import settings?
Ideally if it's going to be a 2D image like a sprite, change its import type to GUI.
I also seem to remember that only certain formats play nicely with GetPixels. ARGB32 and RGBA32 I'm fairly sure work, for example.

Comment
Add comment · Show 10 · 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 TheAmishPirate · Feb 09, 2013 at 03:11 AM 0
Share

Wouldn't making the texture a non-power of 2 scale the sprite? I'd like to keep it at its current size.

I tried changing it to GUI, but it didn't fix the problem.

That's what I've read, but the fact that I can actually get some pixel values from GetPixels() is encouraging. I just need to figure out what it is about DXT compression that doesn't make it work.

That, and we have a TON of sprites in this game, and importing them all on a Truecolor setting is going to take up too much memory.

avatar image Gizmoi · Feb 09, 2013 at 03:17 AM 0
Share

I am assu$$anonymous$$g your image isn't a power of two. In which case, Unity will scale it to power of two. However part of the GUI import type allows non power of two.

Change the import type to Advanced and see what effect different formats there have, like I mentioned, I'm sure RGBA32 solved my similar issue.

avatar image TheAmishPirate · Feb 09, 2013 at 04:03 AM 0
Share

I've had the texture import settings on Advanced, I'll make a note of it in the original question.

As for the other settings, I've run through all of them with the same result: Anything that is compressed fails, everything else works.

However, I cannot leave the textures in as RGBA32. It takes up too much memory for our purposes. Hence why I'm going through all this trouble to get them in a compressed format.

avatar image Gizmoi · Feb 09, 2013 at 09:52 AM 0
Share

But I thought you were adding them to a sprite sheet for use in the game, meaning that this image will not actually be used, only the sprite sheet?

avatar image TheAmishPirate · Feb 09, 2013 at 03:40 PM 0
Share

Yes, the actual problem is that the game runs out of memory on a fresh load. Last time I checked out the project from our repository, Unity.exe used up 3.5 million $$anonymous$$ on the startup import and crashed. I opened it again, and then had to reimport everything that didn't load properly, and even then it sometimes would crash.

Is this not actually as big a problem as I made it out to be?

Show more comments
avatar image
0

Answer by Bunny83 · Feb 08, 2013 at 11:51 PM

Well, this looks like your target texture's width is off by one. Without seeing the code which you use to copy the image it's impossible to say anything. GetPixels returns a "flattened 2D array". What you see here is the typical case where you write a flattened array to a greater or smaller image. In this case i would guess the target size is one pixel larger than the source. That means each row has an additional pixel which originally was on the next row.

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 TheAmishPirate · Feb 09, 2013 at 03:04 AM 0
Share

I've checked the width/height values of both source and target, and they check out. Furthermore, they don't change when I shift from Truecolor to compressed, so that leads me to believe that may not be the case. I'll post the code that does the read/write of the pixels above.

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

11 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

Related Questions

rotate an image by modifying Texture2D.GetPixels32() array 2 Answers

getPixel/setPixels or stencil eraser brush 2 Answers

instantiate a texture2d so changes don't affect clones 1 Answer

How to get ARGB values from Texture object? 1 Answer

How to change origin of GetPixels 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