diff --git a/docs/api/extras/ShaderUtils.html b/docs/api/extras/ShaderUtils.html
deleted file mode 100644
index 8ad6d52df43a35f1ec96aa829741f80dcdb5b925..0000000000000000000000000000000000000000
--- a/docs/api/extras/ShaderUtils.html
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
-
- [name]
-
- todo
-
-
- Constructor
-
- [name]()
-
-
- Properties
-
- .[page:Vector3 todo]
-
-
- Methods
-
- .todo( [page:Vector3 todo] )
-
- todo — todo
-
-
-
- Source
-
- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
-
-
diff --git a/docs/list.js b/docs/list.js
index 418a3daed4fe9a660ee4ffb3cf8a534ee3f857cd..ba690280aac8b9bdb36fd51808866742dc1d2a42 100644
--- a/docs/list.js
+++ b/docs/list.js
@@ -132,8 +132,7 @@ var list = {
[ "FontUtils", "api/extras/FontUtils" ],
[ "GeometryUtils", "api/extras/GeometryUtils" ],
[ "ImageUtils", "api/extras/ImageUtils" ],
- [ "SceneUtils", "api/extras/SceneUtils" ],
- [ "ShaderUtils", "api/extras/ShaderUtils" ]
+ [ "SceneUtils", "api/extras/SceneUtils" ]
],
"Extras / Animation": [
diff --git a/examples/misc_controls_fly.html b/examples/misc_controls_fly.html
index a7c2bcbee98fa923b7b95786a6ec855f844a501e..2f0fbd1084e491adfb0bfee0ca8233467b66fb1c 100644
--- a/examples/misc_controls_fly.html
+++ b/examples/misc_controls_fly.html
@@ -117,7 +117,7 @@
var moonTexture = THREE.ImageUtils.loadTexture( "textures/planets/moon_1024.jpg" );
- var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var shader = THREE.ShaderLib[ "normal2" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "tNormal" ].value = normalTexture;
diff --git a/examples/webgl_loader_ctm.html b/examples/webgl_loader_ctm.html
index 48b3820760c34101090960f15d8bbb61d97b357e..719f1bc1ac844e2c96bdf35afc4bd7292e343624 100644
--- a/examples/webgl_loader_ctm.html
+++ b/examples/webgl_loader_ctm.html
@@ -188,7 +188,7 @@
var ambient = 0xffffff, diffuse = 0xffffff, specular = 0x0e0e0e, shininess = 50;
- var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var shader = THREE.ShaderLib[ "normal2" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "tNormal" ].value = THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
diff --git a/examples/webgl_loader_ctm_materials.html b/examples/webgl_loader_ctm_materials.html
index c633aee587f9892a0a5d566fb548e88377192326..05335163920ab96b5025123e6201ea77864edd0b 100644
--- a/examples/webgl_loader_ctm_materials.html
+++ b/examples/webgl_loader_ctm_materials.html
@@ -114,7 +114,7 @@
textureCube = THREE.ImageUtils.loadTextureCube( urls );
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cars.html b/examples/webgl_materials_cars.html
index 2aec606ad1640ff3de9af4f3c7283a208728686b..4ee30453c4f5480940e7fef35316e5af76d8730d 100644
--- a/examples/webgl_materials_cars.html
+++ b/examples/webgl_materials_cars.html
@@ -191,7 +191,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cars_anaglyph.html b/examples/webgl_materials_cars_anaglyph.html
index 82bad15a61a2ea4f7f9855343c119908490d5403..1215bcf39e80bf9b0bb541732a0f3fa3e7d96f6d 100644
--- a/examples/webgl_materials_cars_anaglyph.html
+++ b/examples/webgl_materials_cars_anaglyph.html
@@ -185,7 +185,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cars_parallaxbarrier.html b/examples/webgl_materials_cars_parallaxbarrier.html
index 323ba3c70ad2f3c084db1e0e0022e43fc9f7bfe5..7ab478eda4fdf63b26f0035108e69f730cc0a9d0 100644
--- a/examples/webgl_materials_cars_parallaxbarrier.html
+++ b/examples/webgl_materials_cars_parallaxbarrier.html
@@ -185,7 +185,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cubemap.html b/examples/webgl_materials_cubemap.html
index 341921b8314188867b4ede14359d41d4be9cf8c0..f1c59df56ba306b4d4cce35f261478eddcab221d 100644
--- a/examples/webgl_materials_cubemap.html
+++ b/examples/webgl_materials_cubemap.html
@@ -118,7 +118,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = reflectionCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cubemap_balls_reflection.html b/examples/webgl_materials_cubemap_balls_reflection.html
index 1eefb8a258f0d3563869b13a77a34791398e0248..96061ecb0d0e8a1999674c51a735aa9f2f9997a9 100644
--- a/examples/webgl_materials_cubemap_balls_reflection.html
+++ b/examples/webgl_materials_cubemap_balls_reflection.html
@@ -108,7 +108,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cubemap_balls_reflection_anaglyph.html b/examples/webgl_materials_cubemap_balls_reflection_anaglyph.html
index b31917dbded13fcad30a163a110766bd6668f4df..08c573b5f5c1a95977825ae1913f715fa7d2f50a 100644
--- a/examples/webgl_materials_cubemap_balls_reflection_anaglyph.html
+++ b/examples/webgl_materials_cubemap_balls_reflection_anaglyph.html
@@ -106,7 +106,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cubemap_balls_refraction.html b/examples/webgl_materials_cubemap_balls_refraction.html
index 35820211c0631cfe6a682e05e220966a32634bb9..e42107a0ae4b80dcca172e7d569d22bc32899355 100644
--- a/examples/webgl_materials_cubemap_balls_refraction.html
+++ b/examples/webgl_materials_cubemap_balls_refraction.html
@@ -107,7 +107,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cubemap_balls_refraction_crosseyed.html b/examples/webgl_materials_cubemap_balls_refraction_crosseyed.html
index 0d6977bf5202293f0f641cf363d091f8becd7115..0f1b3e8e3cb5262c788c293042c24b282db24345 100644
--- a/examples/webgl_materials_cubemap_balls_refraction_crosseyed.html
+++ b/examples/webgl_materials_cubemap_balls_refraction_crosseyed.html
@@ -107,7 +107,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cubemap_escher.html b/examples/webgl_materials_cubemap_escher.html
index 040e78782ab0f2f069b4501842680e7cab195d1a..f9d2b5002cb2dfbfd5f81ff554278481c085d82e 100644
--- a/examples/webgl_materials_cubemap_escher.html
+++ b/examples/webgl_materials_cubemap_escher.html
@@ -96,7 +96,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_cubemap_refraction.html b/examples/webgl_materials_cubemap_refraction.html
index a23a8a434f43610328b3654d4205bfaf4ad9fb52..c26c7f9ff44ad0c38d77cf1b2ac42f6a5eeb2fb1 100644
--- a/examples/webgl_materials_cubemap_refraction.html
+++ b/examples/webgl_materials_cubemap_refraction.html
@@ -111,7 +111,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_materials_normalmap.html b/examples/webgl_materials_normalmap.html
index 6055ef1efb64eccf7d1ba170f90edc264891ee14..e963ec82c6823c0c7214d7df9af7538cebf00f18 100644
--- a/examples/webgl_materials_normalmap.html
+++ b/examples/webgl_materials_normalmap.html
@@ -155,7 +155,7 @@
// normal map shader
- var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var shader = THREE.ShaderLib[ "normal2" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "enableAO" ].value = true;
diff --git a/examples/webgl_materials_normalmap2.html b/examples/webgl_materials_normalmap2.html
index f362978862222c63f746a7b347f0bad7ec0a5c9a..5861982b0b56ec04b9e4f05932e917114d0ea4cb 100644
--- a/examples/webgl_materials_normalmap2.html
+++ b/examples/webgl_materials_normalmap2.html
@@ -122,7 +122,7 @@
var ambient = 0x111111, diffuse = 0xbbbbbb, specular = 0x060606, shininess = 35;
- var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var shader = THREE.ShaderLib[ "normal2" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "tNormal" ].value = THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
diff --git a/examples/webgl_materials_shaders_fresnel.html b/examples/webgl_materials_shaders_fresnel.html
index 3bfd663d9c9596188eb116c9b627077b579c6c63..b60638acb01dd933b85f1b690d7b328e6c189626 100644
--- a/examples/webgl_materials_shaders_fresnel.html
+++ b/examples/webgl_materials_shaders_fresnel.html
@@ -90,7 +90,7 @@
var textureCube = THREE.ImageUtils.loadTextureCube( urls );
textureCube.format = THREE.RGBFormat;
- var shader = THREE.ShaderUtils.lib[ "fresnel" ];
+ var shader = THREE.ShaderLib[ "fresnel" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "tCube" ].value = textureCube;
@@ -118,7 +118,7 @@
// Skybox
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial( {
diff --git a/examples/webgl_postprocessing_advanced.html b/examples/webgl_postprocessing_advanced.html
index c43d56bb44310d46ed112132fb3e0d0171d84d88..1a8eca3b57010e77e40ca40bb47713898496a060 100644
--- a/examples/webgl_postprocessing_advanced.html
+++ b/examples/webgl_postprocessing_advanced.html
@@ -330,7 +330,7 @@
var ambient = 0x444444, diffuse = 0x999999, specular = 0x080808, shininess = 20;
- var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var shader = THREE.ShaderLib[ "normal2" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "tNormal" ].value = THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
diff --git a/examples/webgl_shading_physical.html b/examples/webgl_shading_physical.html
index 370fc1f45028682b86b4faf55bb176a006c441a9..d815f93486a465f016b26eaedd13cc703987ab1e 100644
--- a/examples/webgl_shading_physical.html
+++ b/examples/webgl_shading_physical.html
@@ -202,7 +202,7 @@
// MATERIALS
- var shader = THREE.ShaderUtils.lib[ "cube" ];
+ var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].texture = cubeCamera.renderTarget;
shader.uniforms[ "tFlip" ].value = 1;
diff --git a/src/extras/ShaderUtils.js b/src/extras/ShaderUtils.js
deleted file mode 100644
index 9d41d62b90d3e444a4d6df1db4dc9b41ef841092..0000000000000000000000000000000000000000
--- a/src/extras/ShaderUtils.js
+++ /dev/null
@@ -1,777 +0,0 @@
-/**
- * @author alteredq / http://alteredqualia.com/
- * @author mrdoob / http://mrdoob.com/
- *
- * ShaderUtils currently contains:
- *
- * fresnel
- * normal
- * cube
- *
- */
-
-THREE.ShaderUtils = {
-
- lib: {
-
- /* -------------------------------------------------------------------------
- // Fresnel shader
- // - based on Nvidia Cg tutorial
- ------------------------------------------------------------------------- */
-
- 'fresnel': {
-
- uniforms: {
-
- "mRefractionRatio": { type: "f", value: 1.02 },
- "mFresnelBias": { type: "f", value: 0.1 },
- "mFresnelPower": { type: "f", value: 2.0 },
- "mFresnelScale": { type: "f", value: 1.0 },
- "tCube": { type: "t", value: null }
-
- },
-
- fragmentShader: [
-
- "uniform samplerCube tCube;",
-
- "varying vec3 vReflect;",
- "varying vec3 vRefract[3];",
- "varying float vReflectionFactor;",
-
- "void main() {",
-
- "vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
- "vec4 refractedColor = vec4( 1.0 );",
-
- "refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;",
- "refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;",
- "refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;",
-
- "gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );",
-
- "}"
-
- ].join("\n"),
-
- vertexShader: [
-
- "uniform float mRefractionRatio;",
- "uniform float mFresnelBias;",
- "uniform float mFresnelScale;",
- "uniform float mFresnelPower;",
-
- "varying vec3 vReflect;",
- "varying vec3 vRefract[3];",
- "varying float vReflectionFactor;",
-
- "void main() {",
-
- "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- "vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
-
- "vec3 worldNormal = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
-
- "vec3 I = worldPosition.xyz - cameraPosition;",
-
- "vReflect = reflect( I, worldNormal );",
- "vRefract[0] = refract( normalize( I ), worldNormal, mRefractionRatio );",
- "vRefract[1] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.99 );",
- "vRefract[2] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.98 );",
- "vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), worldNormal ), mFresnelPower );",
-
- "gl_Position = projectionMatrix * mvPosition;",
-
- "}"
-
- ].join("\n")
-
- },
-
- /* -------------------------------------------------------------------------
- // Normal map shader
- // - Blinn-Phong
- // - normal + diffuse + specular + AO + displacement + reflection + shadow maps
- // - point and directional lights (use with "lights: true" material option)
- ------------------------------------------------------------------------- */
-
- 'normal' : {
-
- uniforms: THREE.UniformsUtils.merge( [
-
- THREE.UniformsLib[ "fog" ],
- THREE.UniformsLib[ "lights" ],
- THREE.UniformsLib[ "shadowmap" ],
-
- {
-
- "enableAO" : { type: "i", value: 0 },
- "enableDiffuse" : { type: "i", value: 0 },
- "enableSpecular" : { type: "i", value: 0 },
- "enableReflection": { type: "i", value: 0 },
- "enableDisplacement": { type: "i", value: 0 },
-
- "tDisplacement": { type: "t", value: null }, // must go first as this is vertex texture
- "tDiffuse" : { type: "t", value: null },
- "tCube" : { type: "t", value: null },
- "tNormal" : { type: "t", value: null },
- "tSpecular" : { type: "t", value: null },
- "tAO" : { type: "t", value: null },
-
- "uNormalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) },
-
- "uDisplacementBias": { type: "f", value: 0.0 },
- "uDisplacementScale": { type: "f", value: 1.0 },
-
- "uDiffuseColor": { type: "c", value: new THREE.Color( 0xffffff ) },
- "uSpecularColor": { type: "c", value: new THREE.Color( 0x111111 ) },
- "uAmbientColor": { type: "c", value: new THREE.Color( 0xffffff ) },
- "uShininess": { type: "f", value: 30 },
- "uOpacity": { type: "f", value: 1 },
-
- "useRefract": { type: "i", value: 0 },
- "uRefractionRatio": { type: "f", value: 0.98 },
- "uReflectivity": { type: "f", value: 0.5 },
-
- "uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) },
- "uRepeat" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
-
- "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
-
- }
-
- ] ),
-
- fragmentShader: [
-
- "uniform vec3 uAmbientColor;",
- "uniform vec3 uDiffuseColor;",
- "uniform vec3 uSpecularColor;",
- "uniform float uShininess;",
- "uniform float uOpacity;",
-
- "uniform bool enableDiffuse;",
- "uniform bool enableSpecular;",
- "uniform bool enableAO;",
- "uniform bool enableReflection;",
-
- "uniform sampler2D tDiffuse;",
- "uniform sampler2D tNormal;",
- "uniform sampler2D tSpecular;",
- "uniform sampler2D tAO;",
-
- "uniform samplerCube tCube;",
-
- "uniform vec2 uNormalScale;",
-
- "uniform bool useRefract;",
- "uniform float uRefractionRatio;",
- "uniform float uReflectivity;",
-
- "varying vec3 vTangent;",
- "varying vec3 vBinormal;",
- "varying vec3 vNormal;",
- "varying vec2 vUv;",
-
- "uniform vec3 ambientLightColor;",
-
- "#if MAX_DIR_LIGHTS > 0",
-
- "uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
- "uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
-
- "#endif",
-
- "#if MAX_HEMI_LIGHTS > 0",
-
- "uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];",
- "uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];",
- "uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];",
-
- "#endif",
-
- "#if MAX_POINT_LIGHTS > 0",
-
- "uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
- "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
- "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
-
- "#endif",
-
- "#if MAX_SPOT_LIGHTS > 0",
-
- "uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
- "uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
- "uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
- "uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];",
- "uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
- "uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
-
- "#endif",
-
- "#ifdef WRAP_AROUND",
-
- "uniform vec3 wrapRGB;",
-
- "#endif",
-
- "varying vec3 vWorldPosition;",
- "varying vec3 vViewPosition;",
-
- THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
-
- "void main() {",
-
- "gl_FragColor = vec4( vec3( 1.0 ), uOpacity );",
-
- "vec3 specularTex = vec3( 1.0 );",
-
- "vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;",
- "normalTex.xy *= uNormalScale;",
- "normalTex = normalize( normalTex );",
-
- "if( enableDiffuse ) {",
-
- "#ifdef GAMMA_INPUT",
-
- "vec4 texelColor = texture2D( tDiffuse, vUv );",
- "texelColor.xyz *= texelColor.xyz;",
-
- "gl_FragColor = gl_FragColor * texelColor;",
-
- "#else",
-
- "gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );",
-
- "#endif",
-
- "}",
-
- "if( enableAO ) {",
-
- "#ifdef GAMMA_INPUT",
-
- "vec4 aoColor = texture2D( tAO, vUv );",
- "aoColor.xyz *= aoColor.xyz;",
-
- "gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;",
-
- "#else",
-
- "gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;",
-
- "#endif",
-
- "}",
-
- "if( enableSpecular )",
- "specularTex = texture2D( tSpecular, vUv ).xyz;",
-
- "mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );",
- "vec3 finalNormal = tsb * normalTex;",
-
- "#ifdef FLIP_SIDED",
-
- "finalNormal = -finalNormal;",
-
- "#endif",
-
- "vec3 normal = normalize( finalNormal );",
- "vec3 viewPosition = normalize( vViewPosition );",
-
- // point lights
-
- "#if MAX_POINT_LIGHTS > 0",
-
- "vec3 pointDiffuse = vec3( 0.0 );",
- "vec3 pointSpecular = vec3( 0.0 );",
-
- "for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
-
- "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
- "vec3 pointVector = lPosition.xyz + vViewPosition.xyz;",
-
- "float pointDistance = 1.0;",
- "if ( pointLightDistance[ i ] > 0.0 )",
- "pointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );",
-
- "pointVector = normalize( pointVector );",
-
- // diffuse
-
- "#ifdef WRAP_AROUND",
-
- "float pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );",
- "float pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );",
-
- "vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
-
- "#else",
-
- "float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
-
- "#endif",
-
- "pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;",
-
- // specular
-
- "vec3 pointHalfVector = normalize( pointVector + viewPosition );",
- "float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
- "float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );",
-
- "#ifdef PHYSICALLY_BASED_SHADING",
-
- // 2.0 => 2.0001 is hack to work around ANGLE bug
-
- "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
-
- "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );",
- "pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
-
- "#else",
-
- "pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;",
-
- "#endif",
-
- "}",
-
- "#endif",
-
- // spot lights
-
- "#if MAX_SPOT_LIGHTS > 0",
-
- "vec3 spotDiffuse = vec3( 0.0 );",
- "vec3 spotSpecular = vec3( 0.0 );",
-
- "for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
-
- "vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
- "vec3 spotVector = lPosition.xyz + vViewPosition.xyz;",
-
- "float spotDistance = 1.0;",
- "if ( spotLightDistance[ i ] > 0.0 )",
- "spotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );",
-
- "spotVector = normalize( spotVector );",
-
- "float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );",
-
- "if ( spotEffect > spotLightAngleCos[ i ] ) {",
-
- "spotEffect = max( pow( spotEffect, spotLightExponent[ i ] ), 0.0 );",
-
- // diffuse
-
- "#ifdef WRAP_AROUND",
-
- "float spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );",
- "float spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );",
-
- "vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );",
-
- "#else",
-
- "float spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );",
-
- "#endif",
-
- "spotDiffuse += spotDistance * spotLightColor[ i ] * uDiffuseColor * spotDiffuseWeight * spotEffect;",
-
- // specular
-
- "vec3 spotHalfVector = normalize( spotVector + viewPosition );",
- "float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );",
- "float spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, uShininess ), 0.0 );",
-
- "#ifdef PHYSICALLY_BASED_SHADING",
-
- // 2.0 => 2.0001 is hack to work around ANGLE bug
-
- "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
-
- "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( spotVector, spotHalfVector ), 5.0 );",
- "spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;",
-
- "#else",
-
- "spotSpecular += spotDistance * spotLightColor[ i ] * uSpecularColor * spotSpecularWeight * spotDiffuseWeight * spotEffect;",
-
- "#endif",
-
- "}",
-
- "}",
-
- "#endif",
-
- // directional lights
-
- "#if MAX_DIR_LIGHTS > 0",
-
- "vec3 dirDiffuse = vec3( 0.0 );",
- "vec3 dirSpecular = vec3( 0.0 );",
-
- "for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
-
- "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
- "vec3 dirVector = normalize( lDirection.xyz );",
-
- // diffuse
-
- "#ifdef WRAP_AROUND",
-
- "float directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );",
- "float directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );",
-
- "vec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );",
-
- "#else",
-
- "float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
-
- "#endif",
-
- "dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;",
-
- // specular
-
- "vec3 dirHalfVector = normalize( dirVector + viewPosition );",
- "float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
- "float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );",
-
- "#ifdef PHYSICALLY_BASED_SHADING",
-
- // 2.0 => 2.0001 is hack to work around ANGLE bug
-
- "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
-
- "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );",
- "dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
-
- "#else",
-
- "dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;",
-
- "#endif",
-
- "}",
-
- "#endif",
-
- // hemisphere lights
-
- "#if MAX_HEMI_LIGHTS > 0",
-
- "vec3 hemiDiffuse = vec3( 0.0 );",
- "vec3 hemiSpecular = vec3( 0.0 );" ,
-
- "for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
-
- "vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );",
- "vec3 lVector = normalize( lDirection.xyz );",
-
- // diffuse
-
- "float dotProduct = dot( normal, lVector );",
- "float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
-
- "vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
-
- "hemiDiffuse += uDiffuseColor * hemiColor;",
-
- // specular (sky light)
-
-
- "vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
- "float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
- "float hemiSpecularWeightSky = specularTex.r * max( pow( hemiDotNormalHalfSky, uShininess ), 0.0 );",
-
- // specular (ground light)
-
- "vec3 lVectorGround = -lVector;",
-
- "vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
- "float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
- "float hemiSpecularWeightGround = specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );",
-
- "#ifdef PHYSICALLY_BASED_SHADING",
-
- "float dotProductGround = dot( normal, lVectorGround );",
-
- // 2.0 => 2.0001 is hack to work around ANGLE bug
-
- "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
-
- "vec3 schlickSky = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );",
- "vec3 schlickGround = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );",
- "hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
-
- "#else",
-
- "hemiSpecular += uSpecularColor * hemiColor * ( hemiSpecularWeightSky + hemiSpecularWeightGround ) * hemiDiffuseWeight;",
-
- "#endif",
-
- "}",
-
- "#endif",
-
- // all lights contribution summation
-
- "vec3 totalDiffuse = vec3( 0.0 );",
- "vec3 totalSpecular = vec3( 0.0 );",
-
- "#if MAX_DIR_LIGHTS > 0",
-
- "totalDiffuse += dirDiffuse;",
- "totalSpecular += dirSpecular;",
-
- "#endif",
-
- "#if MAX_HEMI_LIGHTS > 0",
-
- "totalDiffuse += hemiDiffuse;",
- "totalSpecular += hemiSpecular;",
-
- "#endif",
-
- "#if MAX_POINT_LIGHTS > 0",
-
- "totalDiffuse += pointDiffuse;",
- "totalSpecular += pointSpecular;",
-
- "#endif",
-
- "#if MAX_SPOT_LIGHTS > 0",
-
- "totalDiffuse += spotDiffuse;",
- "totalSpecular += spotSpecular;",
-
- "#endif",
-
- "#ifdef METAL",
-
- "gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor + totalSpecular );",
-
- "#else",
-
- "gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor ) + totalSpecular;",
-
- "#endif",
-
- "if ( enableReflection ) {",
-
- "vec3 vReflect;",
- "vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );",
-
- "if ( useRefract ) {",
-
- "vReflect = refract( cameraToVertex, normal, uRefractionRatio );",
-
- "} else {",
-
- "vReflect = reflect( cameraToVertex, normal );",
-
- "}",
-
- "vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
-
- "#ifdef GAMMA_INPUT",
-
- "cubeColor.xyz *= cubeColor.xyz;",
-
- "#endif",
-
- "gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );",
-
- "}",
-
- THREE.ShaderChunk[ "shadowmap_fragment" ],
- THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
-
- "}"
-
- ].join("\n"),
-
- vertexShader: [
-
- "attribute vec4 tangent;",
-
- "uniform vec2 uOffset;",
- "uniform vec2 uRepeat;",
-
- "uniform bool enableDisplacement;",
-
- "#ifdef VERTEX_TEXTURES",
-
- "uniform sampler2D tDisplacement;",
- "uniform float uDisplacementScale;",
- "uniform float uDisplacementBias;",
-
- "#endif",
-
- "varying vec3 vTangent;",
- "varying vec3 vBinormal;",
- "varying vec3 vNormal;",
- "varying vec2 vUv;",
-
- "varying vec3 vWorldPosition;",
- "varying vec3 vViewPosition;",
-
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
-
- "void main() {",
-
- THREE.ShaderChunk[ "skinbase_vertex" ],
- THREE.ShaderChunk[ "skinnormal_vertex" ],
-
- // normal, tangent and binormal vectors
-
- "#ifdef USE_SKINNING",
-
- "vNormal = normalize( normalMatrix * skinnedNormal.xyz );",
-
- "vec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );",
- "vTangent = normalize( normalMatrix * skinnedTangent.xyz );",
-
- "#else",
-
- "vNormal = normalize( normalMatrix * normal );",
- "vTangent = normalize( normalMatrix * tangent.xyz );",
-
- "#endif",
-
- "vBinormal = normalize( cross( vNormal, vTangent ) * tangent.w );",
-
- "vUv = uv * uRepeat + uOffset;",
-
- // displacement mapping
-
- "vec3 displacedPosition;",
-
- "#ifdef VERTEX_TEXTURES",
-
- "if ( enableDisplacement ) {",
-
- "vec3 dv = texture2D( tDisplacement, uv ).xyz;",
- "float df = uDisplacementScale * dv.x + uDisplacementBias;",
- "displacedPosition = position + normalize( normal ) * df;",
-
- "} else {",
-
- "#ifdef USE_SKINNING",
-
- "vec4 skinVertex = vec4( position, 1.0 );",
-
- "vec4 skinned = boneMatX * skinVertex * skinWeight.x;",
- "skinned += boneMatY * skinVertex * skinWeight.y;",
-
- "displacedPosition = skinned.xyz;",
-
- "#else",
-
- "displacedPosition = position;",
-
- "#endif",
-
- "}",
-
- "#else",
-
- "#ifdef USE_SKINNING",
-
- "vec4 skinVertex = vec4( position, 1.0 );",
-
- "vec4 skinned = boneMatX * skinVertex * skinWeight.x;",
- "skinned += boneMatY * skinVertex * skinWeight.y;",
-
- "displacedPosition = skinned.xyz;",
-
- "#else",
-
- "displacedPosition = position;",
-
- "#endif",
-
- "#endif",
-
- //
-
- "vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );",
- "vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );",
-
- "gl_Position = projectionMatrix * mvPosition;",
-
- //
-
- "vWorldPosition = worldPosition.xyz;",
- "vViewPosition = -mvPosition.xyz;",
-
- // shadows
-
- "#ifdef USE_SHADOWMAP",
-
- "for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
-
- "vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;",
-
- "}",
-
- "#endif",
-
- "}"
-
- ].join("\n")
-
- },
-
- /* -------------------------------------------------------------------------
- // Cube map shader
- ------------------------------------------------------------------------- */
-
- 'cube': {
-
- uniforms: { "tCube": { type: "t", value: null },
- "tFlip": { type: "f", value: -1 } },
-
- vertexShader: [
-
- "varying vec3 vWorldPosition;",
-
- "void main() {",
-
- "vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
- "vWorldPosition = worldPosition.xyz;",
-
- "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
-
- "}"
-
- ].join("\n"),
-
- fragmentShader: [
-
- "uniform samplerCube tCube;",
- "uniform float tFlip;",
-
- "varying vec3 vWorldPosition;",
-
- "void main() {",
-
- "gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
-
- "}"
-
- ].join("\n")
-
- }
-
- }
-
-};
diff --git a/src/loaders/Loader.js b/src/loaders/Loader.js
index e574015ece2376c615f60d4d78fdfd6f2d942dc2..9a322330fccc691d48b1ffeb6e10ba1c008a591e 100644
--- a/src/loaders/Loader.js
+++ b/src/loaders/Loader.js
@@ -371,7 +371,7 @@ THREE.Loader.prototype = {
if ( m.mapNormal ) {
- var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var shader = THREE.ShaderLib[ "normal2" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "tNormal" ].value = mpars.normalMap;
diff --git a/src/loaders/SceneLoader.js b/src/loaders/SceneLoader.js
index e6df506418826593fc7f6bc64385127f14e9c72a..ab7c04f2b55489f1b654fca884660b2c9aa42cc1 100644
--- a/src/loaders/SceneLoader.js
+++ b/src/loaders/SceneLoader.js
@@ -1048,7 +1048,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( matJSON.parameters.normalMap ) {
- var shader = THREE.ShaderUtils.lib[ "normal" ];
+ var shader = THREE.ShaderLib[ "normal2" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
var diffuse = matJSON.parameters.color;
diff --git a/src/renderers/WebGLShaders.js b/src/renderers/WebGLShaders.js
index 8de725d40ca4d3bd32a18a49175ef094269dc2c7..54af0240fd7b5d9d777a777f74ea537828237759 100644
--- a/src/renderers/WebGLShaders.js
+++ b/src/renderers/WebGLShaders.js
@@ -2474,6 +2474,764 @@ THREE.ShaderLib = {
},
+ /* -------------------------------------------------------------------------
+ // Normal map shader
+ // - Blinn-Phong
+ // - normal + diffuse + specular + AO + displacement + reflection + shadow maps
+ // - point and directional lights (use with "lights: true" material option)
+ ------------------------------------------------------------------------- */
+
+ 'normal2' : {
+
+ uniforms: THREE.UniformsUtils.merge( [
+
+ THREE.UniformsLib[ "fog" ],
+ THREE.UniformsLib[ "lights" ],
+ THREE.UniformsLib[ "shadowmap" ],
+
+ {
+
+ "enableAO" : { type: "i", value: 0 },
+ "enableDiffuse" : { type: "i", value: 0 },
+ "enableSpecular" : { type: "i", value: 0 },
+ "enableReflection": { type: "i", value: 0 },
+ "enableDisplacement": { type: "i", value: 0 },
+
+ "tDisplacement": { type: "t", value: null }, // must go first as this is vertex texture
+ "tDiffuse" : { type: "t", value: null },
+ "tCube" : { type: "t", value: null },
+ "tNormal" : { type: "t", value: null },
+ "tSpecular" : { type: "t", value: null },
+ "tAO" : { type: "t", value: null },
+
+ "uNormalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) },
+
+ "uDisplacementBias": { type: "f", value: 0.0 },
+ "uDisplacementScale": { type: "f", value: 1.0 },
+
+ "uDiffuseColor": { type: "c", value: new THREE.Color( 0xffffff ) },
+ "uSpecularColor": { type: "c", value: new THREE.Color( 0x111111 ) },
+ "uAmbientColor": { type: "c", value: new THREE.Color( 0xffffff ) },
+ "uShininess": { type: "f", value: 30 },
+ "uOpacity": { type: "f", value: 1 },
+
+ "useRefract": { type: "i", value: 0 },
+ "uRefractionRatio": { type: "f", value: 0.98 },
+ "uReflectivity": { type: "f", value: 0.5 },
+
+ "uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) },
+ "uRepeat" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
+
+ "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
+
+ }
+
+ ] ),
+
+ fragmentShader: [
+
+ "uniform vec3 uAmbientColor;",
+ "uniform vec3 uDiffuseColor;",
+ "uniform vec3 uSpecularColor;",
+ "uniform float uShininess;",
+ "uniform float uOpacity;",
+
+ "uniform bool enableDiffuse;",
+ "uniform bool enableSpecular;",
+ "uniform bool enableAO;",
+ "uniform bool enableReflection;",
+
+ "uniform sampler2D tDiffuse;",
+ "uniform sampler2D tNormal;",
+ "uniform sampler2D tSpecular;",
+ "uniform sampler2D tAO;",
+
+ "uniform samplerCube tCube;",
+
+ "uniform vec2 uNormalScale;",
+
+ "uniform bool useRefract;",
+ "uniform float uRefractionRatio;",
+ "uniform float uReflectivity;",
+
+ "varying vec3 vTangent;",
+ "varying vec3 vBinormal;",
+ "varying vec3 vNormal;",
+ "varying vec2 vUv;",
+
+ "uniform vec3 ambientLightColor;",
+
+ "#if MAX_DIR_LIGHTS > 0",
+
+ "uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
+ "uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
+
+ "#endif",
+
+ "#if MAX_HEMI_LIGHTS > 0",
+
+ "uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];",
+ "uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];",
+ "uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];",
+
+ "#endif",
+
+ "#if MAX_POINT_LIGHTS > 0",
+
+ "uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
+ "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
+ "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
+
+ "#endif",
+
+ "#if MAX_SPOT_LIGHTS > 0",
+
+ "uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
+ "uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
+ "uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
+ "uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];",
+ "uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
+ "uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
+
+ "#endif",
+
+ "#ifdef WRAP_AROUND",
+
+ "uniform vec3 wrapRGB;",
+
+ "#endif",
+
+ "varying vec3 vWorldPosition;",
+ "varying vec3 vViewPosition;",
+
+ THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
+ THREE.ShaderChunk[ "fog_pars_fragment" ],
+
+ "void main() {",
+
+ "gl_FragColor = vec4( vec3( 1.0 ), uOpacity );",
+
+ "vec3 specularTex = vec3( 1.0 );",
+
+ "vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;",
+ "normalTex.xy *= uNormalScale;",
+ "normalTex = normalize( normalTex );",
+
+ "if( enableDiffuse ) {",
+
+ "#ifdef GAMMA_INPUT",
+
+ "vec4 texelColor = texture2D( tDiffuse, vUv );",
+ "texelColor.xyz *= texelColor.xyz;",
+
+ "gl_FragColor = gl_FragColor * texelColor;",
+
+ "#else",
+
+ "gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );",
+
+ "#endif",
+
+ "}",
+
+ "if( enableAO ) {",
+
+ "#ifdef GAMMA_INPUT",
+
+ "vec4 aoColor = texture2D( tAO, vUv );",
+ "aoColor.xyz *= aoColor.xyz;",
+
+ "gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;",
+
+ "#else",
+
+ "gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;",
+
+ "#endif",
+
+ "}",
+
+ "if( enableSpecular )",
+ "specularTex = texture2D( tSpecular, vUv ).xyz;",
+
+ "mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );",
+ "vec3 finalNormal = tsb * normalTex;",
+
+ "#ifdef FLIP_SIDED",
+
+ "finalNormal = -finalNormal;",
+
+ "#endif",
+
+ "vec3 normal = normalize( finalNormal );",
+ "vec3 viewPosition = normalize( vViewPosition );",
+
+ // point lights
+
+ "#if MAX_POINT_LIGHTS > 0",
+
+ "vec3 pointDiffuse = vec3( 0.0 );",
+ "vec3 pointSpecular = vec3( 0.0 );",
+
+ "for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
+
+ "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
+ "vec3 pointVector = lPosition.xyz + vViewPosition.xyz;",
+
+ "float pointDistance = 1.0;",
+ "if ( pointLightDistance[ i ] > 0.0 )",
+ "pointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );",
+
+ "pointVector = normalize( pointVector );",
+
+ // diffuse
+
+ "#ifdef WRAP_AROUND",
+
+ "float pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );",
+ "float pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );",
+
+ "vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
+
+ "#else",
+
+ "float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
+
+ "#endif",
+
+ "pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;",
+
+ // specular
+
+ "vec3 pointHalfVector = normalize( pointVector + viewPosition );",
+ "float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
+ "float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );",
+
+ "#ifdef PHYSICALLY_BASED_SHADING",
+
+ // 2.0 => 2.0001 is hack to work around ANGLE bug
+
+ "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
+
+ "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );",
+ "pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
+
+ "#else",
+
+ "pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;",
+
+ "#endif",
+
+ "}",
+
+ "#endif",
+
+ // spot lights
+
+ "#if MAX_SPOT_LIGHTS > 0",
+
+ "vec3 spotDiffuse = vec3( 0.0 );",
+ "vec3 spotSpecular = vec3( 0.0 );",
+
+ "for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
+
+ "vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
+ "vec3 spotVector = lPosition.xyz + vViewPosition.xyz;",
+
+ "float spotDistance = 1.0;",
+ "if ( spotLightDistance[ i ] > 0.0 )",
+ "spotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );",
+
+ "spotVector = normalize( spotVector );",
+
+ "float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );",
+
+ "if ( spotEffect > spotLightAngleCos[ i ] ) {",
+
+ "spotEffect = max( pow( spotEffect, spotLightExponent[ i ] ), 0.0 );",
+
+ // diffuse
+
+ "#ifdef WRAP_AROUND",
+
+ "float spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );",
+ "float spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );",
+
+ "vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );",
+
+ "#else",
+
+ "float spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );",
+
+ "#endif",
+
+ "spotDiffuse += spotDistance * spotLightColor[ i ] * uDiffuseColor * spotDiffuseWeight * spotEffect;",
+
+ // specular
+
+ "vec3 spotHalfVector = normalize( spotVector + viewPosition );",
+ "float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );",
+ "float spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, uShininess ), 0.0 );",
+
+ "#ifdef PHYSICALLY_BASED_SHADING",
+
+ // 2.0 => 2.0001 is hack to work around ANGLE bug
+
+ "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
+
+ "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( spotVector, spotHalfVector ), 5.0 );",
+ "spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;",
+
+ "#else",
+
+ "spotSpecular += spotDistance * spotLightColor[ i ] * uSpecularColor * spotSpecularWeight * spotDiffuseWeight * spotEffect;",
+
+ "#endif",
+
+ "}",
+
+ "}",
+
+ "#endif",
+
+ // directional lights
+
+ "#if MAX_DIR_LIGHTS > 0",
+
+ "vec3 dirDiffuse = vec3( 0.0 );",
+ "vec3 dirSpecular = vec3( 0.0 );",
+
+ "for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
+
+ "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
+ "vec3 dirVector = normalize( lDirection.xyz );",
+
+ // diffuse
+
+ "#ifdef WRAP_AROUND",
+
+ "float directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );",
+ "float directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );",
+
+ "vec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );",
+
+ "#else",
+
+ "float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
+
+ "#endif",
+
+ "dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;",
+
+ // specular
+
+ "vec3 dirHalfVector = normalize( dirVector + viewPosition );",
+ "float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
+ "float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );",
+
+ "#ifdef PHYSICALLY_BASED_SHADING",
+
+ // 2.0 => 2.0001 is hack to work around ANGLE bug
+
+ "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
+
+ "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );",
+ "dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
+
+ "#else",
+
+ "dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;",
+
+ "#endif",
+
+ "}",
+
+ "#endif",
+
+ // hemisphere lights
+
+ "#if MAX_HEMI_LIGHTS > 0",
+
+ "vec3 hemiDiffuse = vec3( 0.0 );",
+ "vec3 hemiSpecular = vec3( 0.0 );" ,
+
+ "for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
+
+ "vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );",
+ "vec3 lVector = normalize( lDirection.xyz );",
+
+ // diffuse
+
+ "float dotProduct = dot( normal, lVector );",
+ "float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
+
+ "vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
+
+ "hemiDiffuse += uDiffuseColor * hemiColor;",
+
+ // specular (sky light)
+
+
+ "vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
+ "float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
+ "float hemiSpecularWeightSky = specularTex.r * max( pow( hemiDotNormalHalfSky, uShininess ), 0.0 );",
+
+ // specular (ground light)
+
+ "vec3 lVectorGround = -lVector;",
+
+ "vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
+ "float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
+ "float hemiSpecularWeightGround = specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );",
+
+ "#ifdef PHYSICALLY_BASED_SHADING",
+
+ "float dotProductGround = dot( normal, lVectorGround );",
+
+ // 2.0 => 2.0001 is hack to work around ANGLE bug
+
+ "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
+
+ "vec3 schlickSky = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );",
+ "vec3 schlickGround = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );",
+ "hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
+
+ "#else",
+
+ "hemiSpecular += uSpecularColor * hemiColor * ( hemiSpecularWeightSky + hemiSpecularWeightGround ) * hemiDiffuseWeight;",
+
+ "#endif",
+
+ "}",
+
+ "#endif",
+
+ // all lights contribution summation
+
+ "vec3 totalDiffuse = vec3( 0.0 );",
+ "vec3 totalSpecular = vec3( 0.0 );",
+
+ "#if MAX_DIR_LIGHTS > 0",
+
+ "totalDiffuse += dirDiffuse;",
+ "totalSpecular += dirSpecular;",
+
+ "#endif",
+
+ "#if MAX_HEMI_LIGHTS > 0",
+
+ "totalDiffuse += hemiDiffuse;",
+ "totalSpecular += hemiSpecular;",
+
+ "#endif",
+
+ "#if MAX_POINT_LIGHTS > 0",
+
+ "totalDiffuse += pointDiffuse;",
+ "totalSpecular += pointSpecular;",
+
+ "#endif",
+
+ "#if MAX_SPOT_LIGHTS > 0",
+
+ "totalDiffuse += spotDiffuse;",
+ "totalSpecular += spotSpecular;",
+
+ "#endif",
+
+ "#ifdef METAL",
+
+ "gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor + totalSpecular );",
+
+ "#else",
+
+ "gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor ) + totalSpecular;",
+
+ "#endif",
+
+ "if ( enableReflection ) {",
+
+ "vec3 vReflect;",
+ "vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );",
+
+ "if ( useRefract ) {",
+
+ "vReflect = refract( cameraToVertex, normal, uRefractionRatio );",
+
+ "} else {",
+
+ "vReflect = reflect( cameraToVertex, normal );",
+
+ "}",
+
+ "vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
+
+ "#ifdef GAMMA_INPUT",
+
+ "cubeColor.xyz *= cubeColor.xyz;",
+
+ "#endif",
+
+ "gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );",
+
+ "}",
+
+ THREE.ShaderChunk[ "shadowmap_fragment" ],
+ THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
+ THREE.ShaderChunk[ "fog_fragment" ],
+
+ "}"
+
+ ].join("\n"),
+
+ vertexShader: [
+
+ "attribute vec4 tangent;",
+
+ "uniform vec2 uOffset;",
+ "uniform vec2 uRepeat;",
+
+ "uniform bool enableDisplacement;",
+
+ "#ifdef VERTEX_TEXTURES",
+
+ "uniform sampler2D tDisplacement;",
+ "uniform float uDisplacementScale;",
+ "uniform float uDisplacementBias;",
+
+ "#endif",
+
+ "varying vec3 vTangent;",
+ "varying vec3 vBinormal;",
+ "varying vec3 vNormal;",
+ "varying vec2 vUv;",
+
+ "varying vec3 vWorldPosition;",
+ "varying vec3 vViewPosition;",
+
+ THREE.ShaderChunk[ "skinning_pars_vertex" ],
+ THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
+
+ "void main() {",
+
+ THREE.ShaderChunk[ "skinbase_vertex" ],
+ THREE.ShaderChunk[ "skinnormal_vertex" ],
+
+ // normal, tangent and binormal vectors
+
+ "#ifdef USE_SKINNING",
+
+ "vNormal = normalize( normalMatrix * skinnedNormal.xyz );",
+
+ "vec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );",
+ "vTangent = normalize( normalMatrix * skinnedTangent.xyz );",
+
+ "#else",
+
+ "vNormal = normalize( normalMatrix * normal );",
+ "vTangent = normalize( normalMatrix * tangent.xyz );",
+
+ "#endif",
+
+ "vBinormal = normalize( cross( vNormal, vTangent ) * tangent.w );",
+
+ "vUv = uv * uRepeat + uOffset;",
+
+ // displacement mapping
+
+ "vec3 displacedPosition;",
+
+ "#ifdef VERTEX_TEXTURES",
+
+ "if ( enableDisplacement ) {",
+
+ "vec3 dv = texture2D( tDisplacement, uv ).xyz;",
+ "float df = uDisplacementScale * dv.x + uDisplacementBias;",
+ "displacedPosition = position + normalize( normal ) * df;",
+
+ "} else {",
+
+ "#ifdef USE_SKINNING",
+
+ "vec4 skinVertex = vec4( position, 1.0 );",
+
+ "vec4 skinned = boneMatX * skinVertex * skinWeight.x;",
+ "skinned += boneMatY * skinVertex * skinWeight.y;",
+
+ "displacedPosition = skinned.xyz;",
+
+ "#else",
+
+ "displacedPosition = position;",
+
+ "#endif",
+
+ "}",
+
+ "#else",
+
+ "#ifdef USE_SKINNING",
+
+ "vec4 skinVertex = vec4( position, 1.0 );",
+
+ "vec4 skinned = boneMatX * skinVertex * skinWeight.x;",
+ "skinned += boneMatY * skinVertex * skinWeight.y;",
+
+ "displacedPosition = skinned.xyz;",
+
+ "#else",
+
+ "displacedPosition = position;",
+
+ "#endif",
+
+ "#endif",
+
+ //
+
+ "vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );",
+ "vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );",
+
+ "gl_Position = projectionMatrix * mvPosition;",
+
+ //
+
+ "vWorldPosition = worldPosition.xyz;",
+ "vViewPosition = -mvPosition.xyz;",
+
+ // shadows
+
+ "#ifdef USE_SHADOWMAP",
+
+ "for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
+
+ "vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;",
+
+ "}",
+
+ "#endif",
+
+ "}"
+
+ ].join("\n")
+
+ },
+
+ /* -------------------------------------------------------------------------
+ // Cube map shader
+ ------------------------------------------------------------------------- */
+
+ 'cube': {
+
+ uniforms: { "tCube": { type: "t", value: null },
+ "tFlip": { type: "f", value: -1 } },
+
+ vertexShader: [
+
+ "varying vec3 vWorldPosition;",
+
+ "void main() {",
+
+ "vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
+ "vWorldPosition = worldPosition.xyz;",
+
+ "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
+
+ "}"
+
+ ].join("\n"),
+
+ fragmentShader: [
+
+ "uniform samplerCube tCube;",
+ "uniform float tFlip;",
+
+ "varying vec3 vWorldPosition;",
+
+ "void main() {",
+
+ "gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
+
+ "}"
+
+ ].join("\n")
+
+ },
+
+ /* -------------------------------------------------------------------------
+ // Fresnel shader
+ // - based on Nvidia Cg tutorial
+ ------------------------------------------------------------------------- */
+
+ 'fresnel': {
+
+ uniforms: {
+
+ "mRefractionRatio": { type: "f", value: 1.02 },
+ "mFresnelBias": { type: "f", value: 0.1 },
+ "mFresnelPower": { type: "f", value: 2.0 },
+ "mFresnelScale": { type: "f", value: 1.0 },
+ "tCube": { type: "t", value: null }
+
+ },
+
+ fragmentShader: [
+
+ "uniform samplerCube tCube;",
+
+ "varying vec3 vReflect;",
+ "varying vec3 vRefract[3];",
+ "varying float vReflectionFactor;",
+
+ "void main() {",
+
+ "vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
+ "vec4 refractedColor = vec4( 1.0 );",
+
+ "refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;",
+ "refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;",
+ "refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;",
+
+ "gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );",
+
+ "}"
+
+ ].join("\n"),
+
+ vertexShader: [
+
+ "uniform float mRefractionRatio;",
+ "uniform float mFresnelBias;",
+ "uniform float mFresnelScale;",
+ "uniform float mFresnelPower;",
+
+ "varying vec3 vReflect;",
+ "varying vec3 vRefract[3];",
+ "varying float vReflectionFactor;",
+
+ "void main() {",
+
+ "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
+ "vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
+
+ "vec3 worldNormal = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
+
+ "vec3 I = worldPosition.xyz - cameraPosition;",
+
+ "vReflect = reflect( I, worldNormal );",
+ "vRefract[0] = refract( normalize( I ), worldNormal, mRefractionRatio );",
+ "vRefract[1] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.99 );",
+ "vRefract[2] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.98 );",
+ "vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), worldNormal ), mFresnelPower );",
+
+ "gl_Position = projectionMatrix * mvPosition;",
+
+ "}"
+
+ ].join("\n")
+
+ },
+
// Depth encoding into RGBA texture
// based on SpiderGL shadow map example
// http://spidergl.org/example.php?id=6
diff --git a/utils/includes/extras.json b/utils/includes/extras.json
index abe0c621b96a574cbcd60cce533a16c6f90cdcfe..6dfcde3c1ea9e6569daa6756a250cc925f73bf3b 100644
--- a/utils/includes/extras.json
+++ b/utils/includes/extras.json
@@ -3,7 +3,6 @@
"../src/extras/GeometryUtils.js",
"../src/extras/ImageUtils.js",
"../src/extras/SceneUtils.js",
- "../src/extras/ShaderUtils.js",
"../src/extras/FontUtils.js",
"../src/extras/core/Curve.js",
"../src/extras/core/CurvePath.js",