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
- Avatar Mask dropdowns in the Inspector reset and collapse whenever the Asset Type is deselected
- Category filter overlaps with the search bar icon in the Test Runner window when the window is minimized
- Deletion prompt is opened when trying to delete a Parent Blendtree State via delete shortcut
- “Assertion Failed”, “Invalid AABB a” and Mesh errors are thrown when editing Group Seed or Frequency settings for Tree Object
- “GetAllOverlapping failed…” error when clicking a GameObject during a custom picking pass in the Scene view for the second time
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.