Shaku: Effects Sandbox

This demo is a sandbox application to write effects and see them update in realtime on the right side.

// define our custom effect // don't rename it from 'CustomEffect' or it won't work for this demo class CustomEffect extends Shaku.gfx.SpritesEffect { /** * Override the vertex shader for our custom effect. */ get vertexCode() { const vertexShader = ` attribute vec3 position; attribute vec2 uv; attribute vec4 color; uniform mat4 projection; uniform mat4 world; varying vec2 v_texCoord; varying vec4 v_color; void main(void) { gl_Position = projection * world * vec4(position, 1.0); gl_PointSize = 1.0; v_texCoord = uv; v_color = color; } `; return vertexShader; } /** * Override the fragment shader for our custom effect. */ get fragmentCode() { const fragmentShader = ` #ifdef GL_ES precision highp float; #endif uniform sampler2D mainTexture; uniform float elapsedTime; varying vec2 v_texCoord; varying vec4 v_color; void main(void) { gl_FragColor = texture2D(mainTexture, v_texCoord) * v_color; gl_FragColor.r *= sin(v_texCoord.y * 10.0 + elapsedTime) + 0.1; gl_FragColor.g *= sin(1.8 + v_texCoord.y * 10.0 + elapsedTime) + 0.1; gl_FragColor.b *= sin(3.6 + v_texCoord.y * 10.0 + elapsedTime) + 0.1; gl_FragColor.rgb *= gl_FragColor.a; } `; return fragmentShader; } /** * Override the uniform types dictionary to add our custom uniform types. */ get uniformTypes() { let ret = super.uniformTypes; ret['elapsedTime'] = { type: Shaku.gfx.Effect.UniformTypes.Float }; return ret; } /** * This method is called before we render with the effect, to do custom setups * It's not part of Shaku, its something we add for this specific demo. */ static preRenderInit(effectInstance, sprite) { // update effect custom uniform effectInstance.uniforms.elapsedTime(Shaku.gameTime.elapsed); } }