1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390 |
- define([
- '../Core/Cartesian2',
- '../Core/clone',
- '../Core/Color',
- '../Core/combine',
- '../Core/createGuid',
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/destroyObject',
- '../Core/DeveloperError',
- '../Core/isArray',
- '../Core/loadImage',
- '../Core/Matrix2',
- '../Core/Matrix3',
- '../Core/Matrix4',
- '../Renderer/CubeMap',
- '../Renderer/Texture',
- '../Shaders/Materials/BumpMapMaterial',
- '../Shaders/Materials/CheckerboardMaterial',
- '../Shaders/Materials/DotMaterial',
- '../Shaders/Materials/FadeMaterial',
- '../Shaders/Materials/GridMaterial',
- '../Shaders/Materials/NormalMapMaterial',
- '../Shaders/Materials/PolylineArrowMaterial',
- '../Shaders/Materials/PolylineGlowMaterial',
- '../Shaders/Materials/PolylineOutlineMaterial',
- '../Shaders/Materials/RimLightingMaterial',
- '../Shaders/Materials/StripeMaterial',
- '../Shaders/Materials/Water',
- '../ThirdParty/when'
- ], function(
- Cartesian2,
- clone,
- Color,
- combine,
- createGuid,
- defaultValue,
- defined,
- defineProperties,
- destroyObject,
- DeveloperError,
- isArray,
- loadImage,
- Matrix2,
- Matrix3,
- Matrix4,
- CubeMap,
- Texture,
- BumpMapMaterial,
- CheckerboardMaterial,
- DotMaterial,
- FadeMaterial,
- GridMaterial,
- NormalMapMaterial,
- PolylineArrowMaterial,
- PolylineGlowMaterial,
- PolylineOutlineMaterial,
- RimLightingMaterial,
- StripeMaterial,
- WaterMaterial,
- when) {
- "use strict";
-
- var Material = function(options) {
-
- this.type = undefined;
-
- this.shaderSource = undefined;
-
- this.materials = undefined;
-
- this.uniforms = undefined;
- this._uniforms = undefined;
-
- this.translucent = undefined;
- this._strict = undefined;
- this._template = undefined;
- this._count = undefined;
- this._texturePaths = {};
- this._loadedImages = [];
- this._loadedCubeMaps = [];
- this._textures = {};
- this._updateFunctions = [];
- initializeMaterial(options, this);
- defineProperties(this, {
- type : {
- value : this.type,
- writable : false
- }
- });
- if (!defined(Material._uniformList[this.type])) {
- Material._uniformList[this.type] = Object.keys(this._uniforms);
- }
- };
-
-
- Material._uniformList = {};
-
- Material.fromType = function(type, uniforms) {
-
- if (!defined(Material._materialCache.getMaterial(type))) {
- throw new DeveloperError('material with type \'' + type + '\' does not exist.');
- }
-
- var material = new Material({
- fabric : {
- type : type
- }
- });
- if (defined(uniforms)) {
- for (var name in uniforms) {
- if (uniforms.hasOwnProperty(name)) {
- material.uniforms[name] = uniforms[name];
- }
- }
- }
- return material;
- };
-
- Material.prototype.isTranslucent = function() {
- if (defined(this.translucent)) {
- if (typeof this.translucent === 'function') {
- return this.translucent();
- }
- return this.translucent;
- }
- var translucent = true;
- var funcs = this._translucentFunctions;
- var length = funcs.length;
- for (var i = 0; i < length; ++i) {
- var func = funcs[i];
- if (typeof func === 'function') {
- translucent = translucent && func();
- } else {
- translucent = translucent && func;
- }
- if (!translucent) {
- break;
- }
- }
- return translucent;
- };
-
- Material.prototype.update = function(context) {
- var i;
- var uniformId;
- var loadedImages = this._loadedImages;
- var length = loadedImages.length;
- for (i = 0; i < length; ++i) {
- var loadedImage = loadedImages[i];
- uniformId = loadedImage.id;
- var image = loadedImage.image;
- var texture = Material._textureCache.getTexture(this._texturePaths[uniformId]);
- if (!defined(texture)) {
- texture = context.createTexture2D({
- source : image
- });
- Material._textureCache.addTexture(this._texturePaths[uniformId], texture);
- }
- this._textures[uniformId] = texture;
- var uniformDimensionsName = uniformId + 'Dimensions';
- if (this.uniforms.hasOwnProperty(uniformDimensionsName)) {
- var uniformDimensions = this.uniforms[uniformDimensionsName];
- uniformDimensions.x = texture._width;
- uniformDimensions.y = texture._height;
- }
- }
- loadedImages.length = 0;
- var loadedCubeMaps = this._loadedCubeMaps;
- length = loadedCubeMaps.length;
- for (i = 0; i < length; ++i) {
- var loadedCubeMap = loadedCubeMaps[i];
- uniformId = loadedCubeMap.id;
- var images = loadedCubeMap.images;
- var cubeMap = Material._textureCache.getTexture(this._texturePaths[uniformId]);
- if (!defined(cubeMap)) {
- cubeMap = context.createCubeMap({
- source : {
- positiveX : images[0],
- negativeX : images[1],
- positiveY : images[2],
- negativeY : images[3],
- positiveZ : images[4],
- negativeZ : images[5]
- }
- });
- Material._textureCache.addTexture(this._texturePaths[uniformId], cubeMap);
- }
- this._textures[uniformId] = cubeMap;
- }
- loadedCubeMaps.length = 0;
- var updateFunctions = this._updateFunctions;
- length = updateFunctions.length;
- for (i = 0; i < length; ++i) {
- updateFunctions[i](this, context);
- }
- var subMaterials = this.materials;
- for (var name in subMaterials) {
- if (subMaterials.hasOwnProperty(name)) {
- subMaterials[name].update(context);
- }
- }
- };
-
- Material.prototype.isDestroyed = function() {
- return false;
- };
-
- Material.prototype.destroy = function() {
- var materials = this.materials;
- var uniforms = this.uniforms;
- for ( var uniformId in uniforms) {
- if (uniforms.hasOwnProperty(uniformId)) {
- var path = this._texturePaths[uniformId];
- Material._textureCache.releaseTexture(path);
- }
- }
- for ( var material in materials) {
- if (materials.hasOwnProperty(material)) {
- materials[material].destroy();
- }
- }
- return destroyObject(this);
- };
- function initializeMaterial(options, result) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
- result._strict = defaultValue(options.strict, false);
- result._count = defaultValue(options.count, 0);
- result._template = clone(defaultValue(options.fabric, defaultValue.EMPTY_OBJECT));
- result._template.uniforms = clone(defaultValue(result._template.uniforms, defaultValue.EMPTY_OBJECT));
- result._template.materials = clone(defaultValue(result._template.materials, defaultValue.EMPTY_OBJECT));
- result.type = defined(result._template.type) ? result._template.type : createGuid();
- result.shaderSource = '';
- result.materials = {};
- result.uniforms = {};
- result._uniforms = {};
- result._translucentFunctions = [];
- var translucent;
-
- var cachedMaterial = Material._materialCache.getMaterial(result.type);
- if (defined(cachedMaterial)) {
- var template = clone(cachedMaterial.fabric, true);
- result._template = combine(result._template, template, true);
- translucent = cachedMaterial.translucent;
- }
-
- checkForTemplateErrors(result);
-
- if (!defined(cachedMaterial)) {
- Material._materialCache.addMaterial(result.type, result);
- }
- createMethodDefinition(result);
- createUniforms(result);
- createSubMaterials(result);
- var defaultTranslucent = result._translucentFunctions.length === 0 ? true : undefined;
- translucent = defaultValue(translucent, defaultTranslucent);
- translucent = defaultValue(options.translucent, translucent);
- if (defined(translucent)) {
- if (typeof translucent === 'function') {
- var wrappedTranslucent = function() {
- return translucent(result);
- };
- result._translucentFunctions.push(wrappedTranslucent);
- } else {
- result._translucentFunctions.push(translucent);
- }
- }
- }
- function checkForValidProperties(object, properties, result, throwNotFound) {
- if (defined(object)) {
- for ( var property in object) {
- if (object.hasOwnProperty(property)) {
- var hasProperty = properties.indexOf(property) !== -1;
- if ((throwNotFound && !hasProperty) || (!throwNotFound && hasProperty)) {
- result(property, properties);
- }
- }
- }
- }
- }
- function invalidNameError(property, properties) {
- var errorString = 'fabric: property name \'' + property + '\' is not valid. It should be ';
- for ( var i = 0; i < properties.length; i++) {
- var propertyName = '\'' + properties[i] + '\'';
- errorString += (i === properties.length - 1) ? ('or ' + propertyName + '.') : (propertyName + ', ');
- }
- throw new DeveloperError(errorString);
- }
- function duplicateNameError(property, properties) {
- var errorString = 'fabric: uniforms and materials cannot share the same property \'' + property + '\'';
- throw new DeveloperError(errorString);
- }
- var templateProperties = ['type', 'materials', 'uniforms', 'components', 'source'];
- var componentProperties = ['diffuse', 'specular', 'shininess', 'normal', 'emission', 'alpha'];
- function checkForTemplateErrors(material) {
- var template = material._template;
- var uniforms = template.uniforms;
- var materials = template.materials;
- var components = template.components;
-
- if (defined(components) && defined(template.source)) {
- throw new DeveloperError('fabric: cannot have source and components in the same template.');
- }
-
- checkForValidProperties(template, templateProperties, invalidNameError, true);
- checkForValidProperties(components, componentProperties, invalidNameError, true);
-
- var materialNames = [];
- for ( var property in materials) {
- if (materials.hasOwnProperty(property)) {
- materialNames.push(property);
- }
- }
- checkForValidProperties(uniforms, materialNames, duplicateNameError, false);
- }
-
- function createMethodDefinition(material) {
- var components = material._template.components;
- var source = material._template.source;
- if (defined(source)) {
- material.shaderSource += source + '\n';
- } else {
- material.shaderSource += 'czm_material czm_getMaterial(czm_materialInput materialInput)\n{\n';
- material.shaderSource += 'czm_material material = czm_getDefaultMaterial(materialInput);\n';
- if (defined(components)) {
- for ( var component in components) {
- if (components.hasOwnProperty(component)) {
- material.shaderSource += 'material.' + component + ' = ' + components[component] + ';\n';
- }
- }
- }
- material.shaderSource += 'return material;\n}\n';
- }
- }
- var matrixMap = {
- 'mat2' : Matrix2,
- 'mat3' : Matrix3,
- 'mat4' : Matrix4
- };
- function createTexture2DUpdateFunction(uniformId) {
- return function(material, context) {
- var uniforms = material.uniforms;
- var uniformValue = uniforms[uniformId];
- var texture = material._textures[uniformId];
- var uniformDimensionsName;
- var uniformDimensions;
- if (uniformValue instanceof Texture && uniformValue !== texture) {
- Material._textureCache.releaseTexture(material._texturePaths[uniformId]);
- material._texturePaths[uniformId] = undefined;
- material._textures[uniformId] = uniformValue;
- uniformDimensionsName = uniformId + 'Dimensions';
- if (uniforms.hasOwnProperty(uniformDimensionsName)) {
- uniformDimensions = uniforms[uniformDimensionsName];
- uniformDimensions.x = uniformValue._width;
- uniformDimensions.y = uniformValue._height;
- }
- return;
- }
- if (!defined(texture)) {
- material._texturePaths[uniformId] = undefined;
- texture = material._textures[uniformId] = context.defaultTexture;
- uniformDimensionsName = uniformId + 'Dimensions';
- if (uniforms.hasOwnProperty(uniformDimensionsName)) {
- uniformDimensions = uniforms[uniformDimensionsName];
- uniformDimensions.x = texture._width;
- uniformDimensions.y = texture._height;
- }
- }
- if (uniformValue === Material.DefaultImageId) {
- return;
- }
- if (uniformValue !== material._texturePaths[uniformId]) {
- var newTexture = Material._textureCache.getTexture(uniformValue);
- if (defined(newTexture)) {
- Material._textureCache.releaseTexture(material._texturePaths[uniformId]);
- material._textures[uniformId] = newTexture;
- } else {
- when(loadImage(uniformValue), function(image) {
- material._loadedImages.push({
- id : uniformId,
- image : image
- });
- });
- }
- material._texturePaths[uniformId] = uniformValue;
- }
- };
- }
- function createCubeMapUpdateFunction(uniformId) {
- return function(material, context) {
- var uniformValue = material.uniforms[uniformId];
- if (uniformValue instanceof CubeMap) {
- Material._textureCache.releaseTexture(material._texturePaths[uniformId]);
- material._texturePaths[uniformId] = undefined;
- material._textures[uniformId] = uniformValue;
- return;
- }
- if (!defined(material._textures[uniformId])) {
- material._texturePaths[uniformId] = undefined;
- material._textures[uniformId] = context.defaultCubeMap;
- }
- if (uniformValue === Material.DefaultCubeMapId) {
- return;
- }
- var path =
- uniformValue.positiveX + uniformValue.negativeX +
- uniformValue.positiveY + uniformValue.negativeY +
- uniformValue.positiveZ + uniformValue.negativeZ;
- if (path !== material._texturePaths[uniformId]) {
- var newTexture = Material._textureCache.getTexture(path);
- if (defined(newTexture)) {
- Material._textureCache.releaseTexture(material._texturePaths[uniformId]);
- material._textures[uniformId] = newTexture;
- } else {
- var promises = [
- loadImage(uniformValue.positiveX),
- loadImage(uniformValue.negativeX),
- loadImage(uniformValue.positiveY),
- loadImage(uniformValue.negativeY),
- loadImage(uniformValue.positiveZ),
- loadImage(uniformValue.negativeZ)
- ];
- when.all(promises).then(function(images) {
- material._loadedCubeMaps.push({
- id : uniformId,
- images : images
- });
- });
- }
- material._texturePaths[uniformId] = path;
- }
- };
- }
- function createUniforms(material) {
- var uniforms = material._template.uniforms;
- for ( var uniformId in uniforms) {
- if (uniforms.hasOwnProperty(uniformId)) {
- createUniform(material, uniformId);
- }
- }
- }
-
-
- function createUniform(material, uniformId) {
- var strict = material._strict;
- var materialUniforms = material._template.uniforms;
- var uniformValue = materialUniforms[uniformId];
- var uniformType = getUniformType(uniformValue);
- if (!defined(uniformType)) {
- throw new DeveloperError('fabric: uniform \'' + uniformId + '\' has invalid type.');
- } else if (uniformType === 'channels') {
- if (replaceToken(material, uniformId, uniformValue, false) === 0 && strict) {
- throw new DeveloperError('strict: shader source does not use channels \'' + uniformId + '\'.');
- }
- } else {
-
-
- if (uniformType === 'sampler2D') {
- var imageDimensionsUniformName = uniformId + 'Dimensions';
- if (getNumberOfTokens(material, imageDimensionsUniformName) > 0) {
- materialUniforms[imageDimensionsUniformName] = {
- type : 'ivec3',
- x : 1,
- y : 1
- };
- createUniform(material, imageDimensionsUniformName);
- }
- }
-
- var uniformDeclarationRegex = new RegExp('uniform\\s+' + uniformType + '\\s+' + uniformId + '\\s*;');
- if (!uniformDeclarationRegex.test(material.shaderSource)) {
- var uniformDeclaration = 'uniform ' + uniformType + ' ' + uniformId + ';';
- material.shaderSource = uniformDeclaration + material.shaderSource;
- }
- var newUniformId = uniformId + '_' + material._count++;
- if (replaceToken(material, uniformId, newUniformId) === 1 && strict) {
- throw new DeveloperError('strict: shader source does not use uniform \'' + uniformId + '\'.');
- }
-
- material.uniforms[uniformId] = uniformValue;
- if (uniformType === 'sampler2D') {
- material._uniforms[newUniformId] = function() {
- return material._textures[uniformId];
- };
- material._updateFunctions.push(createTexture2DUpdateFunction(uniformId));
- } else if (uniformType === 'samplerCube') {
- material._uniforms[newUniformId] = function() {
- return material._textures[uniformId];
- };
- material._updateFunctions.push(createCubeMapUpdateFunction(uniformId));
- } else if (uniformType.indexOf('mat') !== -1) {
- var scratchMatrix = new matrixMap[uniformType]();
- material._uniforms[newUniformId] = function() {
- return matrixMap[uniformType].fromColumnMajorArray(material.uniforms[uniformId], scratchMatrix);
- };
- } else {
- material._uniforms[newUniformId] = function() {
- return material.uniforms[uniformId];
- };
- }
- }
- }
-
- function getUniformType(uniformValue) {
- var uniformType = uniformValue.type;
- if (!defined(uniformType)) {
- var type = typeof uniformValue;
- if (type === 'number') {
- uniformType = 'float';
- } else if (type === 'boolean') {
- uniformType = 'bool';
- } else if (type === 'string') {
- if (/^([rgba]){1,4}$/i.test(uniformValue)) {
- uniformType = 'channels';
- } else if (uniformValue === Material.DefaultCubeMapId) {
- uniformType = 'samplerCube';
- } else {
- uniformType = 'sampler2D';
- }
- } else if (type === 'object') {
- if (isArray(uniformValue)) {
- if (uniformValue.length === 4 || uniformValue.length === 9 || uniformValue.length === 16) {
- uniformType = 'mat' + Math.sqrt(uniformValue.length);
- }
- } else {
- var numAttributes = 0;
- for ( var attribute in uniformValue) {
- if (uniformValue.hasOwnProperty(attribute)) {
- numAttributes += 1;
- }
- }
- if (numAttributes >= 2 && numAttributes <= 4) {
- uniformType = 'vec' + numAttributes;
- } else if (numAttributes === 6) {
- uniformType = 'samplerCube';
- }
- }
- }
- }
- return uniformType;
- }
-
- function createSubMaterials(material) {
- var strict = material._strict;
- var subMaterialTemplates = material._template.materials;
- for ( var subMaterialId in subMaterialTemplates) {
- if (subMaterialTemplates.hasOwnProperty(subMaterialId)) {
-
- var subMaterial = new Material({
- strict : strict,
- fabric : subMaterialTemplates[subMaterialId],
- count : material._count
- });
- material._count = subMaterial._count;
- material._uniforms = combine(material._uniforms, subMaterial._uniforms, true);
- material.materials[subMaterialId] = subMaterial;
- material._translucentFunctions = material._translucentFunctions.concat(subMaterial._translucentFunctions);
-
- var originalMethodName = 'czm_getMaterial';
- var newMethodName = originalMethodName + '_' + material._count++;
- replaceToken(subMaterial, originalMethodName, newMethodName);
- material.shaderSource = subMaterial.shaderSource + material.shaderSource;
-
- var materialMethodCall = newMethodName + '(materialInput)';
- if (replaceToken(material, subMaterialId, materialMethodCall) === 0 && strict) {
- throw new DeveloperError('strict: shader source does not use material \'' + subMaterialId + '\'.');
- }
- }
- }
- }
-
-
-
- function replaceToken(material, token, newToken, excludePeriod) {
- excludePeriod = defaultValue(excludePeriod, true);
- var count = 0;
- var suffixChars = '([\\w])?';
- var prefixChars = '([\\w' + (excludePeriod ? '.' : '') + '])?';
- var regExp = new RegExp(prefixChars + token + suffixChars, 'g');
- material.shaderSource = material.shaderSource.replace(regExp, function($0, $1, $2) {
- if ($1 || $2) {
- return $0;
- }
- count += 1;
- return newToken;
- });
- return count;
- }
- function getNumberOfTokens(material, token, excludePeriod) {
- return replaceToken(material, token, token, excludePeriod);
- }
- Material._textureCache = {
- _textures : {},
- addTexture : function(path, texture) {
- this._textures[path] = {
- texture : texture,
- count : 1
- };
- },
- getTexture : function(path) {
- var entry = this._textures[path];
- if (defined(entry)) {
- entry.count++;
- return entry.texture;
- }
- return undefined;
- },
- releaseTexture : function(path) {
- var entry = this._textures[path];
- if (defined(entry) && --entry.count === 0) {
- entry.texture = entry.texture && entry.texture.destroy();
- this._textures[path] = undefined;
- }
- }
- };
- Material._materialCache = {
- _materials : {},
- addMaterial : function(type, materialTemplate) {
- this._materials[type] = materialTemplate;
- },
- getMaterial : function(type) {
- return this._materials[type];
- }
- };
-
- Material.DefaultImageId = 'czm_defaultImage';
-
- Material.DefaultCubeMapId = 'czm_defaultCubeMap';
-
- Material.ColorType = 'Color';
- Material._materialCache.addMaterial(Material.ColorType, {
- fabric : {
- type : Material.ColorType,
- uniforms : {
- color : new Color(1.0, 0.0, 0.0, 0.5)
- },
- components : {
- diffuse : 'color.rgb',
- alpha : 'color.a'
- }
- },
- translucent : function(material) {
- return material.uniforms.color.alpha < 1.0;
- }
- });
-
- Material.ImageType = 'Image';
- Material._materialCache.addMaterial(Material.ImageType, {
- fabric : {
- type : Material.ImageType,
- uniforms : {
- image : Material.DefaultImageId,
- repeat : new Cartesian2(1.0, 1.0)
- },
- components : {
- diffuse : 'texture2D(image, fract(repeat * materialInput.st)).rgb',
- alpha : 'texture2D(image, fract(repeat * materialInput.st)).a'
- }
- },
- translucent : true
- });
-
- Material.DiffuseMapType = 'DiffuseMap';
- Material._materialCache.addMaterial(Material.DiffuseMapType, {
- fabric : {
- type : Material.DiffuseMapType,
- uniforms : {
- image : Material.DefaultImageId,
- channels : 'rgb',
- repeat : new Cartesian2(1.0, 1.0)
- },
- components : {
- diffuse : 'texture2D(image, fract(repeat * materialInput.st)).channels'
- }
- },
- translucent : false
- });
-
- Material.AlphaMapType = 'AlphaMap';
- Material._materialCache.addMaterial(Material.AlphaMapType, {
- fabric : {
- type : Material.AlphaMapType,
- uniforms : {
- image : Material.DefaultImageId,
- channel : 'a',
- repeat : new Cartesian2(1.0, 1.0)
- },
- components : {
- alpha : 'texture2D(image, fract(repeat * materialInput.st)).channel'
- }
- },
- translucent : true
- });
-
- Material.SpecularMapType = 'SpecularMap';
- Material._materialCache.addMaterial(Material.SpecularMapType, {
- fabric : {
- type : Material.SpecularMapType,
- uniforms : {
- image : Material.DefaultImageId,
- channel : 'r',
- repeat : new Cartesian2(1.0, 1.0)
- },
- components : {
- specular : 'texture2D(image, fract(repeat * materialInput.st)).channel'
- }
- },
- translucent : false
- });
-
- Material.EmissionMapType = 'EmissionMap';
- Material._materialCache.addMaterial(Material.EmissionMapType, {
- fabric : {
- type : Material.EmissionMapType,
- uniforms : {
- image : Material.DefaultImageId,
- channels : 'rgb',
- repeat : new Cartesian2(1.0, 1.0)
- },
- components : {
- emission : 'texture2D(image, fract(repeat * materialInput.st)).channels'
- }
- },
- translucent : false
- });
-
- Material.BumpMapType = 'BumpMap';
- Material._materialCache.addMaterial(Material.BumpMapType, {
- fabric : {
- type : Material.BumpMapType,
- uniforms : {
- image : Material.DefaultImageId,
- channel : 'r',
- strength : 0.8,
- repeat : new Cartesian2(1.0, 1.0)
- },
- source : BumpMapMaterial
- },
- translucent : false
- });
-
- Material.NormalMapType = 'NormalMap';
- Material._materialCache.addMaterial(Material.NormalMapType, {
- fabric : {
- type : Material.NormalMapType,
- uniforms : {
- image : Material.DefaultImageId,
- channels : 'rgb',
- strength : 0.8,
- repeat : new Cartesian2(1.0, 1.0)
- },
- source : NormalMapMaterial
- },
- translucent : false
- });
-
- Material.GridType = 'Grid';
- Material._materialCache.addMaterial(Material.GridType, {
- fabric : {
- type : Material.GridType,
- uniforms : {
- color : new Color(0.0, 1.0, 0.0, 1.0),
- cellAlpha : 0.1,
- lineCount : new Cartesian2(8.0, 8.0),
- lineThickness : new Cartesian2(1.0, 1.0),
- lineOffset : new Cartesian2(0.0, 0.0)
- },
- source : GridMaterial
- },
- translucent : function(material) {
- var uniforms = material.uniforms;
- return (uniforms.color.alpha < 1.0) || (uniforms.cellAlpha < 1.0);
- }
- });
-
- Material.StripeType = 'Stripe';
- Material._materialCache.addMaterial(Material.StripeType, {
- fabric : {
- type : Material.StripeType,
- uniforms : {
- horizontal : true,
- evenColor : new Color(1.0, 1.0, 1.0, 0.5),
- oddColor : new Color(0.0, 0.0, 1.0, 0.5),
- offset : 0.0,
- repeat : 5.0
- },
- source : StripeMaterial
- },
- translucent : function(material) {
- var uniforms = material.uniforms;
- return (uniforms.evenColor.alpha < 1.0) || (uniforms.oddColor.alpha < 0.0);
- }
- });
-
- Material.CheckerboardType = 'Checkerboard';
- Material._materialCache.addMaterial(Material.CheckerboardType, {
- fabric : {
- type : Material.CheckerboardType,
- uniforms : {
- lightColor : new Color(1.0, 1.0, 1.0, 0.5),
- darkColor : new Color(0.0, 0.0, 0.0, 0.5),
- repeat : new Cartesian2(5.0, 5.0)
- },
- source : CheckerboardMaterial
- },
- translucent : function(material) {
- var uniforms = material.uniforms;
- return (uniforms.lightColor.alpha < 1.0) || (uniforms.darkColor.alpha < 0.0);
- }
- });
-
- Material.DotType = 'Dot';
- Material._materialCache.addMaterial(Material.DotType, {
- fabric : {
- type : Material.DotType,
- uniforms : {
- lightColor : new Color(1.0, 1.0, 0.0, 0.75),
- darkColor : new Color(0.0, 1.0, 1.0, 0.75),
- repeat : new Cartesian2(5.0, 5.0)
- },
- source : DotMaterial
- },
- translucent : function(material) {
- var uniforms = material.uniforms;
- return (uniforms.lightColor.alpha < 1.0) || (uniforms.darkColor.alpha < 0.0);
- }
- });
-
- Material.WaterType = 'Water';
- Material._materialCache.addMaterial(Material.WaterType, {
- fabric : {
- type : Material.WaterType,
- uniforms : {
- baseWaterColor : new Color(0.2, 0.3, 0.6, 1.0),
- blendColor : new Color(0.0, 1.0, 0.699, 1.0),
- specularMap : Material.DefaultImageId,
- normalMap : Material.DefaultImageId,
- frequency : 10.0,
- animationSpeed : 0.01,
- amplitude : 1.0,
- specularIntensity : 0.5,
- fadeFactor : 1.0
- },
- source : WaterMaterial
- },
- translucent : function(material) {
- var uniforms = material.uniforms;
- return (uniforms.baseWaterColor.alpha < 1.0) || (uniforms.blendColor.alpha < 0.0);
- }
- });
-
- Material.RimLightingType = 'RimLighting';
- Material._materialCache.addMaterial(Material.RimLightingType, {
- fabric : {
- type : Material.RimLightingType,
- uniforms : {
- color : new Color(1.0, 0.0, 0.0, 0.7),
- rimColor : new Color(1.0, 1.0, 1.0, 0.4),
- width : 0.3
- },
- source : RimLightingMaterial
- },
- translucent : function(material) {
- var uniforms = material.uniforms;
- return (uniforms.color.alpha < 1.0) || (uniforms.rimColor.alpha < 0.0);
- }
- });
-
- Material.FadeType = 'Fade';
- Material._materialCache.addMaterial(Material.FadeType, {
- fabric : {
- type : Material.FadeType,
- uniforms : {
- fadeInColor : new Color(1.0, 0.0, 0.0, 1.0),
- fadeOutColor : new Color(0.0, 0.0, 0.0, 0.0),
- maximumDistance : 0.5,
- repeat : true,
- fadeDirection : {
- x : true,
- y : true
- },
- time : new Cartesian2(0.5, 0.5)
- },
- source : FadeMaterial
- },
- translucent : function(material) {
- var uniforms = material.uniforms;
- return (uniforms.fadeInColor.alpha < 1.0) || (uniforms.fadeOutColor.alpha < 0.0);
- }
- });
-
- Material.PolylineArrowType = 'PolylineArrow';
- Material._materialCache.addMaterial(Material.PolylineArrowType, {
- fabric : {
- type : Material.PolylineArrowType,
- uniforms : {
- color : new Color(1.0, 1.0, 1.0, 1.0)
- },
- source : PolylineArrowMaterial
- },
- translucent : true
- });
-
- Material.PolylineGlowType = 'PolylineGlow';
- Material._materialCache.addMaterial(Material.PolylineGlowType, {
- fabric : {
- type : Material.PolylineGlowType,
- uniforms : {
- color : new Color(0.0, 0.5, 1.0, 1.0),
- glowPower : 0.25
- },
- source : PolylineGlowMaterial
- },
- translucent : true
- });
-
- Material.PolylineOutlineType = 'PolylineOutline';
- Material._materialCache.addMaterial(Material.PolylineOutlineType, {
- fabric : {
- type : Material.PolylineOutlineType,
- uniforms : {
- color : new Color(1.0, 1.0, 1.0, 1.0),
- outlineColor : new Color(1.0, 0.0, 0.0, 1.0),
- outlineWidth : 1.0
- },
- source : PolylineOutlineMaterial
- },
- translucent : function(material) {
- var uniforms = material.uniforms;
- return (uniforms.color.alpha < 1.0) || (uniforms.outlineColor.alpha < 1.0);
- }
- });
- return Material;
- });
|