Zoom Out WebGL Shader

Concentric Circles

This page includes the GLSL shader source code to zoom out of an image mapped to a mesh. Concentric circles zoom out during animation which creates a dizzying tunnel effect.

Vertex Shader Fragment Shader Texture Summary

Vertex Shader

The zoom out technique is implemented with the vertex shader.

 
 attribute vec4 a_position;   
 attribute vec2 a_tex_coord0;
 varying vec2 v_tex_coord0;
 
 uniform float uf_time;          
 uniform mat4 um4_matrix;
 uniform mat4 um4_pmatrix;
           
void main(void) {
 // Copy attribute.
 // Attributes can't be
 // modified.
 vec2 tex_coord = a_tex_coord0;

 if (tex_coord.s == 1.0){
  tex_coord.s -= uf_time;
 }
 else if (tex_coord.s == 0.0){
  tex_coord.s += uf_time;
 }
 
 if (tex_coord.t == 1.0){
  tex_coord.t -= uf_time;
 }
 else if (tex_coord.t == 0.0){
  tex_coord.t += uf_time;
 } 

 gl_Position = um4_pmatrix * um4_matrix *  a_position; 
 v_tex_coord0 =  tex_coord; 
   
}

Fragment Shader

precision mediump float;
uniform sampler2D u_sampler0;
varying vec2 v_tex_coord0;

void main(void) {
 gl_FragColor = texture2D(u_sampler0, v_tex_coord0); 
}

Texture Map

Lighthouse Texture Map

Summary

This example animates concentric circles which zoom out, creating a dizzying tunnel effect. The zoom out technique is implemented with the vertex shader.

Simple Shaders: Learn WebGL Book 4

Learn the basics of WebGL shader programming with Simple 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 Bursts and 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).

Simple Shaders: Learn WebGL Book 4


Ads >
Create 3D Games: Learn WebGL Book 2 Simple Shaders: Learn WebGL Book 4
3D Programming for Beginners: Learn WebGL Book 1
Web Graphics & Illustration Architectural Rendering 3D Architectural Web Animation
Web Development Python & MySQL Send Email Complete Sitemap About Search 3D