So finally only one thing is still missing from the new system:
The shader source code format
I've thought about it, the user should be able to have a maximum of flexibility to write their shaders but i also want a unified shader interface.
So i need some kind of markup language around the shader source files
XML doesn't really work because the contained glsl code may contains < or > so no option
JSON is another spread markup language. But its syntax isn't that easy to read.
So my solution was Lua. The engine already has a lua scripting interface so easy integration for me. Also way more options for the user to create shaders.
Here is a basic example for an object shader:
-- We compile with GLSL Version 3.3
shader.version = "330"
-- Add a global shader source file that is accessible from all shaders:
shader.add
{
type = "global",
source =
[[
uniform mat4 matWorld;
uniform mat4 matView;
uniform mat4 matProjection;
uniform sampler2D meshDiffuseTexture;
]]
}
-- Add a vertex shader. The input variables and layout is specified by the input entry
shader.add
{
type = "vertex",
input = "mesh",
source =
[[
out vec2 uv;
void main()
{
vec4 pos = vec4(vertexPosition, 1);
gl_Position = matProjection * matView * matWorld * pos;
uv = vertexUV;
}
]]
}
-- Add a fragment shader. Simple alpha-testing shader.
shader.add
{
type = "fragment",
source =
[[
layout(location = 0) out vec4 color;
in vec2 uv;
void main()
{
color = texture(meshDiffuseTexture, uv);
if(color.a < 0.5f) discard;
}
]]
}
Imho this solution is really acceptible because it is easy to read and provides flexibility.
The coolest thing is that your shaders are not static code.
You can easily create a shader based on the system specs or some dynamic settings based on os, graphics card, ...
What do you think?