# Imagery Layer adjustments/filtering during render

**URL:** <https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799>\
**Category:** CesiumJS\
**Created:** [April 13, 2018, 8:11pm UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799 "2018-04-13T20:11:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shahin\_Roboubi](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Shahin\_Roboubi](https://community.cesium.com/u/Shahin_Roboubi)\
**Post date:** [April 13, 2018, 8:11pm UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799/1 "2018-04-13T20:11:30Z")

</div>

**Imagery layer already provides some built in adjustments, like brightness/contrast/hue/saturation, which I believe are performed by shaders in the rendering pipeline. What is the best way to add my own custom adjustments to an imagery layer. For example, I would like to dynamically adjust the brightness of pixels per RGB channel (brighten blue, dim red, etc). Is there any way to add my own shader for a specific imagery layer (and pass parameters to it)? Or perhaps, is there another way to do this without shaders?**

**Thanks.**

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [April 16, 2018, 3:29pm UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799/2 "2018-04-16T15:29:40Z")

</div>

There is no hook for you to add your own shader per imagery layer. All the shading effects are done when rendering the globe surface, and are performed in the globe’s shaders.

If you would like to modify the Source code to achieve this effect, you would need to create new properties on the ImageryLayer itself, pass these values to the shaders, and modify the shaders.

The values are passed to the globe surface shaders in [GlobeSurfaceShaderSet.js](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/GlobeSurfaceShaderSet.js), and the shader files themselves are in [GlobeVS.js](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Shaders/GlobeVS.glsl)and [GlobeFS.js](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Shaders/GlobeFS.glsl).

I’ve opened an issue to track adding the ability to do this in Cesium without modifying the source code ([#6449](https://github.com/AnalyticalGraphicsInc/cesium/issues/6449))We would welcome a PR that is a generic solution, and would be more than happy to provide guidance and review code!

Thanks,

Gabby

---

<div class="post-metadata">

**Author:** ![Shahin\_Roboubi](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Shahin\_Roboubi](https://community.cesium.com/u/Shahin_Roboubi)\
**Post date:** [April 16, 2018, 8:47pm UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799/3 "2018-04-16T20:47:07Z")

</div>

So the shaders are at a global level, but the parameters are per layer… they must be otherwise I wouldn’t be able to set the brightness/contrast/etc individually per layer. After some more thought I believe that modifying the shaders might not be appropriate for what I need. Ideally I would like to:

1. Adjust some parameters on an imagery layer

2. Have the image rendered according to these parameters

3. Have the imagery data be updated according to these parameters (for example if I create a histogram of the image, I want to see it updated)

Alternatively, I can implement my own imagery provider, wrapping the “real” one, and applying my adjustments to the image data. However I would need a way to tell cesium to re-request the image when adjustments are made, so that I don’t have to wait for a zoom event to refresh the image.

Note, I found a similar post from a few years ago, any update on this: [https://groups.google.com/forum/#!topic/cesium-dev/aysBQWn9c88](https://groups.google.com/forum/#!topic/cesium-dev/aysBQWn9c88)

Thanks a lot for the quick replies!

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [April 18, 2018, 4:01pm UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799/4 "2018-04-18T16:01:51Z")

</div>

Custom imagery adjustments or processing would definitely be a powerful feature! A few of the Cesium devs have been talking about it in regards to raster analysis. Doing the processing in the shader would most likely be the best option performance-wise. However we’d need to implement a better hook for the custom shader code. This would not modify the underlying imagery texture, and would just change how the imagery is rendered.

For the histogram however, it sounds like what you need to do is grabbing the texture itself like you suggested and then updating the UI.

[ImageryProvider.loadImage](https://github.com/AnalyticalGraphicsInc/cesium/blob/1.44/Source/Scene/ImageryProvider.js#L335) is where the image itself is returned when requested.

It’s possible trigger the image provider to update. We do that with time for [WMTS Imagery](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/index.html?src=Web%20Map%20Tile%20Service%20with%20Time.html&label=Showcases). Take a look at the [WebMapTileServiceImageryProiver.js](https://github.com/AnalyticalGraphicsInc/cesium/blob/1.44/Source/Scene/WebMapTileServiceImageryProvider.js) source if you’d like to implement your own imagery provider.

---

<div class="post-metadata">

**Author:** ![Shahin\_Roboubi](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Shahin\_Roboubi](https://community.cesium.com/u/Shahin_Roboubi)\
**Post date:** [April 21, 2018, 12:56am UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799/5 "2018-04-21T00:56:49Z")

</div>

I’m having some trouble finding the code that triggers cesium to re-fetch imagery… maybe I’m not looking in the right place? I basically need to tell cesium to fetch imagery data programatically, instead of as a result of a zoom level change. If this is done in WebMapTileServiceImageryProvider, could you help me find the lines of code that make the call (I assume periodically)?

Thanks.

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [April 23, 2018, 1:57pm UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799/6 "2018-04-23T13:57:40Z")

</div>

**WebMapTileServiceImageryProvider** [has an instance](https://github.com/AnalyticalGraphicsInc/cesium/blob/1.44/Source/Scene/WebMapTileServiceImageryProvider.js#L198) of **TimeDynamicImagery** , which watches for the specified interval and calls that [**requestImagery** function in **WebMapTileServiceProvider**](https://github.com/AnalyticalGraphicsInc/cesium/blob/1.44/Source/Scene/WebMapTileServiceImageryProvider.js#L241). Instead of using **TimeDynamicImagery** to trigger the request, you would trigger it when your UI changes.

Let me know if that doesn’t sufficiently answer your question.

---

<div class="post-metadata">

**Author:** ![Shahin\_Roboubi](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Shahin\_Roboubi](https://community.cesium.com/u/Shahin_Roboubi)\
**Post date:** [April 23, 2018, 9:50pm UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799/7 "2018-04-23T21:50:38Z")

</div>

From what I can see, the TimeDynamicImagery only calls requestImage inside addToCache(). This is called when the WebMapTileServiceImageryProvider.requestImage tries to access an image that is not in cache, or when preloading the image for an upcoming time interval.  
After looking at the stack trace, the actual _source_ of the imageryProvider.requestImage call (for any provider), and the consumer of the returned image, seems to always be the scene render function. Basically it looks like:

Scene.render() -\> … -\> TileImagery.processStateMachine() -\> ImageryLayer.\_requestImagery() -\> anyProvider.requestImage()

The only way we can go from TileImagery.processStateMachine() to ImageryLayer.\_requestImagery() is if the tile has ImageryState.UNLOADED. So I think my problem is that I need to set the tile states to UNLOADED. I’m not sure how to do that if all I have is a handle to the Imagery Provider and the Imagery Layer. How does that happen for WebMapTileServiceImageryProvider?

For the WMTS example, it seems to happen when the time is being advanced and also when a user manually adjusts the time interval. In the case of a WMS provided imagery layer, it only happens when a new zoom level of a given tile is needed.

Thanks.

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [April 25, 2018, 1:59pm UTC](https://community.cesium.com/t/imagery-layer-adjustments-filtering-during-render/6799/8 "2018-04-25T13:59:06Z")

</div>

Maybe create something similar to TimeDynamicImagery which requests a new image periodically, and inside your custom provider requestImage function, set an isDirty flag that will only request after you make a change in your UI.
