Shader

The Shader class handle the compilation of the Vertex and Fragment shader, and the creation of the program in OpenGL.

Todo

Write a more complete documentation about shader.

Header inclusion

New in version 1.0.7.

When you are creating a Shader, Kivy will always include default parameters. If you don’t want to rewrite it each time you want to customize / write a new shader, you can add the “$HEADER$” token, and it will be replaced by the corresponding shader header.

Here is the header for Fragment Shader:

#ifdef GL_ES
    precision highp float;
#endif

/* Outputs from the vertex shader */
varying vec4 frag_color;
varying vec2 tex_coord0;

/* uniform texture samplers */
uniform sampler2D texture0;

And the header for Vertex Shader:

#ifdef GL_ES
    precision highp float;
#endif

/* Outputs to the fragment shader */
varying vec4 frag_color;
varying vec2 tex_coord0;

/* vertex attributes */
attribute vec2     vPosition;
attribute vec2     vTexCoords0;

/* uniform variables */
uniform mat4       modelview_mat;
uniform mat4       projection_mat;
uniform vec4       color;
class kivy.graphics.shader.Shader

Bases: object

Create a vertex or fragment shader

Parameters :
vs: string, default to None

source code for vertex shader

fs: string, default to None

source code for fragment shader

fs

Fragment shader source code.

If you set a new fragment shader source code, it will be automatically compiled and replace the current one.

success

Indicate if shader is ok for usage or not.

vs

Vertex shader source code.

If you set a new vertex shader source code, it will be automatically compiled and replace the current one.