There are two potential scenarios to consider.
One possibility is that the internal buffer contains a value of 1.0 (255) for the alpha channel in all texels.
Alternatively, it could be that the buffer you are reading from does not have an alpha channel at all, meaning the internal format is likely RGB.
The WebGL 1.0 Specifications - 5.13.12 Reading back pixels makes reference to the OpenGL ES 2.0 Specification.
Referencing the OpenGL ES 2.0 Specification - 3.6.2 Transfer of Pixel Rectangles:
Final Expansion to RGBA
Each group is converted to a group of 4 elements as follows: If a group lacks an A element, then A is added and set to 1.0. If R, G, or B is missing from the group, each absent element is added and given a value of 0.0.
It is important to note that if you do not specify the alpha channel for the vertex attribute used in fragment color writing, the default alpha channel will be 1.0 (255 in RGBA8 buffer), as all vertex attributes initialize with (0, 0, 0, 1):
The WebGL 1.0 Specifications - 5.13.10 Uniforms and attributes also points towards the OpenGL ES 2.0 Specification.
Check out OpenGL ES 2.0 Specification - See 2.7 Current Vertex State:
The state required to support vertex specification includes MAX_VERTEX_ATTRIBS four-component floating-point vectors to store generic vertex attributes. The initial values for all generic vertex attributes are (0, 0, 0, 1).
If you intend to add an alpha channel to a geometry within a THREE.mesh
, you must use a transparent
material on the mesh with an opacity
lower than 1.0. View THREE.material
:
var geometry = new THREE.BoxGeometry( 10, 10, 10 );
var material = new THREE.MeshBasicMaterial( {
color: 0xff0000,
transparent: true,
opacity: 0.5,
} );
const cube = new THREE.Mesh(geometry, material);
To read an alpha channel successfully, ensure that the canvas has an alpha (transparency) buffer by setting the alpha
attribute of the THREE.WebGLRenderer
:
renderer = new THREE.WebGLRenderer( {
alpha: true
});