From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.

Introduction

Some users desire more control over materials than what the built in material settings provide. Those users often resort to writing their own GLSL shaders to gain greater control. This system offers an API to assist in authoring shaders, as well as an artist friendly user interface to make use of shaders.

Settings

Kupoman-custom-shader-ui.png

Custom shader settings can be found in the Material settings when the renderer is set to Blender Game. The Custom Shader panel allows the user to select what shaders to use for this material, as well as loading the source code for those shaders. Shader source code can come from either an internal location (Text data blocks) or an external location (file path).

When a shader is loaded, the Custom Shader Settings panel appears with options specific to the loaded shader.

API

Uniforms

Any uniforms declared in a shader are added to the user interface when a shader is loaded

Lights

Lighting data can be accessed in a shader by first including the light code:

#pragma bgl include lights

This line gets replaced by the following glsl code before the shader is compiled:

#ifndef MAX_LIGHTS
#define MAX_LIGHTS 4
#endif
struct Light {
	float dist;
	vec3 color;
	vec3 position;
};
uniform int bgl_lightcount;
uniform Light bgl_lights[MAX_LIGHTS];