This file contains description for ODSL (OD Shading Language).
Main purpose for defining own shading language for ODlib-project is both to increase portability and expressibility of shader code, and reducing the need to write different shaders for different platforms.
ODSL is deisgned around concepts of functional programming languages. Shader can actually be considered as a mathematical function that takes certain inputs and gives outputs. For example a vertex shader is merely a mathematical function that is applied per vertex.
ODSL parser in ODlib will be implemented using Boost.Spirit parser framework which generates recursive descent parser (LL(inf)-parser). Grammar is written in inline C++ using PEG (Parsing Expression Grmmar) which is derivative of EBNF.
At some point. Compatibility modes for output languages should be considered. It might not be possible to compile shader into different target languages in some cases, since constraints of shading languages differ. It might be good idea to design some kinds of profiles for different target platforms.
Types should be compatible with native types of target shading languages.
bool int float Vector2, Vector3, Vector4 BVector2, BVector3, BVector4 Matrix2, Matrix3, Matrix4 Texture2D
Value that does not change while processing the same primitive. Input parameter which stays same for every shader instance.
Value that changes per vertex. There can be multiple attributes per vertex.
Value that is written per vertex in vertex shader and gets interpolated per fragment in fragment shader.
[] () .
- /
< > <= => == != && ^^ ||
= += -= *= /=
,
uniform Matrix4 mvp_matrix;
uniform Matrix3 normal_matrix;
uniform Vector3 light_dir;
attribute Vertex3 a_vertex;
attribute Vertex3 a_normal;
attribute Vertex2 a_texcoord;
varying float v_diffuse;
varying Vector2 v_texcoord;
Vector3 ec_normal = normalize(normal_matrix * a_normal);
v_diffuse = max(dot(light_dir, ec_normal), 0.0);
v_texcoord = a_texcoord;
od_position = mvp_matrix * a_vertex;
TODO
TODO
TODO
TODO
TODO
See odlib.git/src/od/graphics/odsl/Lexer.hpp
See odlib.git/src/od/graphics/odsl/Grammar.hpp