1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204 |
- /**
- * @author alteredq / http://alteredqualia.com/
- * @author mrdoob / http://mrdoob.com/
- * @author mikael emtinger / http://gomo.se/
- */
- THREE.ShaderChunk = {
- // FOG
- fog_pars_fragment: [
- "#ifdef USE_FOG",
- "uniform vec3 fogColor;",
- "#ifdef FOG_EXP2",
- "uniform float fogDensity;",
- "#else",
- "uniform float fogNear;",
- "uniform float fogFar;",
- "#endif",
- "#endif"
- ].join("\n"),
- fog_fragment: [
- "#ifdef USE_FOG",
- "float depth = gl_FragCoord.z / gl_FragCoord.w;",
- "#ifdef FOG_EXP2",
- "const float LOG2 = 1.442695;",
- "float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );",
- "fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );",
- "#else",
- "float fogFactor = smoothstep( fogNear, fogFar, depth );",
- "#endif",
- "gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );",
- "#endif"
- ].join("\n"),
- // ENVIRONMENT MAP
- envmap_pars_fragment: [
- "#ifdef USE_ENVMAP",
- "varying vec3 vReflect;",
- "uniform float reflectivity;",
- "uniform samplerCube envMap;",
- "uniform int combine;",
- "#endif"
- ].join("\n"),
- envmap_fragment: [
- "#ifdef USE_ENVMAP",
- "vec4 cubeColor = textureCube( envMap, vec3( -vReflect.x, vReflect.yz ) );",
- "if ( combine == 1 ) {",
- //"gl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );",
- "gl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );",
- "} else {",
- "gl_FragColor = gl_FragColor * cubeColor;",
- "}",
- "#endif"
- ].join("\n"),
- envmap_pars_vertex: [
- "#ifdef USE_ENVMAP",
- "varying vec3 vReflect;",
- "uniform float refractionRatio;",
- "uniform bool useRefract;",
- "#endif"
- ].join("\n"),
- envmap_vertex : [
- "#ifdef USE_ENVMAP",
- "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
- "vec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;",
- "if ( useRefract ) {",
- "vReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );",
- "} else {",
- "vReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );",
- "}",
- "#endif"
- ].join("\n"),
- // COLOR MAP (particles)
- map_particle_pars_fragment: [
- "#ifdef USE_MAP",
- "uniform sampler2D map;",
- "#endif"
- ].join("\n"),
- map_particle_fragment: [
- "#ifdef USE_MAP",
- "gl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );",
- "#endif"
- ].join("\n"),
- // COLOR MAP (triangles)
- map_pars_fragment: [
- "#ifdef USE_MAP",
- "varying vec2 vUv;",
- "uniform sampler2D map;",
- "#endif"
- ].join("\n"),
- map_pars_vertex: [
- "#ifdef USE_MAP",
- "varying vec2 vUv;",
- "#endif"
- ].join("\n"),
- map_fragment: [
- "#ifdef USE_MAP",
- "gl_FragColor = gl_FragColor * texture2D( map, vUv );",
- "#endif"
- ].join("\n"),
- map_vertex: [
- "#ifdef USE_MAP",
- "vUv = uv;",
- "#endif"
- ].join("\n"),
- // LIGHT MAP
- lightmap_pars_fragment: [
- "#ifdef USE_LIGHTMAP",
- "varying vec2 vUv2;",
- "uniform sampler2D lightMap;",
- "#endif"
- ].join("\n"),
- lightmap_pars_vertex: [
- "#ifdef USE_LIGHTMAP",
- "varying vec2 vUv2;",
- "#endif"
- ].join("\n"),
- lightmap_fragment: [
- "#ifdef USE_LIGHTMAP",
- "gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );",
- "#endif"
- ].join("\n"),
- lightmap_vertex: [
- "#ifdef USE_LIGHTMAP",
- "vUv2 = uv2;",
- "#endif"
- ].join("\n"),
- lights_pars_vertex: [
- "uniform bool enableLighting;",
- "uniform vec3 ambientLightColor;",
- "#if MAX_DIR_LIGHTS > 0",
- "uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
- "uniform vec3 directionalLightDirection[ MAX_DIR_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 ];",
- "#ifdef PHONG",
- "varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
- "#endif",
- "#endif"
- ].join("\n"),
- // LIGHTS
- lights_vertex: [
- "if ( !enableLighting ) {",
- "vLightWeighting = vec3( 1.0 );",
- "} else {",
- "vLightWeighting = ambientLightColor;",
- "#if MAX_DIR_LIGHTS > 0",
- "for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
- "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
- "float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );",
- "vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;",
- "}",
- "#endif",
- "#if MAX_POINT_LIGHTS > 0",
- "for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {",
- "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
- "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
- "float lDistance = 1.0;",
- "if ( pointLightDistance[ i ] > 0.0 )",
- "lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
- "lVector = normalize( lVector );",
- "float pointLightWeighting = max( dot( transformedNormal, lVector ), 0.0 );",
- "vLightWeighting += pointLightColor[ i ] * pointLightWeighting * lDistance;",
- "#ifdef PHONG",
- "vPointLight[ i ] = vec4( lVector, lDistance );",
- "#endif",
- "}",
- "#endif",
- "}"
- ].join("\n"),
- lights_pars_fragment: [
- "#if MAX_DIR_LIGHTS > 0",
- "uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
- "#endif",
- "#if MAX_POINT_LIGHTS > 0",
- "varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
- "#endif",
- "varying vec3 vViewPosition;",
- "varying vec3 vNormal;"
- ].join("\n"),
- lights_fragment: [
- "vec3 normal = normalize( vNormal );",
- "vec3 viewPosition = normalize( vViewPosition );",
- "vec4 mColor = vec4( diffuse, opacity );",
- "vec4 mSpecular = vec4( specular, opacity );",
- "#if MAX_POINT_LIGHTS > 0",
- "vec4 pointDiffuse = vec4( 0.0 );",
- "vec4 pointSpecular = vec4( 0.0 );",
- "for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
- "vec3 pointVector = normalize( vPointLight[ i ].xyz );",
- "vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + vViewPosition );",
- "float pointDistance = vPointLight[ i ].w;",
- "float pointDotNormalHalf = dot( normal, pointHalfVector );",
- "float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
- "float pointSpecularWeight = 0.0;",
- "if ( pointDotNormalHalf >= 0.0 )",
- "pointSpecularWeight = pow( pointDotNormalHalf, shininess );",
- "pointDiffuse += mColor * pointDiffuseWeight * pointDistance;",
- "pointSpecular += mSpecular * pointSpecularWeight * pointDistance;",
- "}",
- "#endif",
- "#if MAX_DIR_LIGHTS > 0",
- "vec4 dirDiffuse = vec4( 0.0 );",
- "vec4 dirSpecular = vec4( 0.0 );" ,
- "for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
- "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
- "vec3 dirVector = normalize( lDirection.xyz );",
- "vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );",
- "float dirDotNormalHalf = dot( normal, dirHalfVector );",
- "float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
- "float dirSpecularWeight = 0.0;",
- "if ( dirDotNormalHalf >= 0.0 )",
- "dirSpecularWeight = pow( dirDotNormalHalf, shininess );",
- "dirDiffuse += mColor * dirDiffuseWeight;",
- "dirSpecular += mSpecular * dirSpecularWeight;",
- "}",
- "#endif",
- "vec4 totalLight = vec4( ambient, opacity );",
- "#if MAX_DIR_LIGHTS > 0",
- "totalLight += dirDiffuse + dirSpecular;",
- "#endif",
- "#if MAX_POINT_LIGHTS > 0",
- "totalLight += pointDiffuse + pointSpecular;",
- "#endif",
- "gl_FragColor = gl_FragColor * totalLight;"
- ].join("\n"),
- // VERTEX COLORS
- color_pars_fragment: [
- "#ifdef USE_COLOR",
- "varying vec3 vColor;",
- "#endif"
- ].join("\n"),
- color_fragment: [
- "#ifdef USE_COLOR",
- "gl_FragColor = gl_FragColor * vec4( vColor, opacity );",
- "#endif"
- ].join("\n"),
- color_pars_vertex: [
- "#ifdef USE_COLOR",
- "varying vec3 vColor;",
- "#endif"
- ].join("\n"),
- color_vertex: [
- "#ifdef USE_COLOR",
- "vColor = color;",
- "#endif"
- ].join("\n"),
- // skinning
- skinning_pars_vertex: [
- "#ifdef USE_SKINNING",
- "uniform mat4 boneGlobalMatrices[ MAX_BONES ];",
- "#endif"
- ].join("\n"),
- skinning_vertex: [
- "#ifdef USE_SKINNING",
- "gl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;",
- "gl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;",
- // this doesn't work, no idea why
- //"gl_Position = projectionMatrix * cameraInverseMatrix * objectMatrix * gl_Position;",
- "gl_Position = projectionMatrix * viewMatrix * objectMatrix * gl_Position;",
- "#endif"
- ].join("\n"),
- // morphing
- morphtarget_pars_vertex: [
- "#ifdef USE_MORPHTARGETS",
- "uniform float morphTargetInfluences[ 8 ];",
- "#endif"
- ].join("\n"),
- morphtarget_vertex: [
- "#ifdef USE_MORPHTARGETS",
- "vec3 morphed = vec3( 0.0, 0.0, 0.0 );",
- "morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];",
- "morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];",
- "morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];",
- "morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];",
- "morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];",
- "morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];",
- "morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];",
- "morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];",
- "morphed += position;",
- "gl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );",
- "#endif"
- ].join("\n"),
- default_vertex : [
- "#ifndef USE_MORPHTARGETS",
- "#ifndef USE_SKINNING",
- "gl_Position = projectionMatrix * mvPosition;",
- "#endif",
- "#endif"
- ].join("\n")
- };
- THREE.UniformsLib = {
- common: {
- "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
- "opacity" : { type: "f", value: 1.0 },
- "map" : { type: "t", value: 0, texture: null },
- "lightMap" : { type: "t", value: 2, texture: null },
- "envMap" : { type: "t", value: 1, texture: null },
- "useRefract" : { type: "i", value: 0 },
- "reflectivity" : { type: "f", value: 1.0 },
- "refractionRatio" : { type: "f", value: 0.98 },
- "combine" : { type: "i", value: 0 },
- "fogDensity" : { type: "f", value: 0.00025 },
- "fogNear" : { type: "f", value: 1 },
- "fogFar" : { type: "f", value: 2000 },
- "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) },
- "morphTargetInfluences" : { type: "f", value: 0 }
- },
- lights: {
- "enableLighting" : { type: "i", value: 1 },
- "ambientLightColor" : { type: "fv", value: [] },
- "directionalLightDirection" : { type: "fv", value: [] },
- "directionalLightColor" : { type: "fv", value: [] },
- "pointLightColor" : { type: "fv", value: [] },
- "pointLightPosition" : { type: "fv", value: [] },
- "pointLightDistance" : { type: "fv1", value: [] }
- },
- particle: {
- "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
- "opacity" : { type: "f", value: 1.0 },
- "size" : { type: "f", value: 1.0 },
- "scale" : { type: "f", value: 1.0 },
- "map" : { type: "t", value: 0, texture: null },
- "fogDensity" : { type: "f", value: 0.00025 },
- "fogNear" : { type: "f", value: 1 },
- "fogFar" : { type: "f", value: 2000 },
- "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
- }
- };
- THREE.ShaderLib = {
- 'lensFlareVertexTexture': {
-
- vertexShader: [
- "uniform vec3 screenPosition;",
- "uniform vec2 scale;",
- "uniform float rotation;",
- "uniform int renderType;",
- "uniform sampler2D occlusionMap;",
- "attribute vec2 position;",
- "attribute vec2 UV;",
- "varying vec2 vUV;",
- "varying float vVisibility;",
-
- "void main(void)",
- "{",
- "vUV = UV;",
- "vec2 pos = position;",
-
- "if( renderType == 2 ) {",
- "float visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 )).a +",
- "texture2D( occlusionMap, vec2( 0.5, 0.1 )).a +",
- "texture2D( occlusionMap, vec2( 0.9, 0.1 )).a +",
- "texture2D( occlusionMap, vec2( 0.9, 0.5 )).a +",
- "texture2D( occlusionMap, vec2( 0.9, 0.9 )).a +",
- "texture2D( occlusionMap, vec2( 0.5, 0.9 )).a +",
- "texture2D( occlusionMap, vec2( 0.1, 0.9 )).a +",
- "texture2D( occlusionMap, vec2( 0.1, 0.5 )).a +",
- "texture2D( occlusionMap, vec2( 0.5, 0.5 )).a;",
- "vVisibility = ( 1.0 - visibility / 9.0 );",
- "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
- "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
- "}",
-
- "gl_Position = vec4(( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
- "}"
- ].join( "\n" ),
-
- fragmentShader: [
-
- "#ifdef GL_ES",
- "precision highp float;",
- "#endif",
- "uniform sampler2D map;",
- "uniform float opacity;",
- "uniform int renderType;",
-
- "varying vec2 vUV;",
- "varying float vVisibility;",
-
- "void main( void )",
- "{",
- // pink square
-
- "if( renderType == 0 ) {",
-
- "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
- // "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
-
- // restore
-
- "} else if( renderType == 1 ) {",
- "gl_FragColor = texture2D( map, vUV );",
-
- // flare
-
- "} else {",
-
- "vec4 color = texture2D( map, vUV );",
- "color.a *= opacity * vVisibility;",
- "gl_FragColor = color;",
- "}",
- "}"
- ].join( "\n" )
- },
- 'lensFlare': {
-
- vertexShader: [
- "uniform vec3 screenPosition;",
- "uniform vec2 scale;",
- "uniform float rotation;",
- "uniform int renderType;",
- "attribute vec2 position;",
- "attribute vec2 UV;",
- "varying vec2 vUV;",
-
- "void main(void)",
- "{",
- "vUV = UV;",
- "vec2 pos = position;",
-
- "if( renderType == 2 ) {",
- "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
- "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
- "}",
-
- "gl_Position = vec4(( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
- "}"
- ].join( "\n" ),
-
- fragmentShader: [
-
- "#ifdef GL_ES",
- "precision highp float;",
- "#endif",
- "uniform sampler2D map;",
- "uniform sampler2D occlusionMap;",
- "uniform float opacity;",
- "uniform int renderType;",
-
- "varying vec2 vUV;",
-
- "void main( void )",
- "{",
- // pink square
-
- "if( renderType == 0 ) {",
-
- "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
-
- // restore
-
- "} else if( renderType == 1 ) {",
- "gl_FragColor = texture2D( map, vUV );",
-
- // flare
-
- "} else {",
- "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 )).a +",
- "texture2D( occlusionMap, vec2( 0.9, 0.5 )).a +",
- "texture2D( occlusionMap, vec2( 0.5, 0.9 )).a +",
- "texture2D( occlusionMap, vec2( 0.1, 0.5 )).a;",
-
- "visibility = ( 1.0 - visibility / 4.0 );",
- "vec4 color = texture2D( map, vUV );",
- "color.a *= opacity * visibility;",
- "gl_FragColor = color;",
- "}",
- "}"
- ].join( "\n" )
- },
- 'sprite': {
-
- vertexShader: [
- "uniform int useScreenCoordinates;",
- "uniform int affectedByDistance;",
- "uniform vec3 screenPosition;",
- "uniform mat4 modelViewMatrix;",
- "uniform mat4 projectionMatrix;",
- "uniform float rotation;",
- "uniform vec2 scale;",
- "uniform vec2 alignment;",
- "uniform vec2 uvOffset;",
- "uniform vec2 uvScale;",
- "attribute vec2 position;",
- "attribute vec2 uv;",
- "varying vec2 vUV;",
-
- "void main(void)",
- "{",
- "vUV = uvOffset + uv * uvScale;",
- "vec2 alignedPosition = position + alignment;",
-
- "vec2 rotatedPosition;",
- "rotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;",
- "rotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;",
- "vec4 finalPosition;",
-
- "if( useScreenCoordinates != 0 ) {",
-
- "finalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );",
-
- "} else {",
-
- "finalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );",
- "finalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );",
- "}",
- "gl_Position = finalPosition;",
- "}"
- ].join( "\n" ),
-
- fragmentShader: [
-
- "#ifdef GL_ES",
- "precision highp float;",
- "#endif",
- "uniform sampler2D map;",
- "uniform float opacity;",
-
- "varying vec2 vUV;",
-
- "void main( void )",
- "{",
- "vec4 color = texture2D( map, vUV );",
- "color.a *= opacity;",
- "gl_FragColor = color;",
- // "gl_FragColor = vec4( 1.0, 0.0, 1.0, 1.0 );",
- "}"
- ].join( "\n" )
- },
- 'shadowPost': {
- vertexShader: [
- "uniform mat4 projectionMatrix;",
- "attribute vec3 position;",
- "void main(void)",
- "{",
- "gl_Position = projectionMatrix * vec4( position, 1.0 );",
- "}"
- ].join( "\n" ),
- fragmentShader: [
- "#ifdef GL_ES",
- "precision highp float;",
- "#endif",
- "uniform float darkness;",
- "void main( void )",
- "{",
- "gl_FragColor = vec4( 0, 0, 0, darkness );",
- "}"
- ].join( "\n" )
- },
- 'shadowVolumeDynamic': {
- uniforms: { "directionalLightDirection": { type: "fv", value: [] }},
- vertexShader: [
- "uniform vec3 directionalLightDirection;",
- "void main() {",
- "vec4 pos = objectMatrix * vec4( position, 1.0 );",
- "vec3 norm = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;",
- "vec4 extruded = vec4( directionalLightDirection * 5000.0 * step( 0.0, dot( directionalLightDirection, norm )), 0.0 );",
- "gl_Position = projectionMatrix * viewMatrix * ( pos + extruded );",
- "}"
- ].join( "\n" ),
- fragmentShader: [
- "void main() {",
- "gl_FragColor = vec4( 1, 1, 1, 1 );",
- "}"
- ].join( "\n" )
- },
- 'depth': {
- uniforms: { "mNear": { type: "f", value: 1.0 },
- "mFar" : { type: "f", value: 2000.0 },
- "opacity" : { type: "f", value: 1.0 }
- },
- fragmentShader: [
- "uniform float mNear;",
- "uniform float mFar;",
- "uniform float opacity;",
- "void main() {",
- "float depth = gl_FragCoord.z / gl_FragCoord.w;",
- "float color = 1.0 - smoothstep( mNear, mFar, depth );",
- "gl_FragColor = vec4( vec3( color ), opacity );",
- "}"
- ].join("\n"),
- vertexShader: [
- "void main() {",
- "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
- "}"
- ].join("\n")
- },
- 'normal': {
- uniforms: { "opacity" : { type: "f", value: 1.0 } },
- fragmentShader: [
- "uniform float opacity;",
- "varying vec3 vNormal;",
- "void main() {",
- "gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
- "}"
- ].join("\n"),
- vertexShader: [
- "varying vec3 vNormal;",
- "void main() {",
- "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- "vNormal = normalize( normalMatrix * normal );",
- "gl_Position = projectionMatrix * mvPosition;",
- "}"
- ].join("\n")
- },
- 'basic': {
- uniforms: THREE.UniformsLib[ "common" ],
- fragmentShader: [
- "uniform vec3 diffuse;",
- "uniform float opacity;",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "map_pars_fragment" ],
- THREE.ShaderChunk[ "lightmap_pars_fragment" ],
- THREE.ShaderChunk[ "envmap_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- "void main() {",
- "gl_FragColor = vec4( diffuse, opacity );",
- THREE.ShaderChunk[ "map_fragment" ],
- THREE.ShaderChunk[ "lightmap_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "envmap_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n"),
- vertexShader: [
- THREE.ShaderChunk[ "map_pars_vertex" ],
- THREE.ShaderChunk[ "lightmap_pars_vertex" ],
- THREE.ShaderChunk[ "envmap_pars_vertex" ],
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- "void main() {",
- "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- THREE.ShaderChunk[ "map_vertex" ],
- THREE.ShaderChunk[ "lightmap_vertex" ],
- THREE.ShaderChunk[ "envmap_vertex" ],
- THREE.ShaderChunk[ "color_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "default_vertex" ],
- "}"
- ].join("\n")
- },
- 'lambert': {
- uniforms: Uniforms.merge( [ THREE.UniformsLib[ "common" ],
- THREE.UniformsLib[ "lights" ] ] ),
- fragmentShader: [
- "uniform vec3 diffuse;",
- "uniform float opacity;",
- "varying vec3 vLightWeighting;",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "map_pars_fragment" ],
- THREE.ShaderChunk[ "lightmap_pars_fragment" ],
- THREE.ShaderChunk[ "envmap_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- "void main() {",
- "gl_FragColor = vec4( diffuse, opacity );",
- "gl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );",
- THREE.ShaderChunk[ "map_fragment" ],
- THREE.ShaderChunk[ "lightmap_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "envmap_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n"),
- vertexShader: [
- "varying vec3 vLightWeighting;",
- THREE.ShaderChunk[ "map_pars_vertex" ],
- THREE.ShaderChunk[ "lightmap_pars_vertex" ],
- THREE.ShaderChunk[ "envmap_pars_vertex" ],
- THREE.ShaderChunk[ "lights_pars_vertex" ],
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- "void main() {",
- "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- THREE.ShaderChunk[ "map_vertex" ],
- THREE.ShaderChunk[ "lightmap_vertex" ],
- THREE.ShaderChunk[ "envmap_vertex" ],
- THREE.ShaderChunk[ "color_vertex" ],
- "vec3 transformedNormal = normalize( normalMatrix * normal );",
- THREE.ShaderChunk[ "lights_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "default_vertex" ],
- "}"
- ].join("\n")
- },
- 'phong': {
- uniforms: Uniforms.merge( [ THREE.UniformsLib[ "common" ],
- THREE.UniformsLib[ "lights" ],
- { "ambient" : { type: "c", value: new THREE.Color( 0x050505 ) },
- "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
- "shininess": { type: "f", value: 30 }
- }
- ] ),
- fragmentShader: [
- "uniform vec3 diffuse;",
- "uniform float opacity;",
- "uniform vec3 ambient;",
- "uniform vec3 specular;",
- "uniform float shininess;",
- "varying vec3 vLightWeighting;",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "map_pars_fragment" ],
- THREE.ShaderChunk[ "lightmap_pars_fragment" ],
- THREE.ShaderChunk[ "envmap_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- THREE.ShaderChunk[ "lights_pars_fragment" ],
- "void main() {",
- "gl_FragColor = vec4( vLightWeighting, 1.0 );",
- THREE.ShaderChunk[ "lights_fragment" ],
- THREE.ShaderChunk[ "map_fragment" ],
- THREE.ShaderChunk[ "lightmap_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "envmap_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n"),
- vertexShader: [
- "#define PHONG",
- "varying vec3 vLightWeighting;",
- "varying vec3 vViewPosition;",
- "varying vec3 vNormal;",
- THREE.ShaderChunk[ "map_pars_vertex" ],
- THREE.ShaderChunk[ "lightmap_pars_vertex" ],
- THREE.ShaderChunk[ "envmap_pars_vertex" ],
- THREE.ShaderChunk[ "lights_pars_vertex" ],
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- "void main() {",
- "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- THREE.ShaderChunk[ "map_vertex" ],
- THREE.ShaderChunk[ "lightmap_vertex" ],
- THREE.ShaderChunk[ "envmap_vertex" ],
- THREE.ShaderChunk[ "color_vertex" ],
- "#ifndef USE_ENVMAP",
- "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
- "#endif",
- "vViewPosition = cameraPosition - mPosition.xyz;",
- "vec3 transformedNormal = normalize( normalMatrix * normal );",
- "vNormal = transformedNormal;",
- THREE.ShaderChunk[ "lights_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "default_vertex" ],
- "}"
- ].join("\n")
- },
- 'particle_basic': {
- uniforms: THREE.UniformsLib[ "particle" ],
- fragmentShader: [
- "uniform vec3 psColor;",
- "uniform float opacity;",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "map_particle_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- "void main() {",
- "gl_FragColor = vec4( psColor, opacity );",
- THREE.ShaderChunk[ "map_particle_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n"),
- vertexShader: [
- "uniform float size;",
- "uniform float scale;",
- THREE.ShaderChunk[ "color_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "color_vertex" ],
- "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- "#ifdef USE_SIZEATTENUATION",
- "gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
- "#else",
- "gl_PointSize = size;",
- "#endif",
- "gl_Position = projectionMatrix * mvPosition;",
- "}"
- ].join("\n")
- }
- };
|