From 1c9d6da0da2601cc2e8679cef131dc5708e325d2 Mon Sep 17 00:00:00 2001 From: santilland Date: Wed, 18 Dec 2019 15:51:59 +0100 Subject: [PATCH 1/8] Exposed minificationFilter and magnificationFilter for the Material class --- CONTRIBUTORS.md | 2 ++ Source/Scene/Material.js | 54 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6346f2b35a77..399f335b9a65 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -140,6 +140,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Ian Lilley](https://github.com/IanLilleyT) * [Northrop Grumman](http://www.northropgrumman.com) * [Joseph Stein](https://github.com/nahgrin) +* [EOX IT Services GmbH](https://eox.at) + * [Daniel Santillan](https://github.com/santilland) ## [Individual CLA](Documentation/Contributors/CLAs/individual-contributor-license-agreement-v1.0.pdf) * [Victor Berchet](https://github.com/vicb) diff --git a/Source/Scene/Material.js b/Source/Scene/Material.js index 36b7041a0f3a..e8db06436089 100644 --- a/Source/Scene/Material.js +++ b/Source/Scene/Material.js @@ -31,8 +31,11 @@ import PolylineDashMaterial from '../Shaders/Materials/PolylineDashMaterial.js'; import PolylineGlowMaterial from '../Shaders/Materials/PolylineGlowMaterial.js'; import PolylineOutlineMaterial from '../Shaders/Materials/PolylineOutlineMaterial.js'; import RimLightingMaterial from '../Shaders/Materials/RimLightingMaterial.js'; +import Sampler from '../Renderer/Sampler.js'; import SlopeRampMaterial from '../Shaders/Materials/SlopeRampMaterial.js'; import StripeMaterial from '../Shaders/Materials/StripeMaterial.js'; +import TextureMagnificationFilter from '../Renderer/TextureMagnificationFilter.js'; +import TextureMinificationFilter from '../Renderer/TextureMinificationFilter.js'; import WaterMaterial from '../Shaders/Materials/Water.js'; import when from '../ThirdParty/when.js'; @@ -298,6 +301,30 @@ import when from '../ThirdParty/when.js'; */ this.translucent = undefined; + /** + * The {@link TextureMinificationFilter} to apply to this material. + * Possible values are {@link TextureMinificationFilter.LINEAR} (the default) + * and {@link TextureMinificationFilter.NEAREST}. + * + * To take effect, this property must be set before texture is created + * + * @type {TextureMinificationFilter} + * @default {@link Material.DEFAULT_MINIFICATION_FILTER} + */ + this.minificationFilter = defaultValue(options.minificationFilter, Material.DEFAULT_MINIFICATION_FILTER); + + /** + * The {@link TextureMagnificationFilter} to apply to this layer. + * Possible values are {@link TextureMagnificationFilter.LINEAR} (the default) + * and {@link TextureMagnificationFilter.NEAREST}. + * + * To take effect, this property must be set before texture is created + * + * @type {TextureMagnificationFilter} + * @default {@link Material.DEFAULT_MAGNIFICATION_FILTER} + */ + this.magnificationFilter = defaultValue(options.magnificationFilter, Material.DEFAULT_MAGNIFICATION_FILTER); + this._strict = undefined; this._template = undefined; this._count = undefined; @@ -325,6 +352,22 @@ import when from '../ThirdParty/when.js'; } } + /** + * This value is used as the default texture minification filter for the imagery layer if one is not provided + * during construction or by the imagery provider. + * @type {TextureMinificationFilter} + * @default TextureMinificationFilter.LINEAR + */ + Material.DEFAULT_MINIFICATION_FILTER = TextureMinificationFilter.LINEAR; + + /** + * This value is used as the default texture magnification filter for the imagery layer if one is not provided + * during construction or by the imagery provider. + * @type {TextureMagnificationFilter} + * @default TextureMagnificationFilter.LINEAR + */ + Material.DEFAULT_MAGNIFICATION_FILTER = TextureMagnificationFilter.LINEAR; + // Cached list of combined uniform names indexed by type. // Used to get the list of uniforms in the same order. Material._uniformList = {}; @@ -410,6 +453,11 @@ import when from '../ThirdParty/when.js'; var loadedImages = this._loadedImages; var length = loadedImages.length; + var sampler = new Sampler({ + minificationFilter : this.minificationFilter, + magnificationFilter : this.magnificationFilter + }); + for (i = 0; i < length; ++i) { var loadedImage = loadedImages[i]; uniformId = loadedImage.id; @@ -424,12 +472,14 @@ import when from '../ThirdParty/when.js'; height : image.height, source : { arrayBufferView : image.bufferView - } + }, + sampler : sampler }); } else { texture = new Texture({ context : context, - source : image + source : image, + sampler : sampler }); } From e9a9545f803de53738f719b47aec0952dbf08293 Mon Sep 17 00:00:00 2001 From: Ian Lilley Date: Mon, 6 Jan 2020 19:51:06 -0500 Subject: [PATCH 2/8] changes and test for minmag material PR --- CHANGES.md | 5 ++++ Source/Scene/Material.js | 50 ++++++++++++-------------------- Specs/Scene/MaterialSpec.js | 58 +++++++++++++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 38 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 72c8db6b448e..cdeee25e67ec 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ Change Log ========== +### 1.66.0 - 2020-02-03 + +##### Additions :tada: +* Added `magnificationFilter` and `minificationFilter` options to materials to control texture filtering. [#8473](https://github.com/AnalyticalGraphicsInc/cesium/pull/8473) + ### 1.65.0 - 2019-01-02 ##### Fixes :wrench: diff --git a/Source/Scene/Material.js b/Source/Scene/Material.js index e8db06436089..5dbc5169bafc 100644 --- a/Source/Scene/Material.js +++ b/Source/Scene/Material.js @@ -303,27 +303,25 @@ import when from '../ThirdParty/when.js'; /** * The {@link TextureMinificationFilter} to apply to this material. - * Possible values are {@link TextureMinificationFilter.LINEAR} (the default) - * and {@link TextureMinificationFilter.NEAREST}. + * The default value is {@link TextureMinificationFilter.LINEAR}. * - * To take effect, this property must be set before texture is created + * To take effect, this property must be set before the texture is created. * * @type {TextureMinificationFilter} - * @default {@link Material.DEFAULT_MINIFICATION_FILTER} + * @default {@link TextureMinificationFilter.LINEAR} */ - this.minificationFilter = defaultValue(options.minificationFilter, Material.DEFAULT_MINIFICATION_FILTER); + this.minificationFilter = defaultValue(options.minificationFilter, TextureMinificationFilter.LINEAR); /** * The {@link TextureMagnificationFilter} to apply to this layer. - * Possible values are {@link TextureMagnificationFilter.LINEAR} (the default) - * and {@link TextureMagnificationFilter.NEAREST}. + * The default value is {@link TextureMagnificationFilter.LINEAR}. * - * To take effect, this property must be set before texture is created + * To take effect, this property must be set before the texture is created. * * @type {TextureMagnificationFilter} - * @default {@link Material.DEFAULT_MAGNIFICATION_FILTER} + * @default {@link TextureMagnificationFilter.LINEAR} */ - this.magnificationFilter = defaultValue(options.magnificationFilter, Material.DEFAULT_MAGNIFICATION_FILTER); + this.magnificationFilter = defaultValue(options.magnificationFilter, TextureMagnificationFilter.LINEAR); this._strict = undefined; this._template = undefined; @@ -352,22 +350,6 @@ import when from '../ThirdParty/when.js'; } } - /** - * This value is used as the default texture minification filter for the imagery layer if one is not provided - * during construction or by the imagery provider. - * @type {TextureMinificationFilter} - * @default TextureMinificationFilter.LINEAR - */ - Material.DEFAULT_MINIFICATION_FILTER = TextureMinificationFilter.LINEAR; - - /** - * This value is used as the default texture magnification filter for the imagery layer if one is not provided - * during construction or by the imagery provider. - * @type {TextureMagnificationFilter} - * @default TextureMagnificationFilter.LINEAR - */ - Material.DEFAULT_MAGNIFICATION_FILTER = TextureMagnificationFilter.LINEAR; - // Cached list of combined uniform names indexed by type. // Used to get the list of uniforms in the same order. Material._uniformList = {}; @@ -453,16 +435,16 @@ import when from '../ThirdParty/when.js'; var loadedImages = this._loadedImages; var length = loadedImages.length; - var sampler = new Sampler({ - minificationFilter : this.minificationFilter, - magnificationFilter : this.magnificationFilter - }); - for (i = 0; i < length; ++i) { var loadedImage = loadedImages[i]; uniformId = loadedImage.id; var image = loadedImage.image; + var sampler = new Sampler({ + minificationFilter : this.minificationFilter, + magnificationFilter : this.magnificationFilter + }); + var texture; if (defined(image.internalFormat)) { texture = new Texture({ @@ -512,7 +494,11 @@ import when from '../ThirdParty/when.js'; negativeY : images[3], positiveZ : images[4], negativeZ : images[5] - } + }, + sampler : new Sampler({ + minificationFilter : this.minificationFilter, + magnificationFilter : this.magnificationFilter + }) }); this._textures[uniformId] = cubeMap; diff --git a/Specs/Scene/MaterialSpec.js b/Specs/Scene/MaterialSpec.js index 6bb0f20456d2..4d38ac2d0f5a 100644 --- a/Specs/Scene/MaterialSpec.js +++ b/Specs/Scene/MaterialSpec.js @@ -11,6 +11,8 @@ import { Material } from '../../Source/Cesium.js'; import { MaterialAppearance } from '../../Source/Cesium.js'; import { PolylineCollection } from '../../Source/Cesium.js'; import { Primitive } from '../../Source/Cesium.js'; +import { TextureMagnificationFilter } from '../../Source/Cesium.js'; +import { TextureMinificationFilter } from '../../Source/Cesium.js'; import createScene from '../createScene.js'; import pollToPromise from '../pollToPromise.js'; @@ -20,13 +22,13 @@ describe('Scene/Material', function() { var rectangle = Rectangle.fromDegrees(-10.0, -10.0, 10.0, 10.0); var polygon; - var backgroundColor = [0, 0, 255, 255]; + var backgroundColor = [0, 0, 128, 255]; var polylines; var polyline; beforeAll(function() { scene = createScene(); - Color.unpack(backgroundColor, 0, scene.backgroundColor); + Color.fromBytes(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3], scene.backgroundColor); scene.primitives.destroyPrimitives = false; scene.camera.setView({destination : rectangle}); }); @@ -595,6 +597,46 @@ describe('Scene/Material', function() { }); }); + it('creates material with custom texture filter', function() { + var materialLinear = new Material({ + fabric : { + type : 'DiffuseMap', + uniforms : { + image : './Data/Images/BlueOverRed.png' + } + }, + minificationFilter : TextureMinificationFilter.LINEAR, + magnificationFilter : TextureMagnificationFilter.LINEAR + }); + + var materialNearest = new Material({ + fabric : { + type : 'DiffuseMap', + uniforms : { + image : './Data/Images/BlueOverRed.png' + } + }, + minificationFilter : TextureMinificationFilter.NEAREST, + magnificationFilter : TextureMagnificationFilter.NEAREST + }); + + var purple = [127, 0, 127, 255]; + + return pollToPromise(function() { + var result = materialLinear._loadedImages.length !== 0 || materialNearest._loadedImages.length !== 0; + materialLinear.update(scene.context); + materialNearest.update(scene.context); + return result; + }).then(function() { + renderMaterial(materialLinear, true, function(rgba) { + expect(rgba).toEqualEpsilon(purple, 1); + }); + renderMaterial(materialNearest, true, function(rgba) { + expect(rgba).not.toEqualEpsilon(purple, 1); + }); + }); + }); + it('throws with source and components in same template', function () { expect(function() { return new Material({ @@ -788,8 +830,10 @@ describe('Scene/Material', function() { var material = Material.fromType(Material.DiffuseMapType); material.uniforms.image = './Data/Images/Green.png'; - pollToPromise(function() { - return material._loadedImages.length !== 0; + return pollToPromise(function() { + var result = material._loadedImages.length !== 0; + material.update(scene.context); + return result; }).then(function() { renderMaterial(material); material.destroy(); @@ -820,8 +864,10 @@ describe('Scene/Material', function() { }); material.materials.diffuseMap.uniforms.image = './Data/Images/Green.png'; - pollToPromise(function() { - return material.materials.diffuseMap._loadedImages.length !== 0; + return pollToPromise(function() { + var result = material.materials.diffuseMap._loadedImages.length !== 0; + material.update(scene.context); + return result; }).then(function() { renderMaterial(material); From 4f29d8e3b87a717ea11b251b1e971c97f95420e0 Mon Sep 17 00:00:00 2001 From: Ian Lilley Date: Mon, 6 Jan 2020 19:53:45 -0500 Subject: [PATCH 3/8] Update CHANGES.md Missed newline --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 44d111131221..c3cedfa27a3f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ Change Log ### 1.66.0 - 2020-02-03 ##### Additions :tada: + * Added `Globe.showSkirts` to support the ability to hide terrain skirts when viewing terrain from below the surface. [#8489](https://github.com/AnalyticalGraphicsInc/cesium/pull/8489) * Fixed `BoundingSphere.projectTo2D` when the bounding sphere’s center is at the origin. [#8482](https://github.com/AnalyticalGraphicsInc/cesium/pull/8482) * Added `magnificationFilter` and `minificationFilter` options to materials to control texture filtering. [#8473](https://github.com/AnalyticalGraphicsInc/cesium/pull/8473) From f6558c68054cabe890b373155dadad80a9befa16 Mon Sep 17 00:00:00 2001 From: Ian Lilley Date: Mon, 6 Jan 2020 19:54:59 -0500 Subject: [PATCH 4/8] Update CHANGES.md Fixed wording in CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c3cedfa27a3f..77192e4c6e89 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,7 @@ Change Log * Added `Globe.showSkirts` to support the ability to hide terrain skirts when viewing terrain from below the surface. [#8489](https://github.com/AnalyticalGraphicsInc/cesium/pull/8489) * Fixed `BoundingSphere.projectTo2D` when the bounding sphere’s center is at the origin. [#8482](https://github.com/AnalyticalGraphicsInc/cesium/pull/8482) -* Added `magnificationFilter` and `minificationFilter` options to materials to control texture filtering. [#8473](https://github.com/AnalyticalGraphicsInc/cesium/pull/8473) +* Added `minificationFilter` and `magnificationFilter` options to `Material` to control texture filtering. [#8473](https://github.com/AnalyticalGraphicsInc/cesium/pull/8473) ##### Fixes :wrench: * Fixed a bug where the camera could go underground during mouse navigation. [#8504](https://github.com/AnalyticalGraphicsInc/cesium/pull/8504) From 2693e7c903dbd4da136d72baf42c94da558fa2cc Mon Sep 17 00:00:00 2001 From: Ian Lilley Date: Mon, 6 Jan 2020 20:42:12 -0500 Subject: [PATCH 5/8] made specs use scene render instead of material update --- Specs/Scene/MaterialSpec.js | 38 +++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Specs/Scene/MaterialSpec.js b/Specs/Scene/MaterialSpec.js index 4d38ac2d0f5a..fdce8eca34d4 100644 --- a/Specs/Scene/MaterialSpec.js +++ b/Specs/Scene/MaterialSpec.js @@ -79,7 +79,9 @@ describe('Scene/Material', function() { expect(scene).toRender(backgroundColor); } + scene.primitives.removeAll(); scene.primitives.add(polygon); + expect(scene).toRenderAndCall(function(rgba) { expect(rgba).not.toEqual(backgroundColor); if (defined(callback)) { @@ -92,7 +94,9 @@ describe('Scene/Material', function() { polyline.material = material; expect(scene).toRender(backgroundColor); + scene.primitives.removeAll(); scene.primitives.add(polylines); + var result; expect(scene).toRenderAndCall(function(rgba) { result = rgba; @@ -622,17 +626,26 @@ describe('Scene/Material', function() { var purple = [127, 0, 127, 255]; + var ignoreBackground = true; + renderMaterial(materialLinear, ignoreBackground); // Populate the scene with the primitive prior to updating return pollToPromise(function() { - var result = materialLinear._loadedImages.length !== 0 || materialNearest._loadedImages.length !== 0; - materialLinear.update(scene.context); - materialNearest.update(scene.context); - return result; + var imageLoaded = materialLinear._loadedImages.length !== 0; + scene.renderForSpecs(); + return imageLoaded; }).then(function() { - renderMaterial(materialLinear, true, function(rgba) { + renderMaterial(materialLinear, ignoreBackground, function(rgba) { expect(rgba).toEqualEpsilon(purple, 1); }); - renderMaterial(materialNearest, true, function(rgba) { - expect(rgba).not.toEqualEpsilon(purple, 1); + }).then(function() { + renderMaterial(materialNearest, ignoreBackground); // Populate the scene with the primitive prior to updating + return pollToPromise(function() { + var imageLoaded = materialNearest._loadedImages.length !== 0; + scene.renderForSpecs(); + return imageLoaded; + }).then(function() { + renderMaterial(materialNearest, ignoreBackground, function(rgba) { + expect(rgba).not.toEqualEpsilon(purple, 1); + }); }); }); }); @@ -830,12 +843,13 @@ describe('Scene/Material', function() { var material = Material.fromType(Material.DiffuseMapType); material.uniforms.image = './Data/Images/Green.png'; + renderMaterial(material); + return pollToPromise(function() { var result = material._loadedImages.length !== 0; - material.update(scene.context); + scene.renderForSpecs(); return result; }).then(function() { - renderMaterial(material); material.destroy(); expect(material.isDestroyed()).toEqual(true); }); @@ -864,13 +878,13 @@ describe('Scene/Material', function() { }); material.materials.diffuseMap.uniforms.image = './Data/Images/Green.png'; + renderMaterial(material); + return pollToPromise(function() { var result = material.materials.diffuseMap._loadedImages.length !== 0; - material.update(scene.context); + scene.renderForSpecs(); return result; }).then(function() { - renderMaterial(material); - var diffuseMap = material.materials.diffuseMap; material.destroy(); expect(material.isDestroyed()).toEqual(true); From b4e65509b884b127a595fa54403c60905e723a13 Mon Sep 17 00:00:00 2001 From: Ian Lilley Date: Tue, 7 Jan 2020 09:09:29 -0500 Subject: [PATCH 6/8] Update Material.js Changed wording material filter documentation --- Source/Scene/Material.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Material.js b/Source/Scene/Material.js index 5dbc5169bafc..6bfddae6dd48 100644 --- a/Source/Scene/Material.js +++ b/Source/Scene/Material.js @@ -313,7 +313,7 @@ import when from '../ThirdParty/when.js'; this.minificationFilter = defaultValue(options.minificationFilter, TextureMinificationFilter.LINEAR); /** - * The {@link TextureMagnificationFilter} to apply to this layer. + * The {@link TextureMagnificationFilter} to apply to this material. * The default value is {@link TextureMagnificationFilter.LINEAR}. * * To take effect, this property must be set before the texture is created. From d1bd5ba7c36dc2074a4b76c50c89ccc385e4ec53 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 7 Jan 2020 11:12:19 -0500 Subject: [PATCH 7/8] Add sampler to video materials --- Source/Scene/Material.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Scene/Material.js b/Source/Scene/Material.js index 6bfddae6dd48..c895fd25cd3e 100644 --- a/Source/Scene/Material.js +++ b/Source/Scene/Material.js @@ -761,9 +761,14 @@ import when from '../ThirdParty/when.js'; } if (!defined(texture) || texture === context.defaultTexture) { + var sampler = new Sampler({ + minificationFilter : material.minificationFilter, + magnificationFilter : material.magnificationFilter + }); texture = new Texture({ context : context, - source : uniformValue + source : uniformValue, + sampler : sampler }); material._textures[uniformId] = texture; return; From 5600a18eebdffa1ece2feec2a5b1de466eb7c561 Mon Sep 17 00:00:00 2001 From: Ian Lilley Date: Tue, 7 Jan 2020 18:05:56 -0500 Subject: [PATCH 8/8] fixed documentation --- Source/Scene/Material.js | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/Source/Scene/Material.js b/Source/Scene/Material.js index c895fd25cd3e..91f950d5d022 100644 --- a/Source/Scene/Material.js +++ b/Source/Scene/Material.js @@ -228,6 +228,8 @@ import when from '../ThirdParty/when.js'; * @param {Boolean} [options.strict=false] Throws errors for issues that would normally be ignored, including unused uniforms or materials. * @param {Boolean|Function} [options.translucent=true] When true or a function that returns true, the geometry * with this material is expected to appear translucent. + * @param {TextureMinificationFilter} [options.minificationFilter=TextureMinificationFilter.LINEAR] The {@link TextureMinificationFilter} to apply to this material's textures. + * @param {TextureMagnificationFilter} [options.magnificationFilter=TextureMagnificationFilter.LINEAR] The {@link TextureMagnificationFilter} to apply to this material's textures. * @param {Object} options.fabric The fabric JSON used to generate the material. * * @constructor @@ -301,27 +303,8 @@ import when from '../ThirdParty/when.js'; */ this.translucent = undefined; - /** - * The {@link TextureMinificationFilter} to apply to this material. - * The default value is {@link TextureMinificationFilter.LINEAR}. - * - * To take effect, this property must be set before the texture is created. - * - * @type {TextureMinificationFilter} - * @default {@link TextureMinificationFilter.LINEAR} - */ - this.minificationFilter = defaultValue(options.minificationFilter, TextureMinificationFilter.LINEAR); - - /** - * The {@link TextureMagnificationFilter} to apply to this material. - * The default value is {@link TextureMagnificationFilter.LINEAR}. - * - * To take effect, this property must be set before the texture is created. - * - * @type {TextureMagnificationFilter} - * @default {@link TextureMagnificationFilter.LINEAR} - */ - this.magnificationFilter = defaultValue(options.magnificationFilter, TextureMagnificationFilter.LINEAR); + this._minificationFilter = defaultValue(options.minificationFilter, TextureMinificationFilter.LINEAR); + this._magnificationFilter = defaultValue(options.magnificationFilter, TextureMagnificationFilter.LINEAR); this._strict = undefined; this._template = undefined; @@ -441,8 +424,8 @@ import when from '../ThirdParty/when.js'; var image = loadedImage.image; var sampler = new Sampler({ - minificationFilter : this.minificationFilter, - magnificationFilter : this.magnificationFilter + minificationFilter : this._minificationFilter, + magnificationFilter : this._magnificationFilter }); var texture; @@ -496,8 +479,8 @@ import when from '../ThirdParty/when.js'; negativeZ : images[5] }, sampler : new Sampler({ - minificationFilter : this.minificationFilter, - magnificationFilter : this.magnificationFilter + minificationFilter : this._minificationFilter, + magnificationFilter : this._magnificationFilter }) }); @@ -762,8 +745,8 @@ import when from '../ThirdParty/when.js'; if (!defined(texture) || texture === context.defaultTexture) { var sampler = new Sampler({ - minificationFilter : material.minificationFilter, - magnificationFilter : material.magnificationFilter + minificationFilter : material._minificationFilter, + magnificationFilter : material._magnificationFilter }); texture = new Texture({ context : context,