question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data texture with LuminanceFormat used as alphaMap broken from r136

See original GitHub issue

Describe the bug

After upgrading from v135 to latest the data texture I was using is now logging WebGL warnings to console, looking through the changelog there doesn’t seem to be any breaking changes I should be aware of outside of setting needsUpdate. The change that affected this was introduced in v136.

WebGL warning: texStorage(Multisample)?: internalformat: Invalid enum value LUMINANCE
WebGL warning: texSubImage: The specified TexImage has not yet been specified.

Code

import {
  DataTexture,
  LuminanceFormat,
  UnsignedByteType,
} from 'three';

const primaryMask = new Uint8Array(2500);

const texture = new DataTexture(
  primaryMask,
  50,
  50,
  LuminanceFormat,
  UnsignedByteType
);

texture.needsUpdate = true;

In v135 - nothing logged to console, alphaMap working as intended (partial transparent) In v136 - two warnings logged to console, alphaMap not working as intended (everything transparent)

Live example

Expected behavior

No warnings logged to console, transparency working as intended.

Platform:

  • Device: Desktop
  • OS: MacOS
  • Browser: Firefox
  • Three.js version: r136

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
WestLangleycommented, Apr 2, 2022

@madou You can use this pattern to support a single-channel alpha map texture using RedFormat with three.js r139.

material.onBeforeCompile = function( shader ) {

	shader.fragmentShader = shader.fragmentShader.replace(

		`#include <alphamap_fragment>`,

		`#ifdef USE_ALPHAMAP
			diffuseColor.a *= texture2D( alphaMap, vUv ).r;   // read red channel, instead
		#endif`

	);

};

You could also use NodeMaterial, I assume.

0reactions
Mugen87commented, Apr 2, 2022

with RGFormat obviously it needs double the size of the array now so each array item now would be red/green?

Please keep in mind that gl.LUMINANCE is problematic since at least one WebGL implementation (ANGLE) has to expand texture data to four channels to make luminance textures work with Direct 3D. This is not necessary when using RGFormat (or RedFormat).

I do get one warning however which is THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType - is that a benign warning? Everything is working as expected even with this warning.

I suggest you ask this question at the forum or stackoverflow. If it turns out to be a problem of three.js, we can reopen this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use WebGL texture as a Three.js Texture map - Stack Overflow
I've already tried this solution. But it seems like THREE.Texture() doesn't grab data from raw WebGL texture. javascript · three.
Read more >
A Brief Introduction to Texture Mapping | Discover three.js
Textures are used to store surface details of the objects in our scenes, such as color, ... Data representing the UV mapping is...
Read more >
WebGL 3D - Data Textures
Let's create a 3x2 pixel LUMINANCE texture. Because it's LUMINANCE texture there is only 1 value per pixel and it is repeated for...
Read more >
Animations with alpha textures in Three.js
Here's the image we're going to use: 16x16 px black and white texture var alphaMap = new THREE.TextureLoader().load('alpha.png'); material.
Read more >
Three js alpha maps | Dustin John Pfister at github pages
CanvasTexture method as a way to create a texture to use as an alpha map. This kind of thing can also be used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found