Adding Gravity

What goes up must come down. Isaac Newton became famous because he observed the effects of gravity on apples falling from a tree; our particles will look better if we add some gravity to them as well.

On earth, everyone feels an acceleration of 9.8 meters per second squared, and if we ignore the effects of wind resistance, then the longer something falls, the faster it goes. We can easily reproduce this effect in our code by adding a gravity adjustment to our vertex shader. Let’s open up particle_vertex_shader.glsl and add the following line of code after the assignment to v_ElapsedTime:

Particles/res/raw/particle_vertex_shader.glsl
 
float​ gravityFactor = v_ElapsedTime * v_ElapsedTime / 8.0;

This will calculate an accelerating ...

Get OpenGL ES 2 for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.