The issue with updating the playcanvas.js basic library to the latest version 1.65.3

this.material.updateShader = function(graphicsDevice) {
this.shader = new pc.Shader(graphicsDevice, {
attributes : {
vertex_position : “POSITION”
vshader : " attribute vec3 vertex_position;\n uniform mat4 matrix_model;\n uniform mat4 matrix_projection;\n uniform mat4 matrix_view;\n uniform mat3 matrix_normal;\n uniform float scale;\n varying vec2 vUv0;\n void main(void)\n {\n vec3 normal = normalize(matrix_normal * vec3(0, 1, 0));\n float d = max(0.0, (dot(vec3(matrix_view[0][2], matrix_view[1][2], matrix_view[2][2]), normal) - 0.6) * (1.0 / (1.0 - 0.6)));\n mat4 modelMatrix = matrix_view * matrix_model;\n modelMatrix[0][0] = 1.0;\n modelMatrix[0][1] = 0.0;\n modelMatrix[0][2] = 0.0;\n modelMatrix[1][0] = 0.0;\n modelMatrix[1][1] = 1.0;\n modelMatrix[1][2] = 0.0;\n modelMatrix[2][0] = 0.0;\n modelMatrix[2][1] = 0.0;\n modelMatrix[2][2] = 1.0;\n vec4 positionW = modelMatrix * vec4(vertex_position * scale * d, 1.0);\n gl_Position = matrix_projection * positionW;\n vUv0 = vertex_position.xy + vec2(0.5);\n vUv0.y = 1.0 - vUv0.y;\n }\n",
fshader : " precision highp float;\n varying vec2 vUv0;\n uniform float opacity;\n uniform sampler2D texture_diffuseMap;\n void main(void)\n {\n vec3 diffuse = texture2D(texture_diffuseMap, vUv0).rgb;\n if (diffuse.r * opacity < 0.001) discard;\n gl_FragColor = vec4(diffuse * opacity, 1.0);\n }\n"


Is there any compatibility between the vertex shader I wrote and the vertex shader invalidation in the latest basic library 1.65.3

Do you have something that worked using 1.64 but does not work using 1.65? Or do you get shader compile errors?

I don’t think it worked in older engine version either?

Couple of things I noticed:

  • you are using vertex_position as an attribute, you should use pc.SEMANTIC_POSITION instead of “POSITION”
  • make sure you set a texture to texture_diffuseMap, since you are sampling it in the shader

And as Martin mentioned, you should share the error you are getting.

1 Like

It can display normally in versions 1.64.4 and earlier

Display error in version 1.65.3, I don’t know where the problem is with my shader

The above is an example I did, which shows normal in version 1.64.4 and no effect in version 1.65.3

Could you please describe what it is you’re trying to do, how you do it and anything else that can help us?

Hmm, I haven’t looked deeply, but I noticed the OP is trying to set a custom shader on a BasicMaterial. @mvaligursky is this supported? I think it should be pc.Material?

1 Like

Thanks @LeXXik - yes, please use pc.Material for custom shaders.

1 Like