2
\$\begingroup\$

I create some simple geometrical shapes in Inkscape, then export it to PNG and import into Unity.

Positive example: I make a rectangle of colour hsva(0, 0, 32, 255), export it as a 32x32 PNG image and import to Unity. Then I put it into the scene. When I check its rendered colour with a probe tool it's perfectly correct: hsva(0, 0, 32, 255).

Negative (problematic) example: I create a right triangle of colour hsva(0, 0, 32, 255), export it as a 32x32 PNG image. Effect: half of the image is transparent and the triangle edge is "anti-aliased", but the main triangle's area in the PNG file still conserves its original colour.

enter image description here

Then I import it into Unity and I put it into the same scene and check its rendered colour with a probe tool. It's actually hsva(299, 8, 33, 255) - very dark purple, but still distinguishable from the (0, 0, 32, 255).

What am I doing wrong? Why is the rendered colour of the sprite different? How can I solve this problem?

Thanks in advance for your help :)

PD

Adding my import settings, as requested in on of the comments (now I'm experimenting with larger images 512x512, but the effect is the same): enter image description here

\$\endgroup\$
  • \$\begingroup\$ A few questions, Have you opened the png's with another image editting tool and verified the color values are indeed correct after exporting? Are you using the default sprite settings when importing? Are you using the point filter? \$\endgroup\$ – Eddge Aug 17 '17 at 13:42
  • \$\begingroup\$ Have you tried manipulating the shader of the auto-created game objects (when you drag the sprite into the scene)? If you go with standard shaders, the sprites might be affected by the scene's lighting settings. \$\endgroup\$ – Tolga Şen Aug 17 '17 at 13:45
  • \$\begingroup\$ Yes, verified in IrfanView that the colour is correct. The import setting for the two images are exactly the same. \$\endgroup\$ – Ismael Aug 17 '17 at 13:46
  • \$\begingroup\$ Can you show us your texture import settings? Specifically the compression mode and "Alpha is transparency" flags may be relevant here. \$\endgroup\$ – DMGregory Aug 17 '17 at 13:47
  • \$\begingroup\$ Added the import settings. My in-scene object uses default sprite material. \$\endgroup\$ – Ismael Aug 17 '17 at 14:00
2
\$\begingroup\$

Thanks @DMGregory and @Draco18s for help with this one!

The problem turned out to be the compression algorithm which Unity automatically applied for the imported image. The DXT5 compression reduced colour precision, provoking the subtle change in the rendered colour of the sprite.

The solution to the problem was changing Compression Quality from "Normal Quality" to "High Quality" in the default import settings for the image.

enter image description here

This could be also solved by explicitly overriding the compresison algorithm in the build-specific settings of the image, selecting BC7 compression algorithm for instance.

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.