Deforming objects with a vertex shader
A vertex shader processes each vertex of drawing objects and can change their built-in attributes such as position, color, normal, and can also change any custom attributes. Here, we consider the example of the vertex shader that just moves vertices according to a rule with the help of parameters that are controlled by the mouse position.
Note
This is example 08-Shaders/06-VertexDeformation
.
This example is based on the example given in the The triangles cloud example section of Chapter 2, Drawing in 3D. The original example draws a rotated sphere-shaped cloud of random triangles.
Vertex shader
In the bin/data
folder, create a new text file shaderVert.c
containing the following code:
#version 120 #extension GL_ARB_texture_rectangle : enable #extension GL_EXT_gpu_shader4 : enable uniform float phase = 0.0; //Phase for "sin" function uniform float distortAmount = 0.25; //Amount of distortion void main() { //Get original position of the vertex vec3 v...