Shader engine generel questions

Started by
13 comments, last by Shaarigan 12 years, 5 months ago

There isnt any way to combining compiled shaders in opengl because you can link only one shader of each type to a program. Also there isnt any #include-statement in GLSL.
In generating a shader i push my shader file as a set of strings to the api and ink al shaders (fragment, vertex) to a program. So i dont know any dynamic linking mechanic.
The example i've given above is what it is pointing on !!


Yeah I realized that we are talking about opengl here and that it doesn't have existing solutions for dynamic shader linkage (as far as I know from a short research on the net). Yes, you can make your own parser for the shader files to handle #including files for redundant shader code.

Have you considered deferred shading or übershaders?


Advertisement
I think im orienting on bigger solutions like Unreal, that uses a system of basic and included shaders so i use the deffered version
with a set of basic shaders and some specielized ones with includes

[quote name='kauna' timestamp='1320565832' post='4881004']
This doesn't really make sense. There shouldn't be any reason to "manage #include tags or copy shader files together". It is more like compiling a shader with certain set of flags (the übershader case) or compiling shader parts and joining them together with the opengl api (the dynamic linkage case).


There isnt any way to combining compiled shaders in opengl because you can link only one shader of each type to a program. Also there isnt any #include-statement in GLSL.
In generating a shader i push my shader file as a set of strings to the api and ink al shaders (fragment, vertex) to a program. So i dont know any dynamic linking mechanic.

The example i've given above is what it is pointing on !!
[/quote]

Actually, you can link several shaders together as long as there is only 1 main() function.

Also, there is the include feature now. It is an extension for now
http://www.opengl.or...age_include.txt
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Also #include is pretty straight-forward to implement on your own anyway. Since you are the ones writing the shaders, there is no reason a most-basic parser will not work.

I suggest going with uber shaders though. It is straight-forward and simple to implement.
You basically just associate one #ifdef with one bit flag in your code.
You ask for shaders from your shader manager (at the time of rendering) by sending bit flags that tell the manager what kind of shader you want (one with normal mapping, one without, etc.) and when it sees a given flag it sends the matching macro to the shader. Now you have permutations, and it was that simple.
The shader creation flags are remembered by the manager, so next time you ask for the same shader you will get the one that was already compiled.

The important thing in any case is to request shaders at the actual time of rendering. This is the only time you can check for lighting being enabled and other system states.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


Actually, you can link several shaders together as long as there is only 1 main() function.

Also, there is the include feature now. It is an extension for now
http://www.opengl.or...age_include.txt


Ah ok, good to know. But i think it isnt availible on older cards (like mine radean hd 2600) isnt it?


Also #include is pretty straight-forward to implement on your own anyway. Since you are the ones writing the shaders, there is no reason a most-basic parser will not work.

I suggest going with uber shaders though. It is straight-forward and simple to implement.
You basically just associate one #ifdef with one bit flag in your code.
You ask for shaders from your shader manager (at the time of rendering) by sending bit flags that tell the manager what kind of shader you want (one with normal mapping, one without, etc.) and when it sees a given flag it sends the matching macro to the shader. Now you have permutations, and it was that simple.
The shader creation flags are remembered by the manager, so next time you ask for the same shader you will get the one that was already compiled.


Creating a shader preprocessor isnt as strength to me as you might think. I already build a 'compiler' for a scripting alguage with dynamic loaded syntax and
commands based on an ebnf pattern struct. I only have to change this a little, managing several includes ionto one file an well it is.

To had the idea with the flags too but in a different way. My engine only contains the main propertys per object (like only position and orientation of a mesh) and the other
propertys are modified by either there is an existing property (like color) so there is a filter object added, that modifies the property or it is a completly new ability (like a clipping function)
then there is a propperty handler added. Now im able to add a flag handler to a shader object that modifies some known flags or uniforms every time the shader is activated.

This topic is closed to new replies.

Advertisement