Set interpolation (nearest neighbor) type for material used for rectangle primitive

1. A concise explanation of the problem you’re experiencing.

I am trying to set the interpolation type of a material to “Nearest neighbor”, i can’t find out how to do it.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

I managed to do it for an imagerylayer as follows:


imageryLayer.splitDirection = Cesium.ImagerySplitDirection.RIGHT;

imageryLayer.minificationFilter = Cesium.TextureMinificationFilter.NEAREST;

imageryLayer.magnificationFilter = Cesium.TextureMagnificationFilter.NEAREST;

It seems it is possible to set this for a texture object with the setSampler method (https://cesium.com/downloads/cesiumjs/releases/b18/Documentation/Texture.html),

but i don’t know how exactly Textures and Materials interact, i don’t really see a way to actually set the “TextureMagnification” for Materials.

I tried to define my own fabric and see if i could set the sampler there somehow but o don’t find much information

on what is all possible with the fabric approach.


var fabric = {

type : 'customMaterial',

uniforms : {

image : 'someimage.png

},

components : {

diffuse : 'texture2D(image, materialInput.st).rgb'

},

sampler: Cesium.TextureMinificationFilter.NEAREST

};

var newmat = new Cesium.Material({

fabric : fabric

});

**3. Context. Why do you need to do this? We might know a better way to accomplish your goal.**

I have relatively low resolved textures that look horrible (not usable) when stretched over a larger rectangle

and i would like to use nearest neighbor to solve that. I also tried deactivating antialiasing completely with the fxaa parameter of the viewer, this does also not solve the issue.

**4. The Cesium version you're using, your operating system and browser.**

Does not really apply

Thanks for any help!

Kind regards,

Daniel

Looks like there indeed isn’t an option to set the sampler, but there is a feature request for this here, which I’ve just bumped: https://github.com/AnalyticalGraphicsInc/cesium/issues/8328

Hello Omar,

thanks for the super quick answer and bumping the feature request, lets see how it evolves with priority.

If i get some pointers how textures relate to materials i might be able to have a look myself, i must say i’m a bit confused

on how the pipeline works. I tried to instantiate a texture object myself but the documentation is a bit thin there,

i found this example (https://gist.github.com/mramato/5146500e57d675fb1ee5):

var texture = viewer.scene.context.createTexture2D({

source : image

});

but then i found some commit where the texture creation was moved away from the scene context to the texture object…

and then the createTexture2D was dropped for something else… in any case a bit lost.

Kind regards,

Daniel

Daniel,

If you can invest some time into adding this feature and contributing a pull request that’d definitely be appreciated! Since Texture and Sampler are both private classes, I think you’d need to do something similar to how ImageryLayer does it, which takes in a min/mag filter here:

It then internally creates the sampler here and passes it to the Texture constructor below:

You would do this in the Material class, take in a min/mag filter, create a sampler, pass it when the Texture is created here:

This would make it work at the Primitive level, when creating a material directly, like in this Sandcastle example:

https://sandcastle.cesium.com/index.html?src=Materials.html

It would be a separate feature to link it up with the Entity API. Hope this helps, let me know if you run into any other issues! You can always open a draft PR if you have an implementation that works but are unsure if it’s the best approach.

Hi Omar,

thanks for all the pointers, gave it a try :slight_smile:

https://github.com/AnalyticalGraphicsInc/cesium/pull/8473

at least i got it working for me, hope it makes it to the main branch at some point.

Kind regards,

Daniel

Are there plans to add this?