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.

MaterialLoader changes transparent to true when alphaMap present

See original GitHub issue
Description of the problem

MaterialLoader changes the loaded material’s transparent property to true if there is an alphaMap defined. This might be desirable when transparent is undefined so that transparent doesn’t default to false. However, when transparent is explicitly defined as false in the material JSON, it should probably be recognized as false by MaterialLoader.

Here is the code from MaterialLoader.js

if ( json.alphaMap !== undefined ) {

	material.alphaMap = getTexture( json.alphaMap );
	material.transparent = true;

}

The following is a potential solution to this

if ( json.alphaMap !== undefined ) {

	material.alphaMap = getTexture( json.alphaMap );

	if (json.transparent !== undefined) {
		material.transparent = json.transparent;
	}
	else {
		material.transparent = true;
	}
}

This example shows why you might want to have transparent = false with an alphaMap. This material uses alphaTest to create sharp edges with the AlphaMap. If transparent = true, the edges start to fade and no longer look clean.

{
	"uuid": "9ebca7f1-90b0-49d2-8a87-94a7b381811f","type": "PointsMaterial",
	"color": 15728768,
	"size": 0.3,
	"sizeAttenuation": true,
	"alphaMap": "da9f3d50-e5d3-4384-a594-861c5ab02a6d",
	"transparent": false,
	"alphaTest": 0.5
}

Here is what the fix looks like when I test it. It provides the clean edges that you might want in a data visualization, for instance.

current (transparent=true): transparent_true

proposed (transparent=false): transparent_false

Three.js version
  • Dev
  • r113
Browser
  • All of them
OS
  • All of them

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
meliharveycommented, Feb 22, 2020

Sure I’ll file a PR.

1reaction
WestLangleycommented, Feb 22, 2020

Exactly. If you export and then import, and don’t get what you started with, then something is wrong.

Would you like to file a PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Geometry with white alphaMap and transparency=true ...
Set transparent to true and opacity=1 on the same geometry; The geometry is not rendered fully opaque, even though the alpha mask is...
Read more >
Using an alphaMap is not providing transparency in my material
Try setting the transparent parameter to true instead of transparency material.transparent = true;.
Read more >
MeshBasicMaterial#alphaMap – three.js docs
The alpha map is a grayscale texture that controls the opacity across the surface (black: fully transparent; white: fully opaque). Default is null....
Read more >
Transparent Materials in threejs | Dustin John Pfister at github ...
When creating the basic material I just need to set the transparent property of the material to true. Once I have the transparency...
Read more >
Viewing online file analysis results for 'three.js'
( sum );last = current;}this. ... alphaMap );material.transparent = true;}if ( json. ... json.opacity < 1 ) json.transparent = true;materialLoader.
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