Search Issue Tracker
By Design
Votes
2
Found in
2019.4
2020.2
2020.3
2021.1.0a1
2021.2
2021.2.14f1
2022.1
2022.2
Issue ID
1409238
Regression
No
RGB values from Texture2D.GetPixel are wrong when pixel has an alpha value of 0
How to reproduce:
1. Open the user's project "My project.zip"
2. Press Play and observe the 5th message in the Console window
Expected result: The message displays the corresponding RGB values of the pixel
Actual result: The message displays the RGB values of a neighboring pixel
Reproducible with: 2021.1.0a1, 2021.1.28f1, 2021.2.15f1, 2022.1.0b11, 2022.2.0a8 (left pixel is picked up)
Reproducible with: 2019.4.36f1, 2020.2.0a21, 2020.3.31f1 (bottom middle pixel is picked up)
Comments (1)
-
elliselkins
Mar 08, 2022 22:12
There is a mispelled word in the Actual Result description. It should be "to the left" instead of "to the lift"
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
Resolution Note:
The behaviour is in fact expected, though it can be confusing due to the awkward naming of the "Alpha Is Transparency" option in the Texture Importer Inspector.
The 3x3 textures in the repro project have the "Alpha Is Transparency" option toggled on. This toggle tells the importer that any fully transparent pixel (alpha == 0) won't be visible at all. As such: the RGB values of pixels with alpha == 0 are modified/pre-filtered using an algorithm to prevent possible filtering artefacts.
(For clarity, this toggle actually does not modify the behaviour of texture transparency in shaders or such, currently it only does what I've described above! The preview in the inspector is unfortunately a bit misleading...)
Since the pixel in the middle of the 3x3 textures have alpha == 0 and "Alpha Is Transparency" is toggled on, the algorithm modifies the RGB values of these middle pixels. As the texture is very small, the result can seem a bit odd though it is the expected result of the algorithm.
In this case, in order to obtain the expected RGB value for fully transparent pixels, one can simply turn off "Alpha Is Transparency" to disable the pre-filtering that occurs while importing.