I’m planning to write a transpiler for a new shading language as a final year college project. This transpiler will read the SESL (what I call until I come up with a good name) code and produce valid GLSL or GLSL ES code. You can find the current thoughts here:
A glimpse of the code is as follows:
// Import shader functions from libraries
import sesl.phong.*;
import sesl.lights.*;
// Declare the VertexShader called as MyShader. This will be
// compiled to the output file MyShader.vert.glsl
shader vert MyShader
{
uniform mat4 mv;
uniform mat4 mvp;
in vec3 position;
// Pass variables are similar to inputs, but they are automatically
// passed to the next shader stage.
pass vec3 normal;
pass Material material;
pass PointLight pointLight;
// Additional outputs can be added here
out vec3 vertex;
// The main shader function. Note that we avoid having a gl_ variables.
// The return value of the main function will be automatically assigned
// to gl_Position in GLSL target.
vec4 main()
{
vert = vec3(mv * vec4(position, 1.0));
return mvp * vec4(position, 1.0);
}
}
// Declare the FragmentShader called as MyShader. This will be
// compiled to the output file MyShader.frag.glsl
shader frag MyShader
{
// out variables of vertex shader as well as the pass variables
// are in variables in the fragment shader here.
in vec3 vertex;
in vec3 normal;
in Material material;
in PointLight pointLight;
// The main shader function. Older GLSL has gl_FragColor and in modern
// GLSL, we have to declare an output of vec4 and assign to that. In
// SESL, the shader simply returns the fragment color, which will be
// handled automatically.
vec4 main()
{
// Call the phong function from the sesl.phong package.
return phong(pointLight, material, vertex, normal);
}
}
You can extend shaders to create new ones!
import sesl.Math;
import sesl.Color;
shader frag MyNewShader extends MyShader {
vec4 main() {
return Math.mix(Color.BLUE, super.main(), 0.5);
}
}
This is an interesting project to be done for a final year project. I’d like to know your opinions guys.