Last active
November 5, 2020 04:16
-
-
Save gonnavis/024e099b6582034618199ef873752123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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