# Custom shader on terrain, can i get the terrain normals somehow?

**URL:** <https://community.cesium.com/t/custom-shader-on-terrain-can-i-get-the-terrain-normals-somehow/24865>\
**Category:** CesiumJS\
**Created:** [June 19, 2023, 2:34am UTC](https://community.cesium.com/t/custom-shader-on-terrain-can-i-get-the-terrain-normals-somehow/24865 "2023-06-19T02:34:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ka\_sc](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ka_sc/32/2397_2.png) [@ka\_sc](https://community.cesium.com/u/ka_sc)\
**Post date:** [June 19, 2023, 2:34am UTC](https://community.cesium.com/t/custom-shader-on-terrain-can-i-get-the-terrain-normals-somehow/24865/1 "2023-06-19T02:34:04Z")

</div>

I would like to use the terrain’s normals in my fabric shader. Could i do that somehow? My naive idea

const material = new Cesium.Material({  
fabric: {  
uniforms: {  
image: “…/images/earthspec1k.jpg”,  
heightField: “…/images/earthbump1k.jpg”,  
},  
materials: {  
bumpMap: {  
type: “BumpMap”,  
uniforms: {  
image: “…/images/earthbump1k.jpg”,  
},  
},  
},  
source: ` czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); vec4 color; material.diffuse = materialInput.normalEC;//color.rgb; material.alpha = 0.5;//color.a; return material; } `,  
},  
});  
viewer.scene.globe.material = material

 ![image](https://global.discourse-cdn.com/cesium/original/2X/7/7fff3110349c67b20b4b3a74cba61368c508ce50.jpeg)

Will those be available in shader?  
const viewer = new Cesium.Viewer(“cesiumContainer”, {  
terrain: Cesium.Terrain.fromWorldTerrain({  
requestVertexNormals: true, //Needed to visualize slope  
}),  
});

---

<div class="post-metadata">

**Author:** ![jjhembd](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jjhembd/32/10144_2.png) [@jjhembd](https://community.cesium.com/u/jjhembd)\
**Post date:** [June 20, 2023, 9:10pm UTC](https://community.cesium.com/t/custom-shader-on-terrain-can-i-get-the-terrain-normals-somehow/24865/2 "2023-06-20T21:10:16Z")

</div>

Hi @ka_sc, you are correct that the normals should be available via `materialInput.normalEC`. I am not quite clear on what your code example is trying to do. Did it already show what you wanted?

Here is a quick [Sandcastle example](https://sandcastle.cesium.com/#c=bVNdj9owEPwrFk8gccZJyBfHoVa0Uiv12lNbXV8i9YyzgFXHprYD5Sr+excSOCj3YnnHM7vr8VqBJ2sJG7C3hfZ2S/4WmrQIuSMaNmQKTtYVfTxg3aIjDvHUaM+lBlt0+o2IEA/WIvZgzVqWYEeEb7j0xwTCAvfww1hVfm+Ib91Wi24rJsTC7xqcfwTr4c9nYyuu3Ih4W0PD2PX6zYZrWXEvjR6ROXKghb2sQGFL5+iuh/faEcG9WJIuljW217QrjHZGAVVm0eJ7ZqELvT/xBCuAlVxdunDfok3Xcz6zUoyO93emtgLLP4nn6udJvw8W4E/K88OPelW/lDpEvUK36S6yVNhHm+kdzHmtXhJeym8bcUVLOZ/XDlB3QaD64Oz76YnI1WrJkcZo3mIWfG01qfaOPDU+4nrwstDNcFAnQANdKDMDeubVcXtNFbwCy6kDvx+lxsAS31vq9i3PbJ5ynAEnuY66N2EUhyyPaBJlaZRHAUv75CZK4xT3NGQsQyiJ+2QYZ3kWMRrkYTLMkiRvxsVYCTiqVyU+AC+lXjxInIyvRqnukGZpOoyDIMnSnLE4wDKMZkmMDaThENEIlz7axBgLkRGGaRIFQxZlcdA7+tPpd8bObxVMjmP9RlYrYz2prepSOvBQrRSa5AazWvwCT4Vzx0cbD86l41KuiSzvXvlyRCjuHJ7Ma6W+yWcoOpPxAPlXUmUO1/yyBqv4dk9bBpNPDUgpHQ8wfF3pjVEzbv/L/A8) that uses the terrain normal to color the terrain.

 ![image](https://global.discourse-cdn.com/cesium/original/2X/f/f34c23ec13e3c989364c5ccbb27b677f92120cf5.jpeg)

---

<div class="post-metadata">

**Author:** ![ka\_sc](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ka_sc/32/2397_2.png) [@ka\_sc](https://community.cesium.com/u/ka_sc)\
**Post date:** [June 21, 2023, 12:40am UTC](https://community.cesium.com/t/custom-shader-on-terrain-can-i-get-the-terrain-normals-somehow/24865/3 "2023-06-21T00:40:48Z")

</div>

Very exciting. I wasnt sure if it worked

---

<div class="post-metadata">

**Author:** ![ka\_sc](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ka_sc/32/2397_2.png) [@ka\_sc](https://community.cesium.com/u/ka_sc)\
**Post date:** [June 28, 2023, 4:59am UTC](https://community.cesium.com/t/custom-shader-on-terrain-can-i-get-the-terrain-normals-somehow/24865/4 "2023-06-28T04:59:23Z")

</div>

Somehow if i zoom closer i loose the normals in your castle. The highest resolution is probably the most interesting…

 ![image](https://global.discourse-cdn.com/cesium/original/2X/f/f97df8470b7f123e8b0d1959aab455410427db4c.jpeg)
