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.

Include vertex color alpha?

See original GitHub issue
Description of the problem

I’m working with a set of models that use vertex color alpha. Now that threejs uses buffer geometry almost exclusively, adding in vertex color alpha is pretty simple, and it would be nice to see these changes upstream. The changes mostly involve declaring color as a vec4 instead of vec3.

'#ifdef USE_COLOR',
'   attribute vec4 color;',
'#endif',
var color_fragment = `
#ifdef USE_COLOR
    diffuseColor.rgb *= vColor.xyz;
    diffuseColor.a *= vColor.a;
#endif 
`;

var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec4 vColor;\n#endif\n";
var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec4 vColor;\n#endif";
var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyzw = color.xyzw;\n#endif";
Example Without Vertex Color Alpha

Imgur

Example With Vertex Color Alpha

Imgur

Three.js version
  • [ x ] Dev
  • r104
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
looeeecommented, May 8, 2019

The changes mostly involve declaring color as a vec4 instead of vec3.

Unfortunately, doing that will break all of the existing models that have RGB vertex colors so it’s not that simple.

See previous discussions: #2118 and #6014

It would be nice to revisit this issue and add support for RGBA vertex colors at some point. That would match the glTF spec which supports both RGB and RGBA .

In the meantime, you will need to create a custom shader to achieve this.

3reactions
chubeicommented, Dec 7, 2020

@donmccurdy guided me here. I’ll leave my implementation for discussion.

In https://github.com/chubei/three.js/tree/opacity, I added an aOpacity attribute, which is controlled by a shader macro USE_OPACITY, which is then controlled by a material property vertexOpacities (all of this mirrored the implementation of vertex colors).

In this way, users only pay for the vertex opacity attribute if they choose to.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to set the vertex color alpha component?
There is no alpha component in vertex colors in Blender. The property is array with size 3, not 4. You can have any...
Read more >
How do you use the Alpha channel of Vertex Colors?
The vertex colors do seem to have an alpha channel since you can choose “Add Alpha” or “Erase Alpha” in the blend mode...
Read more >
Alpha channel for vertex color ⁠— Right-Click Select
Alpha channel for vertex color ⁠— Right-Click Select. We can use another vertex color set to define alpha for internal work but what...
Read more >
How to set alpha of all vertex colors to 0? : r/blenderhelp - Reddit
I am trying to transfer some vertex groups to the node/shader editor, in order to have a mockup of fur colour before I...
Read more >
MSFS - How to see vertex paint alpha channel - FSDeveloper
To see the vertex paint alpha channel you can Add - Input - Vertex Color. Set the source to be Object Data Properties...
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