Shaders

Shaders are very useful as they allow a lot of the complex work required to apply textures and lighting to an object by offloading the task to the more powerful GPU in Raspberry Pi. The Shader class is defined as follows:

class pi3d.Shader.Shader(shfile=None, vshader_source=None, 
                                      fshader_source=None) 

This allows you to specify a shader file (shfile) and specific vertex and fragment shaders (if required) within the file.

There are several shaders included in the pi3d library, some of which allow multiple textures to be used for reflections, close-up details, and transparency effects. The implementation of the shader will determine how the lights and textures are applied to the object (and in some cases, such as uv_flat, the shader will ignore any lighting effects).

The shader files are listed in the pi3dshaders directory. Try experimenting with different shaders, such as mat_reflect, which will ignore the textures/fonts but still apply the lighting effects, or uv_toon, which will apply a cartoon effect to the texture.

Each shader consists of two files, vs (vertex shader) and fs (fragment shader), written in C-like code. They work together to apply the effects to the object as desired. The vertex shader is responsible for mapping the 3D location of the vertices to the 2D display. The fragment shader (sometimes called the pixel shader) is responsible for applying lighting and texture effects to the pixels themselves. The construction and operation of these shaders is well beyond the scope of this chapter, but there are several example shaders that you can compare, change, and experiment with within the pi3dshaders directory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.93.175