[SOLVED] Example code implementing multi texture shaders in Cocos Creator

Hi.

We’re shipping a commercial title in less than a month and we need help integrating a custom multi texture shader within the Cocos Creator engine.

We’re trying to do an advanced compositing draw where the final pixel write is dependent on the source texture pixel value and the destination buffer pixel values.

In Webgl, it’s not possible to sample the target frame buffer directly. However, the workaround is to write a multi texture shader which takes 2 (or more) textures - one being the source texture, and the other being the frame buffer as a texture.

Writing code to pass in two textures and the necessary vertex / uv buffer is fairly straightforward in pure JavaScript. However, I’m having a difficult time figuring out how to write said code under the Cocos Creator context given the engine’s rendering system.

Has anyone figured out how to accomplish this, or to write a custom render call with the Cocos Creator context? If so, can you share an example of how this was accomplished?

Thanks

multi texture material demo,reference1.zip (137.9 KB)
made by v2.1.2

Thank you for the quick response. It’s much appreciated!

Thanks for the sample. It answers all the questions that I have regarding multi-texture support. Out of curiosity, is it possible to add in a second vertex or UV stream?

Finally, just a head’s up that the demo renders properly in the editor and in the simulator, but it doesn’t render properly as a browser preview or when exported.

That’s because Cocos Creator is efficient and created a texture atlas for all the referenced textures thereby invalidating the shader’s assumption about the UV relationship between the first texture and the second one. The shader assumes it can use the first texture’s UV for sampling the second texture. However, this is no longer possible if the first texture’s UV is mapped to a larger texture atlas.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.