Jump to content
  • Advertisement
Sign in to follow this  
Bergmann89

OpenGL ShaderFile (a PreCompiler for OpenGL Shader Code)

This topic is 997 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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));
}

Links:
Gitlab WebFrontend
Licence
Documentation (save as and view offline)

Downloads:
git clone: gitlab@git.ccs-baumann.de:bitspace/ShaderFile.git
Download lastest Source (as zip)
libShaderFile (v1.0.0.4 i386 Linux)
libShaderFile (v1.0.0.4 x86_64 Linux)
libShaderFile (v1.0.0.4 i386 Win32)
libShaderFile (v1.0.0.4 x86_64 Win64)
 

Edited by Bergmann89

Share this post


Link to post
Share on other sites
Advertisement

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.

 

The latest download is available in the first post.

 

Greetings Bergmann.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!