# Normal map shading for terrain tiles

**URL:** <https://community.cesium.com/t/normal-map-shading-for-terrain-tiles/8026>\
**Category:** CesiumJS\
**Created:** [February 21, 2019, 9:17am UTC](https://community.cesium.com/t/normal-map-shading-for-terrain-tiles/8026 "2019-02-21T09:17:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel\_Massing](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@Manuel\_Massing](https://community.cesium.com/u/Manuel_Massing)\
**Post date:** [February 21, 2019, 9:17am UTC](https://community.cesium.com/t/normal-map-shading-for-terrain-tiles/8026/1 "2019-02-21T09:17:17Z")

</div>

Dear cesium developers,

I am currently looking for a way to add normal map shading  
to heightmap-based terrain (backed by an elevation TMS), and I  
have a few thoughts/questions I'd like to run by you:

1) Implementing normal map shading via terrain renderer

I would love an approach which can work directly on the TMS  
elevation data, but implementing this in the cesium terrain renderer seems like a lot of work.

Do you have an idea for a quicker way to implement this (e.g. adding pre-generated normal maps as image layer, and using a custom fragment shader)?

2) HeightMap-based terrain

Is support for heightmap-based terrain being phased out? Just  
asking because from what I remember cesium had more raster-based  
terrain providers in older versions, I don't want to bet on  
the wrong horse!

3) Implementing normal map shading on 3d tiles

Alternatively, I have thought about pre-processing the elevation data into 3d tiles, with accompanying normal maps. Does cesium currently support projectively texturing 3d tiles from imagery layers?

Thanks for reading this, and I'm grateful for your comments & suggestions!

Regards,

Manuel

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [February 22, 2019, 10:28pm UTC](https://community.cesium.com/t/normal-map-shading-for-terrain-tiles/8026/2 "2019-02-22T22:28:18Z")

</div>

Are you trying to do something like this?

> **[Cesium Sandcastle](https://sandcastle.cesium.com/?src=Globe%20Materials.html)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

I believe the way Globe Materials work is the shader uses the normals to color the pixels. There was also a recent PR to add the aspect as well so that it can be used to color:

> <https://github.com/CesiumGS/cesium/pull/7415>

As for heightmap-based terrain, it’s still supported, but we’ve been doing a lot more work on quantized mesh. There’s some more discussion on that in this thread: [https://groups.google.com/d/msg/cesium-dev/KmEELn7LXAo/DSHrFLVtGgAJ](https://groups.google.com/d/msg/cesium-dev/KmEELn7LXAo/DSHrFLVtGgAJ)

---

<div class="post-metadata">

**Author:** ![Benjamin\_Tolputt](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Benjamin\_Tolputt](https://community.cesium.com/u/Benjamin_Tolputt)\
**Post date:** [February 23, 2019, 1:52am UTC](https://community.cesium.com/t/normal-map-shading-for-terrain-tiles/8026/3 "2019-02-23T01:52:26Z")

</div>

I think it’s more likely he is looking for a way to ADD normal to the terrain for better lighting that doesn’t need 1000’s of vertices in the mesh.

FWIW, I was looking at that too (low res mesh, high res lighting) but it doesn’t seem possible with Cesium as is.

---

<div class="post-metadata">

**Author:** ![Manuel\_Massing](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@Manuel\_Massing](https://community.cesium.com/u/Manuel_Massing)\
**Post date:** [February 25, 2019, 3:15pm UTC](https://community.cesium.com/t/normal-map-shading-for-terrain-tiles/8026/4 "2019-02-25T15:15:03Z")

</div>

Hi Omar,  
Hi Benjamin,

thanks for your input!

It's good to hear heightmaps are not deprecated.

As Benjamin correctly noted, I want to apply normal maps in order to add  
detailed normals to the terrain geometry (independent of mesh tesselation).

Basically, terrain normal maps can be parametrized and sampled the same  
way as the usual ImageyLayers (aka "daytextures" in  
GlobeSurfaceShaderSet), so fortunately a lot of the required setup is  
already present.

AFAICT, the steps currently missing for working normal maps:

- designate an ImageryLayer as normal map layer (e.g. via flag)  
- setup samplers + parameters (scaling, offset etc.) for normal map:  
&nbsp;&nbsp;analoguous to dayTextureSetup in GlobeSurfaceTile.js; normal map must  
&nbsp;&nbsp;be bound for each pass when using multi-pass rendering

- Adapt fragment shader in GlobeSurfaceShaderSet.js:  
&nbsp;&nbsp;- decoding of normal into appropriate coordinate frame (possibly  
&nbsp;&nbsp;&nbsp;&nbsp;with support from VS, e.g. tangent space vectors)  
&nbsp;&nbsp;- diffuse shading in the fragment shader  
&nbsp;&nbsp;- add define + conditional code sections to FS, e.g. "#define  
&nbsp;&nbsp;&nbsp;&nbsp;ENABLE\_NORMAL\_MAPS"

Looks doable, although it might still be out of scope for my  
current project.

cheers,

Manuel

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [February 26, 2019, 11:43pm UTC](https://community.cesium.com/t/normal-map-shading-for-terrain-tiles/8026/5 "2019-02-26T23:43:04Z")

</div>

Ah, I see what you mean. That sounds like it would be a pretty awesome feature! We’d definitely appreciate a contribution to that effect. If you’ve got something started in a fork I’d be happy to take a look, or another way to get feedback would be to open a work-in-progress PR.
