Excuse me, why do I get this error“ 'czm_translucentPhong' : no matching overloaded function found”?

Hi there,

I defined the shader using version 1.105 of cesium and received the following error

RuntimeError: Fragment shader failed to compile.  Compile log: ERROR: 0:35: 'czm_translucentPhong' : no matching overloaded function found
ERROR: 0:35: '=' : dimension mismatch
ERROR: 0:35: 'assign' : cannot convert from 'const mediump float' to 'out highp 4-component vector of float'

    at new RuntimeError (
    at createAndLinkProgram (
    at reinitialize (
    at initialize2 (
    at ShaderProgram._bind (
    at beginDraw (
    at Context.draw (
    at DrawCommand.execute (
    at executeCommand (
    at executeTranslucentCommandsSortedMRT (

The following is my definition of the Fragment shader

 const getFragmentShaderSource = function () {
            return "#version 300 es\n\
              in vec3 v_position;\n\
              in vec3 v_normal; \n\
              uniform float picked; \n\
              uniform vec4  pickedColor; \n\
              uniform vec4  defaultColor; \n\
              uniform float specular; \n\
              uniform float shininess; \n\
              uniform vec3  emission; \n\
              in vec2 v_st; \n\
              uniform bool isLine; \n\
              uniform float glowPower; \n\
              layout(location=2) out vec4 pc_FragColor; \n\
              void main() { \n\
                vec3 positionToEyeEC = -v_position; \n\
                vec3 normalEC = normalize(v_normal); \n\
                vec4 color = defaultColor; \n\
                 if (picked != 0.0) { \n\
                        color = pickedColor; \n\
                 } \n\
                  czm_material material; \n\
                  material.specular = specular; \n\
                  material.shininess = shininess; \n\
                  material.normal = normalEC; \n\
                  material.emission = emission;//vec3(0.2,0.2,0.2);\n\
                  material.diffuse = color.rgb ;\n\
                        material.alpha = 1.0; \n\
                  else{ \n\
                    material.alpha = color.a; \n\
                  if(v_st.x==0.0){ \n\
                      pc_FragColor =color ;\n\
                  }else { \n\
                      pc_FragColor = czm_phong(normalize(positionToEyeEC), material) ; \n\
                  } \n\

The following is my definition of the Vertex shader

  const getVertexShaderSource = function () {
            return "#version 300 es\n\
              #ifdef GL_ES\n\
                precision highp float;\n\
              in vec3 position;\n\
              in vec2 st;\n\
              in vec3 normal;\n\
              uniform mat4 modelViewMatrix;\n\
              uniform mat3 normalMatrix;\n\
              uniform mat4 projectionMatrix;\n\
              out vec3 v_position;\n\
              out vec3 v_normal;\n\
              out vec2 v_st;\n\n\
              out vec3 v_light0Direction;\n\n\
              void main(void) \n\
                    vec4 pos =  modelViewMatrix * vec4( position,1.0);\n\
                    v_normal =  normalMatrix *  normal;\n\
                    v_st = st;\n\
                    v_position = pos.xyz;\n\
                    v_light0Direction = mat3( modelViewMatrix) * vec3(1.0,1.0,1.0);\n\
                    gl_Position =  projectionMatrix * pos;\n\

Who can help me? I’ve been searching for it for a long time and I don’t know where the mistake is.

Hi @Baker, are you using globe translucency somewhere? This would explain why czm_phong is being replaced by czm_translucentPhong.

I think the error is here:

pc_FragColor = czm_phong(normalize(positionToEyeEC), material) ;

Both the czm_phong and czm_translucentPhong functions require a third argument for the light direction:

czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC);

An aside: The question had been asked quite a while ago. But it is incredibly hard (I’d say ‘impossible’) to just glance at the code and provide “the” solution. People like jjhembd can give profound hints and recommendations. But making sure that the suggestion or hint really solves the problem is not possible. Questions like this can be answered far more easily when the problem can be demonstrated reproducibly in a Cesium Sandcastle .

@Marco13 Hi Marco13 Thank you for providing me with the advice. This is my Demo demo address, and the code is a bit messy. Please forgive me;

@jjhembd Hi jjhembd, Thank you for your help. I added ‘czm’_ LightDirectionEC ', the code is running normally, but nothing is displayed .
This is my Demo demo address, and the code is a bit messy. Please forgive me;

@jjhembd @Marco13 During my testing, I found an error with layout (location=2) out vec4 pc-FragColor;. I deleted it and changed it to out vec4 pc-FragColor;, and then returned the following error

RuntimeError: Fragment shader failed to compile Compile log: ERROR: 0:12: 'pc_ FragColor ': must explicitly specify all locations when using multiple fragment outputs

Hi @Baker, can you break that example down into something smaller?

Since the shader is compiling now, the error could be anywhere in the JavaScript. Each of the functions and classes need to be tested separately to find the problem.

Also the code style is harder for me to read. Some individual lines take a while to figure out, like this one:

	return (0, Cesium.Scene.computeVertexNormals)(D), m = [], p = [], D

This kind of syntax is an interesting challenge, but it makes debugging slower.

Hi @jjhembd, I’m sorry to have troubled you. I have reorganized the Demo and could you please help me check it, I speculate that the problem is probably on line 333.

Hi @Baker, thanks for the reorganized Demo. I think in this case you can simply write to out_FragColor in the fragment shader, rather than defining a custom output variable.

When I try this, the result makes sense:

See my Updated demo code.

Is this what you were expecting? It looks interesting! Can you share what the goal of this new primitive is?

@jjhembd Wow, thank you very much. This is the result I want. This problem has been bothering me for several months. This case is mainly used to enhance the visual effects of the scene. Originally, everything was running normally in version 1.86 of cesium, but later using version 1.105 of cesium required upgrading webgl from 1.0 to 2.0. There were many changes here, and the relevant documents for the upgrade were not found on the cesium official website.

only for reference WebGL2 from WebGL1 I made some modifications, but my webgl is really poor, so I have been unable to correct the program. I am ashamed and want to study webgl related knowledge well, but I have not found any good materials.