Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Passing parameters into shader programs


The shaders we have seen so far simply apply a non-configurable filter to a texture, and nothing more. You will most likely want to have richer effects in your applications, some that change over time and others that take into account external factors such as user input. This recipe is all about uniforms, which let us send parameters from the Java code into the vertex and fragment shader scripts.

We will add a vignette effect to our classic jungle background. The shader will create a circle in the center of the screen and darken everything that falls out of it. From the code, we will increase and decrease the circle's radius so that it looks like a scene transition. Refer to the following diagram for further clarity:

Getting ready

This recipe requires you to import the sample projects into your Eclipse workspace.

The code for the vignette shader is located in the following paths:

  • [cookbook]/samples/samples-android/assets/data/shaders/vignette.vert

  • [cookbook...