diff --git a/examples/webgl_buffergeometry_instancing_lambert.html b/examples/webgl_buffergeometry_instancing_lambert.html index caf261802fd09e..da6e09b1c40d34 100644 --- a/examples/webgl_buffergeometry_instancing_lambert.html +++ b/examples/webgl_buffergeometry_instancing_lambert.html @@ -56,153 +56,150 @@ if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); - THREE.CustomShaderLib = { + THREE.ShaderLib.customDepthRGBA = { // this is a cut-and-paste of the depth shader -- modified to accommodate instancing for this app - customDepthRGBA: { // this is a cut-and-paste of the depth shader -- modified to accommodate instancing for this app + uniforms: THREE.ShaderLib.depth.uniforms, - uniforms: THREE.ShaderLib.depth.uniforms, + vertexShader: + ` + // instanced + #ifdef INSTANCED - vertexShader: - ` - // instanced - #ifdef INSTANCED + attribute vec3 instanceOffset; + attribute float instanceScale; - attribute vec3 instanceOffset; - attribute float instanceScale; + #endif - #endif + #include + #include + #include + #include + #include + #include + #include - #include - #include - #include - #include - #include - #include - #include + void main() { - void main() { + #include - #include + #include - #include + #ifdef USE_DISPLACEMENTMAP - #ifdef USE_DISPLACEMENTMAP + #include + #include + #include - #include - #include - #include + #endif - #endif + #include - #include + // instanced + #ifdef INSTANCED - // instanced - #ifdef INSTANCED + transformed *= instanceScale; + transformed = transformed + instanceOffset; - transformed *= instanceScale; - transformed = transformed + instanceOffset; + #endif - #endif + #include + #include + #include + #include + #include + #include - #include - #include - #include - #include - #include - #include + } + `, - } - `, + fragmentShader: THREE.ShaderChunk.depth_frag - fragmentShader: THREE.ShaderChunk.depth_frag + }; - }, + THREE.ShaderLib.lambert = { // this is a cut-and-paste of the lambert shader -- modified to accommodate instancing for this app - lambert: { // this is a cut-and-paste of the lambert shader -- modified to accommodate instancing for this app + uniforms: THREE.ShaderLib.lambert.uniforms, - uniforms: THREE.ShaderLib.lambert.uniforms, + vertexShader: + ` + #define LAMBERT - vertexShader: - ` - #define LAMBERT + #ifdef INSTANCED + attribute vec3 instanceOffset; + attribute vec3 instanceColor; + attribute float instanceScale; + #endif - #ifdef INSTANCED - attribute vec3 instanceOffset; - attribute vec3 instanceColor; - attribute float instanceScale; - #endif + varying vec3 vLightFront; - varying vec3 vLightFront; + #ifdef DOUBLE_SIDED - #ifdef DOUBLE_SIDED + varying vec3 vLightBack; - varying vec3 vLightBack; + #endif - #endif + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - - void main() { - - #include - #include - #include - - // vertex colors instanced - #ifdef INSTANCED - #ifdef USE_COLOR - vColor.xyz = instanceColor.xyz; - #endif - #endif + void main() { - #include - #include - #include - #include - #include + #include + #include + #include - #include - - // position instanced - #ifdef INSTANCED - transformed *= instanceScale; - transformed = transformed + instanceOffset; + // vertex colors instanced + #ifdef INSTANCED + #ifdef USE_COLOR + vColor.xyz = instanceColor.xyz; #endif + #endif + + #include + #include + #include + #include + #include + + #include - #include - #include - #include - #include - #include + // position instanced + #ifdef INSTANCED + transformed *= instanceScale; + transformed = transformed + instanceOffset; + #endif - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include - } - `, + #include + #include + #include + #include + #include - fragmentShader: THREE.ShaderLib.lambert.fragmentShader + } + `, - } + fragmentShader: THREE.ShaderLib.lambert.fragmentShader }; + // var mesh, renderer, scene, camera, controls; @@ -303,48 +300,30 @@ var envMap = new THREE.TextureLoader().load( `textures/metal.jpg`, function ( texture ) { texture.mapping = THREE.SphericalReflectionMapping; + texture.encoding = THREE.sRGBEncoding; + if ( mesh ) mesh.material.needsUpdate = true; } ); - var shader = THREE.CustomShaderLib[ 'lambert' ]; + var material = new THREE.MeshLambertMaterial( { - var uniforms = THREE.UniformsUtils.clone( shader.uniforms ); - - uniforms[ "diffuse" ].value.set( 0xffb54a ); - uniforms[ "envMap" ].value = envMap; - uniforms[ "reflectivity" ].value = 1; - - // defines - Since we are reusing the ShaderChunks, we must specify the required defines. - // The renderer does not set these defines for ShaderMaterial - - var defines = { - 'INSTANCED': "", - 'USE_ENVMAP': "", - 'ENVMAP_TYPE_SPHERE': "", - 'ENVMAP_MODE_REFLECTION': "", - 'ENVMAP_BLENDING_MULTIPLY': "", - }; - - var material = new THREE.ShaderMaterial( { - - // Material and ShaderMaterial properties can be set here -- except opacity - // the Lambert-properties must be set in the uniforms or defines - - defines: defines, - uniforms: uniforms, - vertexShader: shader.vertexShader, - fragmentShader: shader.fragmentShader, + color: 0xffb54a, + envMap: envMap, + combine: THREE.MultiplyOperation, + reflectivity: 0.8, vertexColors: THREE.VertexColors, - lights: true, fog: true } ); + material.defines = material.defines || {}; + material.defines[ 'INSTANCED'] = ""; + // custom depth material - required for instanced shadows - var shader = THREE.CustomShaderLib[ 'customDepthRGBA' ]; + var shader = THREE.ShaderLib[ 'customDepthRGBA' ]; var uniforms = THREE.UniformsUtils.clone( shader.uniforms );