Giter VIP home page Giter VIP logo

cocos2d-shaders-test's Introduction

Cocos2d-JS/Cocos2d-x shader and uniforms

Cocos2d-x allows to use shaders, which are supported both on native platforms and in HTML5 with WebGL. To pass custom parameters to a shader, you use shader uniforms.

  • Cocos2d provides cc.GLProgram to update these uniforms but it only works with the HTML5 version.
  • If you want it to work when compiling with Cocos2d-x for Windows/Android/iOS/OS X/Linux, you have to use cocos2d::Node::getGLProgramState. Luckily it is provided in the JS bindings of Cocos2d-x.

This example shows how to use both to have shader uniforms properly updated on all platforms.

How to test this example

  • Be sure to have Cocos2d-x installed.
  • Create a new Cocos2d project with Javascript:
cocos new -l js ShadersTest
  • Copy the content of this git in the created folder, replacing res, src and root files.
  • Try the HTML5 version. You need to serve the files using a server. For example:
npm i http-server
http-server .
  • The HTML5 version will display the Cocos2d Hello World game with a shader applied to the sprite. The sprite will blink because a uniform of the shader is randomly updated at each new frame.

  • Try the game using a Cocos2d-x platform. For example:

cocos run -p mac

See a related issue discussion here: http://discuss.cocos2d-x.org/t/basic-shader-help/16533/13

cocos2d-shaders-test's People

Contributors

4ian avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.