Sorry to bother you again @dave, but I'm still having trouble with this.
When I change it to
new pc.BasicMaterial() it seems like the shader has no effect at all (like shaders aren't being applied to the material). Do I need to do something different when applying it to a
BasicMaterial ? Do you have a working example of this I could look at?
Alternative Way of Doing Flat Shading?
On a slightly tangential note, I've seen discussions of a different technique, instead of calculating the normal at each pixel like that, to just change the normals that are passed to the vertex shader.
I believe this is how Three.js does it. Just compute the face normals, and then set that face normal on each vertex so even after intepolation, everything still looks flat. (That way you can achieve flat shading without any custom shaders). Although I haven't been able to correctly compute this on a generated mesh in PlayCanvas.
So if you know of any example of that, that would also help!