Skip to content

Commit

Permalink
Merge pull request #8473 from santilland/materialminmag
Browse files Browse the repository at this point in the history
Exposed minificationFilter and magnificationFilter for Material
  • Loading branch information
lilleyse committed Jan 7, 2020
2 parents b5943bc + 5600a18 commit 684e9b7
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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 `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)
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 28 additions & 4 deletions Source/Scene/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -225,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 <code>true</code> or a function that returns <code>true</code>, 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
Expand Down Expand Up @@ -298,6 +303,9 @@ import when from '../ThirdParty/when.js';
*/
this.translucent = undefined;

this._minificationFilter = defaultValue(options.minificationFilter, TextureMinificationFilter.LINEAR);
this._magnificationFilter = defaultValue(options.magnificationFilter, TextureMagnificationFilter.LINEAR);

this._strict = undefined;
this._template = undefined;
this._count = undefined;
Expand Down Expand Up @@ -415,6 +423,11 @@ import when from '../ThirdParty/when.js';
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({
Expand All @@ -424,12 +437,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
});
}

Expand Down Expand Up @@ -462,7 +477,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;
Expand Down Expand Up @@ -725,9 +744,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;
Expand Down
78 changes: 69 additions & 9 deletions Specs/Scene/MaterialSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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});
});
Expand Down Expand Up @@ -77,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)) {
Expand All @@ -90,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;
Expand Down Expand Up @@ -595,6 +601,55 @@ 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];

var ignoreBackground = true;
renderMaterial(materialLinear, ignoreBackground); // Populate the scene with the primitive prior to updating
return pollToPromise(function() {
var imageLoaded = materialLinear._loadedImages.length !== 0;
scene.renderForSpecs();
return imageLoaded;
}).then(function() {
renderMaterial(materialLinear, ignoreBackground, function(rgba) {
expect(rgba).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);
});
});
});
});

it('throws with source and components in same template', function () {
expect(function() {
return new Material({
Expand Down Expand Up @@ -788,10 +843,13 @@ describe('Scene/Material', function() {
var material = Material.fromType(Material.DiffuseMapType);
material.uniforms.image = './Data/Images/Green.png';

pollToPromise(function() {
return material._loadedImages.length !== 0;
renderMaterial(material);

return pollToPromise(function() {
var result = material._loadedImages.length !== 0;
scene.renderForSpecs();
return result;
}).then(function() {
renderMaterial(material);
material.destroy();
expect(material.isDestroyed()).toEqual(true);
});
Expand Down Expand Up @@ -820,11 +878,13 @@ describe('Scene/Material', function() {
});
material.materials.diffuseMap.uniforms.image = './Data/Images/Green.png';

pollToPromise(function() {
return material.materials.diffuseMap._loadedImages.length !== 0;
}).then(function() {
renderMaterial(material);
renderMaterial(material);

return pollToPromise(function() {
var result = material.materials.diffuseMap._loadedImages.length !== 0;
scene.renderForSpecs();
return result;
}).then(function() {
var diffuseMap = material.materials.diffuseMap;
material.destroy();
expect(material.isDestroyed()).toEqual(true);
Expand Down

0 comments on commit 684e9b7

Please sign in to comment.