Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//https://threejs.org/examples/?q=webgl_instancing_modified#webgl_instancing_modified
const material = new THREE.MeshMatcapMaterial( { color: 0xaaaaff, matcap: texture } );
material.onBeforeCompile = function(shader) {
shader.vertexShader = shader.vertexShader
.replace("#include <common>", `
attribute vec3 instanceColor;
varying vec3 vInstanceColor;
#include <common>
`)
.replace("#include <begin_vertex>", `
#include <begin_vertex>
vInstanceColor = instanceColor;
`);
shader.fragmentShader = shader.fragmentShader
.replace("#include <common>", `
varying vec3 vInstanceColor;
#include <common>
`)
.replace("vec4 diffuseColor = vec4( diffuse, opacity );", `
vec4 diffuseColor = vec4( diffuse * vInstanceColor, opacity );
`);
//console.log( shader.uniforms );
//console.log( shader.vertexShader );
//console.log( shader.fragmentShader );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment