Issue 1:
Description of the problem

I am working on a Three.js project which requires thousands of unique meshes to be rendered. Since number of objects have big impact on rendering performance I merged those objects into single mesh (manually, not using geometry.merge() function) and created "pseudo objects" which keeps parent mesh reference and index data (faceIndexStart, faceIndexEnd) so that I can manipulate color and position of individual objects using those references. (I could not find a built in way to do that, please let me know if there is one). At the end I achieved a super performant scene.

However, I would like to manage visibility of those individual objects, too. I know I can use multimaterial but this will increase number of drawcalls which will have random effect on the performance.

For example; let's say I have a model with 10000 individual objects and I create single mesh by merging position and index vectors and create 10000 pseudo objects which just keep a reference to this mesh and information about this individual objects face indices. If I use multimaterial and hide 2000 of these objects during runtime. In the best case scenario those objects will be continuous in my buffers and I will have just one more draw call but if they are at random places I can have up to 1+2000*2 draw calls. One may suggest sortByMaterial function in that case but than it will mess up with order of my buffer attributes and my pseudo objects will be useless. (Not sure, correct me if I am wrong);

Suggestion

Three.js already supports everything neccessary to create single mesh out of lot's of meshes and pseudo meshes to manipulate position data of every single mesh. I can also manipulate color of those individual objects using vertex colors. It would be really helpful if materials could have THREE.faceVisibility or THREE.vertexVisibility as a value for visibility property and shader code to include logic to discard fragments based on "visibility" attribute value if one of those values I suggested passed on visibility property of a material.

Currently I am overriding MeshPhong shader code by string replacements to achieve this desired solution and it feels dirty/hacky. This suggestion seems to me easy to implement and doesn't seem to have any downsides.

EDIT: Here is the ugly/hacky thing I do:

var vert = THREE.ShaderChunk['meshphong_vert'];

THREE.ShaderChunk['meshphong_vert'] = `attribute float hidden;
varying float vhidden;
` + vert.replace('void main() {', `void main() {
vhidden=hidden;`);

var frag = THREE.ShaderChunk['meshphong_frag'];
THREE.ShaderChunk['meshphong_frag'] = `varying float vhidden;
` + frag.replace('void main() {', `void main() {
if(vhidden>0.0)
{
discard;
}`);

THREE.ShaderLib['phong'] = {

uniforms: THREE.UniformsUtils.merge([

THREE.UniformsLib['common'],
THREE.UniformsLib['aomap'],
THREE.UniformsLib['lightmap'],
THREE.UniformsLib['emissivemap'],
THREE.UniformsLib['bumpmap'],
THREE.UniformsLib['normalmap'],
THREE.UniformsLib['displacementmap'],
THREE.UniformsLib['fog'],
THREE.UniformsLib['lights'],

{
"emissive": { value: new THREE.Color(0x000000) },
"specular": { value: new THREE.Color(0x111111) },
"shininess": { value: 30 }
}

]),

vertexShader: THREE.ShaderChunk['meshphong_vert'],
fragmentShader: THREE.ShaderChunk['meshphong_frag']
};

Issue 2:
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

Example With Vertex Color Alpha

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, ...)