Animated Radiating Colors
WebGL Shader
This Web page includes the GLSL shader source code. This WebGL shader displays animated radiating colors. The WebGL vertex and fragment shaders work with vertex colors to generate a series of blended colorful circular areas.
Vertex Shader
attribute vec4 a_position; attribute vec4 a_tex_coord0; varying vec4 v_tex_coord0; uniform mat4 um4_matrix; uniform mat4 um4_pmatrix; uniform float uf_time; void main(void) { gl_Position = um4_pmatrix * um4_matrix * a_position; float f_dist = distance( a_position, vec4(0.0,0.0,0.0,1.0) ); vec4 v4_color = a_tex_coord0; v4_color.rb = v4_color.rb * f_dist / uf_time; v_tex_coord0 = v4_color; }
Fragment Shader
precision mediump float; varying vec4 v_tex_coord0; void main(void) { gl_FragColor = v_tex_coord0; }
Texture
The Animated Radiating Colors example applies vertex colors rather than a texture. Vertex colors allow rendering color per vertex.
Summary
This WebGL shader displays animated radiating colors. The WebGL vertex and fragment shaders work with vertex colors to generate a series of blended colorful circular areas.
Simple Shaders: Learn WebGL Book 4
Learn the basics of WebGL shader programming withSimple Shaders: Learn WebGL Book 4. This book covers seven projects with unique shaders, in detail, providing an overview of GLSL (OpenGL Shading Language), which is the shader language used for WebGL. See the following projects online
Spotlight Across Text, Radiating Colors, Cube Vertex Colors, Color Filters, Zoom Shader, Spotted Balloon Burstsand
Colors Fade. Most shaders activate as you swipe over the canvas. See various visual effects including color animation, zooming, color filters, a traveling spotlight and expanding mesh.
Simple Shaders
explains how to prepare basic WebGL GLSL shaders.
This new Kindle book includes detailed instruction and links to many interesting
WebGL shader examples online.
Learn to program WebGL shaders. Harness the power of the Graphics Processing Unit (GPU).