question about modify the shader in model.js

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

I was trying to modify the model shader in the example: http://localhost:8080/Apps/Sandcastle/index.html?src=3D%20Models.html&label=Showcases. I change the code in Model.js like this:

var tmpVS = ‘precision highp float; \n’ +

‘attribute vec3 a_position; \n’ +

‘attribute vec3 a_normal; \n’ +

‘varying vec3 v_normal; \n’ +

‘uniform mat3 u_normalMatrix; \n’ +

‘uniform mat4 u_modelViewMatrix; \n’ +

‘uniform mat4 u_projectionMatrix; \n’ +

‘attribute vec2 a_texcoord0; \n’ +

‘varying vec2 v_texcoord0; \n’ +

‘varying vec4 v_color; \n’ +

‘void main() { \n’ +

‘vec4 pos = u_modelViewMatrix * vec4(a_position,1.0); \n’ +

‘v_normal = u_normalMatrix * a_normal; \n’ +

‘v_texcoord0 = a_texcoord0; \n’ +

‘v_color = pos; \n’ +

‘pos.z = sin(5.0*pos.x)*0.25; \n’ +

‘gl_Position = u_projectionMatrix * pos; \n’ +


var tmpFS = ‘precision highp float; \n’ +

‘varying vec4 v_color; \n’ +

‘void main() { \n’ +

‘gl_FragColor = v_color; \n’ +



model._rendererResources.programs[id] = ShaderProgram.fromCache({

context : context,

vertexShaderSource : tmpVS,

fragmentShaderSource : tmpFS,

attributeLocations : attributeLocations


But the model “Cesium_Air” was invisible if I ran the code. I don’t know what’s the mistake in the code?

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

Cesium 1.41

pos.z is setting the model’s position in eye space, which looks into the -z direction. Either the result of that equation is a positive number, in which case the airplane won’t be visible, or the result is a small negative number, in which case the camera is “inside” the airplane but appears invisible because back faces are culled. If you set pos.z to something like -30.0 you should be able to see it.

Hi, Sean, thank you for your reply. I tried the value like -30.0, and the airplane was visible. If so, how could I flatten a 3D model in Cesium by setting its z coordinate to zero like this:

void main(void)
	vec4 v = vec4(gl_Vertex);
	v.z = 0.0;

	gl_Position = gl_ModelViewProjectionMatrix * v;

在 2018年2月3日星期六 UTC+8上午8:37:22,Sean Lilley写道:

Hi, Sean, I think I have got it by setting the a_position value. But I still don’t understand why was the airplane flattened by setting its y coordinate to zero?

在 2018年2月3日星期六 UTC+8上午8:37:22,Sean Lilley写道:

Cool that you got the effect you wanted.

That worked because the model’s up axis is Y, so scaling a_position.y is basically scaling the height of the original vertices.