PDA

View Full Version : ShaderFile (a PreCompiler for OpenGL Shader Code)



Bergmann89
09-27-2015, 10:38 AM
Hey Guys,

i've developed a pre compiler for OpenGL Shader Code, called ShaderFile. With the ShaderFile Project you be able to manage large shader code and produce a simple and small output file. The generated code is normally interpreted, compiled and linked by an OpenGL shader object.

a short overview over the most important commands and features:
- as known from the normal pre compiler you can use if commands to add another path to the code generation
- using the include command, you can spread your code over more than one file
- with the class command you can define a class like strukture to manage your shader code; within a class you can overwrite member methods from base classes
- you can define properties which values are set inside the application code to control the shader code generation
- and much more...

The project is written in FPC. It can be used directly in your FPC project or as shared library. The shared library is available for Windows and Linux as 32bit and 64bit binary. The library also includes header files for C, C++, FPC and Delphi.

a simple example for a class:

{$CLASS Color}
{$PROPERTY UseColorMap 'false'}
{$END}

{$CLASS ColorFrag $EXTENDS Color}

/* you can also define code here. It will be added when the code for the class is generated */

{$FUNC 'vec4' GetColor $INLINE}
{$IF UseColorMap}
{$VAR 'vec2' '_texCoord' 'gl_TexCoord[0].st'}
{$UNIFORM 'sampler2D' 'uColorMap'}
return texture2D(uColorMap, _texCoord);
{$ELSE}
return gl_Color;
{$END}
{$END}

{$MAIN}
gl_FragColor = {$CALL GetColor};
{$END}
{$END}

{$CLASS ColorVert $EXTENDS Color}
{$MAIN}
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
{$IF UseColorMap}
gl_TexCoord[0] = gl_MultiTexCoord0;
{$ELSE}
gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;
{$END}
{$END}
{$END}

resulting code for ColorFrag with UseColorMap = true:

/* you can also define code here. It will be added when the code for the class is generated */

uniform sampler2D uColorMap;

vec2 _texCoord = gl_TexCoord[0].st;

void main(void)
{
gl_FragColor = (texture2D(uColorMap, _texCoord));
}

Unfortunately i can not add any links to this post. So if you are interested in this project please contact me or reply to this post.

Greetings Bergmann89.

Bergmann89
10-13-2015, 12:52 PM
Hey Guys,

i've just uploaded a new version (v1.0.0.3). The new version contains the feature to load shader files from a callback function, respectively an suitable interface. With this feature you be able to load the shader code from a database, a virtual file system or something like that.

The function was already available in the source code, but not implemented in the library. So for those of you, who used the source directly there are no changes.

Greetings Bergmann.

Bergmann89
10-27-2015, 10:49 AM
Hey Guys,

i've just released an update (v1.0.0.4) with some small bugfixes. I would be pleased to get some feedback about my library from you :)

Greetings Bergmann.

Alfonse Reinheart
10-27-2015, 12:55 PM
Well, there's really not much useful feedback that I could give about it.

1: There's no link to your project. That makes it hard to try it and provide feedback. Note that new users are prevented from posting links to avoid spam, but new users can still submit OpenGL news items (https://www.opengl.org/news/submit/). Also, you could have just mentioned where we could find the project (GitHub, Bitbucket, SourceForge, etc). Something that a Google search could be used to track down.

2: It's written in Free Pascal, which is not a language/toolset that I use. So to even try it, I either have to use a raw DLL or download and install the Free Pascal compiler distribution. I'm not going to install a whole compilation suite for a language I never intend to use just to use your tool.

3: Your macro-language makes shader code look absolutely hideous. The syntax constantly pokes you in the eye with ALL CAPS. And what's with everything being in a class; what's the point of that sort of thing? It seems like taking bad ideas from Java.

I understand and appreciate what you're trying to accomplish, but if it means having to write my shader code like that, I'll stick with actual GLSL macros.

If you're going to make that many changes in the language, It'd be better if you just made a whole new language than this sort of macro-language. Obviously new languages aren't easy to write or design, but they're a lot easier to use. And people use languages more than they write them.