Possibly a bug in Sprite3D::setGLProgramState, not setting _usingAutogeneratedGLProgram to false

Hi,

I’m on 3.14.1.

I was struggling with setting custom shaders to my Sprite3D objects for some time. Now it’s 3:17 AM here and I realized, that any shader which I add to my Sprite3D is overwritten by autogenerated one, because _usingAutogeneratedGLProgram is never set to false.

my quick fix for this is:

void Sprite3D::setGLProgramState(GLProgramState* glProgramState)
{
Node::setGLProgramState(glProgramState);
for (auto state : _meshes) {
state->setGLProgramState(glProgramState);
}
_usingAutogeneratedGLProgram = false; // ← here
}

after this change everything started to work for me.

cheers,

/Arek

That’s strange, because 3.14.1 doesn’t have this line of code. -> see https://github.com/cocos2d/cocos2d-x/blob/v3/cocos/3d/CCSprite3D.cpp#L804

PS: I didn’t check git, if the was earlier.

I’ve added marked line to make things work. That’s the point.

Interesting. I believe Sprite3D was built to rely on using Materials for custom shader support. It appears at a glance that your fix might screw up behavior of previous code using Sprite3D (backward incompatible), but I’m not sure why someone would call setGLProgramState while also assuming that their shader would work with the lighting system, since the lights rely on the shader additions in Sprite3D.

Have you tried to learn how to set your custom shader as a material instead? It appears that the Material subsystem is currently a required for custom shaders.

Submit an issue with your post (link or copy/paste) over on the github page.