Replacing Cg - BSD licensed shader front / back end and runtime

FoxMcCloud

Newcomer
Hi,

I've been trying to move away from Cg for a while now because of the time it takes to get feature requests and bug fixes in addition to the fact that it doesn't play nicely with OpenGL 3.x core contexts. After a significant amount of work I finally have a working replacement and I'd like to hear everyone's $0.02.

The project I have came out of an internal renderer abstraction library called LiteGraph and is called the LiteGraph Shader Language, or LGSL. No play on words regarding GLSL was intended. It is basically Cg with some minor changes like attribute semantics being called ATTRIBUTE_n and interpolator semantics being explicitly referred to as interpolators (INTERPOLATOR_n) as opposed to texture coordinates (TEXCOORD_n) in vanilla Cg. The other major change is that mul() isn't part of the standard library, and matrix-vector multiplication is performed using the overloaded operator *.

The shader source is passed at runtime to a parser, which builds a parse-tree and has the front end add annotations to it. The GLSL backend takes that parse tree and converts it to GLSL 3 core with ARB_separate_programs. The runtime layer extracts the uniform information from that GLSL parse tree and exposes the ability to set their values to the user.

The system is highly decoupled and backends don't take a large amount of time and / or code to write - the GLSL backend is under one thousand lines of code. I plan to add more backends / runtimes for platforms that I deploy to (and feel free to add your own publicly or in a fork) and the rich parse tree even allows for code analysis and transformations like variable renaming with very few lines of code. For example, here's the code that extracts uniform information from a GLSL shader's parse tree: https://gist.github.com/sherief/5521687

Here's a small (~100 LOC) program that uses basic LGSL shaders and the OpenGL runtime to create a rotating triangle using GLFW and an OpenGL 3.2 Core profile with ARB_separate_programs: https://gist.github.com/sherief/5521281

And here's a video of that program running on my MBP Retina with OS X 10.8.3: https://vimeo.com/65504625

Right now the code uses some C++11 features like initializer lists that aren't yet supported by Visual Studio, but Microsoft has indicated that support is coming during 2013 and since I don't plan to ship anytime soon I'm planning to wait till they catch up rather than perform the (admittedly small but tedious) changes needed to run on Win32. If there's significant interest in a Win32 port I might consider getting it up and running on VS2012 though - let me know. Right now the code comes with Xcode projects and uses Clang and libc++ on OS X - which shouldn't be a problem for that platform since you need OS X 10.8.3 (the latest version as of the time of writing) for ARB_separate_programs support anyway.

You can find the source code for the compiler (embeddable library) at:
https://bitbucket.org/sherief/litegraph-shader-compiler

The OpenGL 3.x Core runtime is at:
https://bitbucket.org/sherief/litegraph-shader-opengl-runtime

A command-line driver for the compiler library can be also found at:
https://bitbucket.org/sherief/litegraph-shader-compiler-driver

Everything is BSD licensed. Let me know what you think.
 
Back
Top