Cocos2d Shader Cookbook Port

I’ve recently started to port the shader cookbook from Cocos2d-iPhone to cocos2d-x 3.3+. Also looking into porting or documenting how to generate and use something similar to Cocos2d-Swift’s CCEffect and CCEffectNode.

Need to finish adding GUI modifiers as well as implement the shaders #7-16 (Water effect #10 is complete) and refactor and cleanup the code.

I’ll update this topic when I’ve finished porting. I’ll likely look to add others in the future and anyone else could post here or submit PR as well.

Hope it helps someone.

1 Like

Just a little offtopic thought.

As for me shaders are not so hard. Expecially those examples from the Cookbook, since they are quite simple and not really usable in a real game. What I mean is that in a real game we have to use batching and texture atlases to decrease the number of draw calls and utilize memory bandwidth more efficially etc. So, let’s assume that we have several characters on the screen. All of them are sprites related to the same batch. When the character is hit with a bullet I’d like to make him flash with a solid color like in good old 2d games ( https://github.com/slembcke/Cocos2DShaderCookbook/blob/master/Cookbook/Docs/E07_ColorFlash.md ).So, how can I do this for the single sprite if the shaders are shared between all the sprites in the batch (actually those ‘sprites’ form a single mesh)?

Good points. I agree they may not be useful. I’m doing it mainly to learn the rendering pipeline including the new shader capabilities setting uniforms. If I understand things correctly you could use the ColorFlash shader for all sprites in the batch, but have a single uniform vec4 flash_color, and set all but the sprite that was hit either with WHITE or CLEAR.

I believe it’ll batch all sprites still if they use the same shader+texture, but I think you can have different uniform values for each sprite in the batch.

But I’m still diving into the new rendering pipeline.

I’ll add example(s)/test(s) using texture atlases and having multiple sprites on screen while using both the example set of shaders as well as at least your example.