Skip to content

Instantly share code, notes, and snippets.

@gonnavis
Last active November 5, 2020 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gonnavis/024e099b6582034618199ef873752123 to your computer and use it in GitHub Desktop.
Save gonnavis/024e099b6582034618199ef873752123 to your computer and use it in GitHub Desktop.
//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