custom geometry always float on terrain.

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

A custom geometry always float on terrain.

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

var positions = Cesium.Cartesian3.fromDegreesArrayHeights([

104.317776, 31.59491, 0,

105.317776, 32.59491, 0,

102.317776, 33.59491, 0


var numPositions = positions.length;

var pos = new Float64Array(numPositions * 3);

for (var i = 0; i < numPositions; ++i) {

pos[i * 3] = positions[i].x;

pos[i * 3 + 1] = positions[i].y;

pos[i * 3 + 2] = positions[i].z;


var geometry = new Cesium.Geometry({

attributes: {

position: new Cesium.GeometryAttribute({

componentDatatype: Cesium.ComponentDatatype.DOUBLE, // not FLOAT

componentsPerAttribute: 3,

values: pos


normal: new Cesium.GeometryAttribute({

componentDatatype: Cesium.ComponentDatatype.FLOAT,

componentsPerAttribute: 3,

values: new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0])



indices: new Uint32Array([0, 1, 2]),

primitiveType: Cesium.PrimitiveType.TRIANGLES,

boundingSphere: Cesium.BoundingSphere.fromVertices(pos)


var geoInstance = new Cesium.GeometryInstance({

geometry: geometry,

attributes: {

color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED)


show: new Cesium.ShowGeometryInstanceAttribute(true)


var appearance = new Cesium.MaterialAppearance({

flat: true,

vertexShaderSource:"attribute vec3 position3DHigh;\n\

attribute vec3 position3DLow;\n\

attribute vec3 normal;\n\

attribute float batchId;\n\

varying vec3 v_positionEC;\n\

varying vec3 v_normalEC;\n\

void main(){\n\

vec4 p = czm_computePosition();\n\

v_positionEC = (czm_modelViewRelativeToEye * p).xyz;\n\

v_normalEC = czm_normal * normal;\n\

gl_Position = czm_modelViewProjectionRelativeToEye * p;\n\


fragmentShaderSource:"varying vec3 v_positionEC;\n\

varying vec3 v_normalEC;\n\

void main(){\n\

gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n\


translucent: true


viewer.scene.primitives.add(new Cesium.Primitive({

geometryInstances: [geoInstance],

asynchronous: false,

appearance: appearance


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

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

Cesium 1.53

If you want your geometry on the terrain, you can either construct it there by getting the terrain heights at the vertices:

Or I think you need to use GroundPrimitive instead of Primitive:

I try to use GroundPrimitive instead of Primitive,but the GroundPrimitive does not support custom geometry .

Even thougth I set the really heights at the vertices, the same geometry has different position while eye point changed.

在 2019年1月14日星期一 UTC+8下午10:15:08,Omar Shehata写道:

I’m not sure what you mean by:

Even thougth I set the really heights at the vertices, the same geometry has different position while eye point changed.

Did you use sampleTerrainHeightsMostDetailed to get the ground heights? Are you able to create this effect in a Sandcastle ( that you can share? (Create your example, then click “Share” at the top and paste the link here).

For GroundPrimitive and custom geometry, it should work fine as long as it’s in the list of valid geometries described here:

I think this is because those geometries have a shadowVolume defined, which is what is used to drape the polygon on the surface.

I am sorry ,I forgot globe depthTestAgainstTerrain.

在 2019年1月16日星期三 UTC+8上午4:07:29,Omar Shehata写道:

Oh, yes! Glad to hear it works now. And thanks for posting your code snippet, I’m sure it will be useful to anyone working with custom geometry in CesiumJS.