123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356 |
- THREE.ShaderChunk[ "sphere_vertex"] =
- ["vec4 mvPosition;",
- "#ifdef USE_SKINNING",
- " mvPosition = modelViewMatrix * skinned;",
- "#endif",
- "#if !defined( USE_SKINNING ) && defined( USE_MORPHTARGETS )",
- " mvPosition = modelViewMatrix * vec4( morphed, 1.0 );",
- "#endif",
- "#if !defined( USE_SKINNING ) && ! defined( USE_MORPHTARGETS )",
- " mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- "#endif ",
- " vec4 p = mvPosition; // put the vector into the camera frame",
- " float len = length(p.xyz); // use the length of the vector - not the z component",
- " if(p.z<0.0)len = -len; // the length sign should reflect the z sign",
- " float ctan = projectionMatrix[0][0]; // this is the cotangent of the x-component",
- " p.y *= projectionMatrix[1][1]/ctan; // set the y aspect ratio",
- " p.w = -len; // the w component is the negative of the z component",
- " p.z = len*projectionMatrix[2][2]+projectionMatrix[3][2]; // the z component is really the length of the vector",
- " p.xy *= sqrt((ctan*ctan)+1.0); // this is the camera field of view - the narrower the fov, the larger this multiplier is",
- " p.x += projectionMatrix[2][0]*len;",
- " p.y += projectionMatrix[2][1]*len;",
- " gl_Position = p; // done"
- ].join("\n");
- THREE.ShaderLib = {
- 'basic': {
- uniforms: THREE.UniformsUtils.merge( [
- THREE.UniformsLib[ "common" ],
- THREE.UniformsLib[ "fog" ],
- THREE.UniformsLib[ "shadowmap" ]
- ] ),
- vertexShader: [
- THREE.ShaderChunk[ "map_pars_vertex" ],
- THREE.ShaderChunk[ "lightmap_pars_vertex" ],
- THREE.ShaderChunk[ "envmap_pars_vertex" ],
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "map_vertex" ],
- THREE.ShaderChunk[ "lightmap_vertex" ],
- THREE.ShaderChunk[ "color_vertex" ],
- THREE.ShaderChunk[ "skinbase_vertex" ],
- " #ifdef USE_ENVMAP",
- THREE.ShaderChunk[ "morphnormal_vertex" ],
- THREE.ShaderChunk[ "skinnormal_vertex" ],
- THREE.ShaderChunk[ "defaultnormal_vertex" ],
- " #endif",
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "sphere_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- THREE.ShaderChunk[ "worldpos_vertex" ],
- THREE.ShaderChunk[ "envmap_vertex" ],
- THREE.ShaderChunk[ "shadowmap_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- "uniform vec3 diffuse;",
- "uniform float opacity;",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "map_pars_fragment" ],
- THREE.ShaderChunk[ "alphamap_pars_fragment" ],
- THREE.ShaderChunk[ "lightmap_pars_fragment" ],
- THREE.ShaderChunk[ "envmap_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
- THREE.ShaderChunk[ "specularmap_pars_fragment" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- " gl_FragColor = vec4( diffuse, opacity );",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- THREE.ShaderChunk[ "map_fragment" ],
- THREE.ShaderChunk[ "alphamap_fragment" ],
- THREE.ShaderChunk[ "alphatest_fragment" ],
- THREE.ShaderChunk[ "specularmap_fragment" ],
- THREE.ShaderChunk[ "lightmap_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "envmap_fragment" ],
- THREE.ShaderChunk[ "shadowmap_fragment" ],
- THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n")
- },
- 'lambert': {
- uniforms: THREE.UniformsUtils.merge( [
- THREE.UniformsLib[ "common" ],
- THREE.UniformsLib[ "fog" ],
- THREE.UniformsLib[ "lights" ],
- THREE.UniformsLib[ "shadowmap" ],
- {
- "ambient" : { type: "c", value: new THREE.Color( 0xffffff ) },
- "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
- "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
- }
- ] ),
- vertexShader: [
- "#define LAMBERT",
- "varying vec3 vLightFront;",
- "#ifdef DOUBLE_SIDED",
- " varying vec3 vLightBack;",
- "#endif",
- THREE.ShaderChunk[ "map_pars_vertex" ],
- THREE.ShaderChunk[ "lightmap_pars_vertex" ],
- THREE.ShaderChunk[ "envmap_pars_vertex" ],
- THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "map_vertex" ],
- THREE.ShaderChunk[ "lightmap_vertex" ],
- THREE.ShaderChunk[ "color_vertex" ],
- THREE.ShaderChunk[ "morphnormal_vertex" ],
- THREE.ShaderChunk[ "skinbase_vertex" ],
- THREE.ShaderChunk[ "skinnormal_vertex" ],
- THREE.ShaderChunk[ "defaultnormal_vertex" ],
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "sphere_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- THREE.ShaderChunk[ "worldpos_vertex" ],
- THREE.ShaderChunk[ "envmap_vertex" ],
- THREE.ShaderChunk[ "lights_lambert_vertex" ],
- THREE.ShaderChunk[ "shadowmap_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- "uniform float opacity;",
- "varying vec3 vLightFront;",
- "#ifdef DOUBLE_SIDED",
- " varying vec3 vLightBack;",
- "#endif",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "map_pars_fragment" ],
- THREE.ShaderChunk[ "alphamap_pars_fragment" ],
- THREE.ShaderChunk[ "lightmap_pars_fragment" ],
- THREE.ShaderChunk[ "envmap_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
- THREE.ShaderChunk[ "specularmap_pars_fragment" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- " gl_FragColor = vec4( vec3( 1.0 ), opacity );",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- THREE.ShaderChunk[ "map_fragment" ],
- THREE.ShaderChunk[ "alphamap_fragment" ],
- THREE.ShaderChunk[ "alphatest_fragment" ],
- THREE.ShaderChunk[ "specularmap_fragment" ],
- " #ifdef DOUBLE_SIDED",
-
-
- " if ( gl_FrontFacing )",
- " gl_FragColor.xyz *= vLightFront;",
- " else",
- " gl_FragColor.xyz *= vLightBack;",
- " #else",
- " gl_FragColor.xyz *= vLightFront;",
- " #endif",
- THREE.ShaderChunk[ "lightmap_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "envmap_fragment" ],
- THREE.ShaderChunk[ "shadowmap_fragment" ],
- THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n")
- },
- 'phong': {
- uniforms: THREE.UniformsUtils.merge( [
- THREE.UniformsLib[ "common" ],
- THREE.UniformsLib[ "bump" ],
- THREE.UniformsLib[ "normalmap" ],
- THREE.UniformsLib[ "fog" ],
- THREE.UniformsLib[ "lights" ],
- THREE.UniformsLib[ "shadowmap" ],
- {
- "ambient" : { type: "c", value: new THREE.Color( 0xffffff ) },
- "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
- "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
- "shininess": { type: "f", value: 30 },
- "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
- }
- ] ),
- vertexShader: [
- "#define PHONG",
- "varying vec3 vViewPosition;",
- "varying vec3 vNormal;",
- THREE.ShaderChunk[ "map_pars_vertex" ],
- THREE.ShaderChunk[ "lightmap_pars_vertex" ],
- THREE.ShaderChunk[ "envmap_pars_vertex" ],
- THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "map_vertex" ],
- THREE.ShaderChunk[ "lightmap_vertex" ],
- THREE.ShaderChunk[ "color_vertex" ],
- THREE.ShaderChunk[ "morphnormal_vertex" ],
- THREE.ShaderChunk[ "skinbase_vertex" ],
- THREE.ShaderChunk[ "skinnormal_vertex" ],
- THREE.ShaderChunk[ "defaultnormal_vertex" ],
- " vNormal = normalize( transformedNormal );",
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "sphere_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- " vViewPosition = -mvPosition.xyz;",
- THREE.ShaderChunk[ "worldpos_vertex" ],
- THREE.ShaderChunk[ "envmap_vertex" ],
- THREE.ShaderChunk[ "lights_phong_vertex" ],
- THREE.ShaderChunk[ "shadowmap_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- "uniform vec3 diffuse;",
- "uniform float opacity;",
- "uniform vec3 ambient;",
- "uniform vec3 emissive;",
- "uniform vec3 specular;",
- "uniform float shininess;",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "map_pars_fragment" ],
- THREE.ShaderChunk[ "alphamap_pars_fragment" ],
- THREE.ShaderChunk[ "lightmap_pars_fragment" ],
- THREE.ShaderChunk[ "envmap_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
- THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
- THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
- THREE.ShaderChunk[ "normalmap_pars_fragment" ],
- THREE.ShaderChunk[ "specularmap_pars_fragment" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- " gl_FragColor = vec4( vec3( 1.0 ), opacity );",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- THREE.ShaderChunk[ "map_fragment" ],
- THREE.ShaderChunk[ "alphamap_fragment" ],
- THREE.ShaderChunk[ "alphatest_fragment" ],
- THREE.ShaderChunk[ "specularmap_fragment" ],
- THREE.ShaderChunk[ "lights_phong_fragment" ],
- THREE.ShaderChunk[ "lightmap_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "envmap_fragment" ],
- THREE.ShaderChunk[ "shadowmap_fragment" ],
- THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n")
- },
- 'particle_basic': {
- uniforms: THREE.UniformsUtils.merge( [
- THREE.UniformsLib[ "particle" ],
- THREE.UniformsLib[ "shadowmap" ]
- ] ),
- vertexShader: [
- "uniform float size;",
- "uniform float scale;",
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_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;",
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- THREE.ShaderChunk[ "worldpos_vertex" ],
- THREE.ShaderChunk[ "shadowmap_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- "uniform vec3 psColor;",
- "uniform float opacity;",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "map_particle_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- " gl_FragColor = vec4( psColor, opacity );",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- THREE.ShaderChunk[ "map_particle_fragment" ],
- THREE.ShaderChunk[ "alphatest_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "shadowmap_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n")
- },
- 'dashed': {
- uniforms: THREE.UniformsUtils.merge( [
- THREE.UniformsLib[ "common" ],
- THREE.UniformsLib[ "fog" ],
- {
- "scale" : { type: "f", value: 1 },
- "dashSize" : { type: "f", value: 1 },
- "totalSize": { type: "f", value: 2 }
- }
- ] ),
- vertexShader: [
- "uniform float scale;",
- "attribute float lineDistance;",
- "varying float vLineDistance;",
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "color_vertex" ],
- " vLineDistance = scale * lineDistance;",
- " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- " gl_Position = projectionMatrix * mvPosition;",
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- "uniform vec3 diffuse;",
- "uniform float opacity;",
- "uniform float dashSize;",
- "uniform float totalSize;",
- "varying float vLineDistance;",
- THREE.ShaderChunk[ "color_pars_fragment" ],
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
- " discard;",
- " }",
- " gl_FragColor = vec4( diffuse, opacity );",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- "}"
- ].join("\n")
- },
- 'depth': {
- uniforms: {
- "mNear": { type: "f", value: 1.0 },
- "mFar" : { type: "f", value: 2000.0 },
- "opacity" : { type: "f", value: 1.0 }
- },
- vertexShader: [
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "sphere_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- "uniform float mNear;",
- "uniform float mFar;",
- "uniform float opacity;",
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- " #ifdef USE_LOGDEPTHBUF_EXT",
- " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
- " #else",
- " float depth = gl_FragCoord.z / gl_FragCoord.w;",
- " #endif",
- " float color = 1.0 - smoothstep( mNear, mFar, depth );",
- " gl_FragColor = vec4( vec3( color ), opacity );",
- "}"
- ].join("\n")
- },
- 'normal': {
- uniforms: {
- "opacity" : { type: "f", value: 1.0 }
- },
- vertexShader: [
- "varying vec3 vNormal;",
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- " vNormal = normalize( normalMatrix * normal );",
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "sphere_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- "uniform float opacity;",
- "varying vec3 vNormal;",
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- "}"
- ].join("\n")
- },
-
- 'normalmap' : {
- 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 },
- "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 },
- "diffuse": { type: "c", value: new THREE.Color( 0xffffff ) },
- "specular": { type: "c", value: new THREE.Color( 0x111111 ) },
- "ambient": { type: "c", value: new THREE.Color( 0xffffff ) },
- "shininess": { type: "f", value: 30 },
- "opacity": { type: "f", value: 1 },
- "useRefract": { type: "i", value: 0 },
- "refractionRatio": { type: "f", value: 0.98 },
- "reflectivity": { 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 ambient;",
- "uniform vec3 diffuse;",
- "uniform vec3 specular;",
- "uniform float shininess;",
- "uniform float opacity;",
- "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 refractionRatio;",
- "uniform float reflectivity;",
- "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" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- " gl_FragColor = vec4( vec3( 1.0 ), opacity );",
- " 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",
- " }",
-
- THREE.ShaderChunk[ "alphatest_fragment" ],
- " 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 );",
-
- " #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 );",
-
- " #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 ] * diffuse * pointDiffuseWeight;",
-
- " vec3 pointHalfVector = normalize( pointVector + viewPosition );",
- " float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
- " float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
- " float specularNormalization = ( shininess + 2.0 ) / 8.0;",
- " vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( pointVector, pointHalfVector ), 0.0 ), 5.0 );",
- " pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
- " }",
- " #endif",
-
- " #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( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );",
-
- " #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 ] * diffuse * spotDiffuseWeight * spotEffect;",
-
- " vec3 spotHalfVector = normalize( spotVector + viewPosition );",
- " float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );",
- " float spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, shininess ), 0.0 );",
- " float specularNormalization = ( shininess + 2.0 ) / 8.0;",
- " vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( spotVector, spotHalfVector ), 0.0 ), 5.0 );",
- " spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;",
- " }",
- " }",
- " #endif",
-
- " #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 );",
-
- " #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 ] * diffuse * dirDiffuseWeight;",
-
- " vec3 dirHalfVector = normalize( dirVector + viewPosition );",
- " float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
- " float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
- " float specularNormalization = ( shininess + 2.0 ) / 8.0;",
- " vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );",
- " dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
- " }",
- " #endif",
-
- " #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 );",
-
- " float dotProduct = dot( normal, lVector );",
- " float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
- " vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
- " hemiDiffuse += diffuse * hemiColor;",
-
- " vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
- " float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
- " float hemiSpecularWeightSky = specularTex.r * max( pow( max( hemiDotNormalHalfSky, 0.0 ), shininess ), 0.0 );",
-
- " vec3 lVectorGround = -lVector;",
- " vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
- " float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
- " float hemiSpecularWeightGround = specularTex.r * max( pow( max( hemiDotNormalHalfGround, 0.0 ), shininess ), 0.0 );",
- " float dotProductGround = dot( normal, lVectorGround );",
- " float specularNormalization = ( shininess + 2.0 ) / 8.0;",
- " vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, hemiHalfVectorSky ), 0.0 ), 5.0 );",
- " vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 0.0 ), 5.0 );",
- " hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
- " }",
- " #endif",
-
- " 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 * ambient + totalSpecular );",
- " #else",
- " gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient ) + totalSpecular;",
- " #endif",
- " if ( enableReflection ) {",
- " vec3 vReflect;",
- " vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );",
- " if ( useRefract ) {",
- " vReflect = refract( cameraToVertex, normal, refractionRatio );",
- " } 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 * reflectivity );",
- " }",
- 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" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "skinbase_vertex" ],
- THREE.ShaderChunk[ "skinnormal_vertex" ],
-
- " #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;",
-
- " 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 = bindMatrix * vec4( position, 1.0 );",
- " vec4 skinned = vec4( 0.0 );",
- " skinned += boneMatX * skinVertex * skinWeight.x;",
- " skinned += boneMatY * skinVertex * skinWeight.y;",
- " skinned += boneMatZ * skinVertex * skinWeight.z;",
- " skinned += boneMatW * skinVertex * skinWeight.w;",
- " skinned = bindMatrixInverse * skinned;",
- " displacedPosition = skinned.xyz;",
- " #else",
- " displacedPosition = position;",
- " #endif",
- " }",
- " #else",
- " #ifdef USE_SKINNING",
- " vec4 skinVertex = bindMatrix * vec4( position, 1.0 );",
- " vec4 skinned = vec4( 0.0 );",
- " skinned += boneMatX * skinVertex * skinWeight.x;",
- " skinned += boneMatY * skinVertex * skinWeight.y;",
- " skinned += boneMatZ * skinVertex * skinWeight.z;",
- " skinned += boneMatW * skinVertex * skinWeight.w;",
- " skinned = bindMatrixInverse * skinned;",
- " 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;",
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
-
- " vWorldPosition = worldPosition.xyz;",
- " vViewPosition = -mvPosition.xyz;",
-
- " #ifdef USE_SHADOWMAP",
- " for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
- " vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;",
- " }",
- " #endif",
- "}"
- ].join("\n")
- },
-
- 'cube': {
- uniforms: { "tCube": { type: "t", value: null },
- "tFlip": { type: "f", value: - 1 } },
- vertexShader: [
- "varying vec3 vWorldPosition;",
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- " vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
- " vWorldPosition = worldPosition.xyz;",
- " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- "uniform samplerCube tCube;",
- "uniform float tFlip;",
- "varying vec3 vWorldPosition;",
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "void main() {",
- " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- "}"
- ].join("\n")
- },
-
- 'depthRGBA': {
- uniforms: {},
- vertexShader: [
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "skinbase_vertex" ],
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "sphere_vertex" ],
- THREE.ShaderChunk[ "logdepthbuf_vertex" ],
- "}"
- ].join("\n"),
- fragmentShader: [
- THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
- "vec4 pack_depth( const in float depth ) {",
- " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
- " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
- " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );",
- " res -= res.xxyz * bit_mask;",
- " return res;",
- "}",
- "void main() {",
- THREE.ShaderChunk[ "logdepthbuf_fragment" ],
- " #ifdef USE_LOGDEPTHBUF_EXT",
- " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
- " #else",
- " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
- " #endif",
-
-
-
-
- "}"
- ].join("\n")
- }
- };
|