I have no clue about OpenGL and Shaders and I don’t know what would even be possible or where to start.
Would it be possible to use OpenGL Shader on a full screen background sprite with an animation like this for example: https://www.shadertoy.com/view/ldBGRR ?
Would this work on iOS and Android devices? And is there a way to use such a shader from shadertoy in Cocos2d-x?
Where to start learning about OpenGL Shaders and how to use them with Cocos2d-x (3.9)?
Seems everything I can find on OpenGL shaders in Cocos2d-x is outdated. There is only the API reference, which doesn’t help in learning at all, and the samples, which don’t help me either. If I missed anything, I would be happy if someone could point me to the right direction?
For now just have a look at the cpp-tests ShaderTest folder. There is only a little cocos2d-x specific code you have to write, namely loading in your custom shader, setting the uniform values, and applying it to the sprite/node.
Shadertoy does have specific values that aren’t directly applicable to a cocos2d-x shader, but there are some engine shader uniform values that are provided.
In your example iGlobalTime would probably be changed to CC_Time[0] or CC_Time[1]
Is there any recommended book (or video?) about shaders like they are used in cocos2d-x? From what I have seen at amazon, most are either opengl ES in general with probably very little about shaders, or they are on opengl ES 3.0, which, as far as I understand, is not what I want.
I got it to work - even though I have completely no idea how or why But it does work and it works actually very well and fairly fast as a background, I’m still getting 60 fps on my Moto G 1st gen even with lots of sprites movement.
I tested quite a few of the shaders. The more complicated 3d and even raytracing shaders work too, but they are way too slow, but that was expected. The simple 2d shaders like plasmas and 2d kind of shapes mostly work quite good, sometimes one need to make some adjustments and lower the quality - but just for using it as an animated background that’s perfectly fine.
However, as I have no clue what I am doing and just playing around with some values, I stumble fairly often and it was of course not my intention to just steal other code, I want to learn and make my own. I will check out the documentation from Apple.
I don’t get how to just use the current texture of a sprite?
I use this function in my code (some lines are just for testing other things, I leave them in, maybe it helps someone else who struggles to find this out, like I did):
I don’t get any errors, but it produces just a white texture. Shouldn’t this use the original texture of the sprite and just pass this through (I don’t mean the noise.png, that was just for testing other things, but the original sprite texture)?
You’re setting the fragment (pixel) color to the varying v_fragmentColor which seems to be white in your case. If you want to get a texel from the texture, do something like this: