Introduction
This file is not a shader tutorial. You should be familiar with the OpenGL shading language if you want to understand all of this.
The shaders are specified in a xml file. The root node of this file is shaders, containing all shaders that could be used within EL.
shaders
This is the root node, containing all shaders in the file.
format:
<shaders>
<shader>...</shader>
...
</shaders>
shader
This tag contains all the informations that make the shader. They are name, vertex and fragment shader and the uniforms.
format:
<shader>
<name>...</name>
<vertex_shader>...</vertex_shader>
<fragment_shader>...</fragment_shader>
<shader_uniforms>...</shader_uniforms>
</shader>
name
The name of the shader. The name must be unique, because name is used to tell EL what shader should be used.
format:
<name></name>
example:
<name>3dobject/normal mapping</name>
vertex_shader
The list of vertex shaders to use. Every vertex shader can have as many files as you like.
All the files are compiled and then attached to the program.
If you don't specify a vertex shader, then the default OpenGL vertex processing is used.
format:
<vertex_shader>
<file_name></file_name>
...
</vertex_shader>
If you specify the vertex_shader tag, then you must specify at least one file name.
example:
<vertex_shader>
<file_name>normal_mapping_vs.glsl</file_name>
</vertex_shader>
fragment_shader
The list of fragment shaders to use. Every fragment shader can have as many files as you like.
All the files are compiled and then attached to the program.
If you don't specify a fragment shader, then the default OpenGL fragment processing is used.
format:
<fragment_shader>
<file_name></file_name>
...
</fragment_shader>
If you specify the fragment_shader tag, then you must specify at least one file name.
example:
<fragment_shader>
<file_name>normal_mapping_vs.glsl</file_name>
</fragment_shader>
shader_uniforms
The list of shader uniforms. Both uniforms and auto_uniforms are supported and can be mixed freely in any order.
format:
<shader_uniforms>
<uniform>...</uniform>
<auto_uniform>...</auto_uniform>
....
</shader_uniforms>
uniform
This command sets the value of a constant uniform parameter.
format:
<uniform>
<name></name>
<type></type>
<values></values>
</uniform>
'values' is simply a comma-delimited list of values which can be converted into the type you have specified.
All types of GLSL version 1.10 are supported, also codeler2DRect and codeler2DRectShadow.
example:
<uniform>
<name>test</name>
<type>vec4</type>
<values>10.0, 0, 1, 2</values>
</uniform>
auto_uniform
This command tells EL to automatically update a given parameter with a derived value.
This frees you from writing code to update uniform parameters every frame when they are always changing.
format:
<auto_uniform>
<name></name>
<type></type>
<index></index>
<size></size>
<texture></texture>
</auto_uniform>
The index, size and texture parameter are only available if the given auto_uniform type needs them.
- index
- Index into the light array of the object, to get the light data of the given index light.
- size
- Size of the array that holds the data.
- texture
-
Specifies the needed texture. The following values are supported:
- diffuse
- The default diffuse texture of the material.
- extra_diffuse
- The second/extra diffuse texture of the material.
- shadow
- The shadow texture used for this object.
- reflection
- The reflection texture used for this object.
- clouds
- The clouds texture.
- normal
- The normal texture used for this material.
- specular
- The specular texture used for this material.
- jitter_noise
- A 3d noise texture used for 2d jitter of texture coordinates.
Supported types for uniform constants that are automatically updated:
- time
- Current time (in seconds), float(time).
- cos_time
- Cosines of current time (in seconds), float(cos(time)).
- sin_time
- Sinus of current time (in seconds), float(sin(time)).
- tan_time
- Tangent of current time (in seconds), float(tan(time)).
- packed_time
- Current time. Packed as vec4(time, cos(time), sin(time), tan(time)).
- light_count
- Number of active lights, int(light_count).
- light_diffuse_color
- Light diffuse color parameters, vec3(red, green, blue). An extra index parameter into the light array of the current object is needed.
- light_specular_color
- Light specular color parameters, vec3(red, green, blue). An extra index parameter into the light array of the current object is needed.
- light_attenuation
- Light attenuation parameters, vec4(range, constant, linear, quadric). An extra index parameter
into the light array of the current object is needed.
- light_position
- Light position parameters, vec4(x, y, z, not_directional).
For directional lights, x, y and z are the light direction and not_directional is zero.
For non directional lights, x, y and z are the position of the light and not_directional is one. This let you use code like this:
new_light_dir = light_position.xyz - position.xyz * light_position.w;
An extra index parameter into the light array of the current object is needed.
- spotlight_params
- Spotlight parameters, vec2(cos(cutoff), exponent). For non spotlights, cutoff is 180.0° and exponent is 0.0.
An extra index parameter into the light array of the current object is needed.
- light_params
- Light parameters, vec4(range, quadric, cos(cutoff), exponent). For non spotlights, cutoff is 180.0° and exponent is 0.0.
An extra index parameter into the light array of the current object is needed.
- light_direction
- Light direction, vec3(dx, dy, dz). Light direction for spot lights, zero for other lights.
An extra index parameter into the light array of the current object is needed.
- light_diffuse_color_array
- Light diffuse color parameters array, vec3(red, green, blue). An extra size parameter for the size of the array is needed.
- light_specular_color_array
- Light specular color parameters array, vec3(red, green, blue). An extra size parameter for the size of the array is needed.
- light_attenuation_array
- Light attenuation parameters array, vec4(range, constant, linear, quadric). An extra size parameter for the size of the array is needed.
- light_position_array
- Light position parameters array, vec4(x, y, z, not_directional).
For directional lights, x, y and z are the light direction and not_directional is zero.
For non directional lights, x, y and z are the position of the light and not_directional is one. This let you use code like this:
new_light_dir = light_position[i].xyz - position.xyz * light_position[i].w;
An extra size parameter for the size of the array is needed.
- spotlight_params_array
- Spotlight parameters array, vec2(cos(cutoff), exponent). For non spotlights, cutoff is 180.0° and exponent is 0.0.
An extra size parameter for the size of the array is needed.
- light_params_array
- Light parameters array, vec4(range, quadric, cos(cutoff), exponent). For non spotlights, cutoff is 180.0° and exponent is 0.0.
An extra size parameter for the size of the array is needed.
- light_direction_array
- Light direction array, vec3(dx, dy, dz). Light direction for spot lights, zero for other lights.
An extra size parameter for the size of the array is needed.
- scene_ambient_color
- Scene ambient color, vec3(red, green, blue).
- texture_size
- Provides texture size of the texture unit. Packed as ivec3(width, height, depth). Texture is defined by an extra texture parameter.
- inverse_texture_size
- Provides inverse texture size of the texture unit. Packed as vec3(1.0 / width, 1.0 / height, 1.0 / depth).
Texture is defined by an extra texture parameter.
- packed_texture_size
- Provides packed texture size of the texture unit. Packed as vec4(width, height, 1.0 / width, 1.0 / height).
Texture is defined by an extra texture parameter.
- fog_color
- Fog color, vec3(red, green, blue).
- fog_params
- Fog params, vec4(linear end, 1.0 / (linear end - linear start), density * log2(e), density * density * log2(e)).
- world_matrix
- World 4x4 matrix of the object.
- reflection_matrix
- Reflection 4x4 matrix of the scene.
- shadow_matrix
- Shadow 4x4 matrix of the scene.
- clouds_params
- Clouds params, vec4(cos(rot_z) / texture_scale, sin(rot_z) / texture_scale, 1.0f / texture_scale, obj_x_pos / texture_scale + clouds_movement_u),
and vec4(-sin(rot_z) / texture_scale, cos(rot_z) / texture_scale, 1.0f / texture_scale, obj_y_pos / texture_scale + clouds_movement_v).
- texture
- Texture codeler of texture is defined by an extra texture parameter.
Example
An example shader for procedural texturing, using only the clouds and noise texture.
Lightning is done per pixel, with changing diffuse and specular lightning, depending on the procedural texture generation.
All types of light are supported, up to three lights. This is the code of the hole xml file:
example:
<?xml version="1.0" encoding="UTF-8"?>
<shaders>
<shader>
<name>procedural stone texture</name>
<vertex_shader>
<file_name>procedural_stone_vs.glsl</file_name>
</vertex_shader>
<fragment_shader>
<file_name>procedural_stone_fs.glsl</file_name>
</fragment_shader>
<shader_uniforms>
<auto_uniform>
<name>world_matrix</name>
<type>world_matrix</type>
</auto_uniform>
<auto_uniform>
<name>clouds_data</name>
<type>clouds_params</type>
</auto_uniform>
<auto_uniform>
<name>light_pos</name>
<type>light_position_array</type>
<size>3</size>
</auto_uniform>
<auto_uniform>
<name>light_dif_colors</name>
<type>light_diffuse_color_array</type>
<size>3</size>
</auto_uniform>
<auto_uniform>
<name>light_spec_colors</name>
<type>light_specular_color_array</type>
<size>3</size>
</auto_uniform>
<auto_uniform>
<name>light_params</name>
<type>light_params_array</type>
<size>3</size>
</auto_uniform>
<auto_uniform>
<name>light_dirs</name>
<type>light_direction_array</type>
<size>3</size>
</auto_uniform>
<auto_uniform>
<name>ambient</name>
<type>scene_ambient_color</type>
</auto_uniform>
<uniform>
<name>base_dif_color</name>
<type>vec4</type>
<values>0.37, 0.37, 0.37, 1.0</values>
</uniform>
<uniform>
<name>extra_dif_color</name>
<type>vec4</type>
<values>0.7, 0.6, 0.5, 1.0</values>
</uniform>
<auto_uniform>
<name>noise_texture</name>
<type>texture</type>
<texture>jitter_noise</texture>
</auto_uniform>
<auto_uniform>
<name>clouds_texture</name>
<type>texture</type>
<texture>clouds</texture>
</auto_uniform>
<uniform>
<name>base_spec_color</name>
<type>vec4</type>
<values>0.37, 0.37, 0.37, 1.0</values>
</uniform>
<uniform>
<name>extra_spec_color</name>
<type>vec4</type>
<values>1.0, 1.0, 1.0, 1.0</values>
</uniform>
</shader_uniforms>
</shader>
</shaders>