I am completely new to shader and need help with the following. I have two shader working (see below) and I changed the fragment shader with the one at the bottom (gaussian blur). Why I get an GL_INVALID_VALUE error? Should I init some values?
The color vector is initialized incorrectly. It should be:
vec4 color = vec4( 0.0 );
Additionally some hw does not support dynamic indexing into constant arrays in the pixel shader. If on such hw the driver fails to unroll the for loop, the compilation might also fail. You can use the glGetShaderInfoLog function to retrieve string describing compilation or linking errors.
If you want to see the reason of your invalid errors try to compile manually your shader using Cg compiler for example, or at running time, check the shader compilation infoLog, which contains all the syntax errors that cause the compilation failing.
Look at the glGetShaderInfoLog function that is very useful to retrieve many informations about your shaders.
External applications for checking shaders are: GLSL Validate This is somewhat older tool without support for never versions of the GLSL language. In my experience it can be sometimes confused by #ifdef statements.
Cg Toolkit While intended for the Cg language it can be used to compile GLSL shaders using the -oglsl command line parameter. The same compiler is used in the Nvidia drivers.
GLExpert This program can enable automatic dump of compiled shaders and log files into directory of the program which compiled them. Works only on Nvidia cards.
Even in C this would not work since you are not allocating the memory the for this array.
you have to put a constant value between the brackets to define the size of the array. Dynamic allocation and pointers are not supported in glsl shaders, you can only create static arrays. Some nvidia cards will allow you to put a variable between the brackets compiling with their own specific profile.
EDIT:
I have never tested but I think you can do something like:
float plop[] = {0.0, 1.0, 2.0};
Since the compiler will know at compile time the array size.
Just a clarification, as a programmer I am a little concerned about all these ’ should work ', ’ on my geforce it works ', ’ nvidia GPU are more tolerant ': isn’t the shading language “A STANDARD” ?
My last fragment shader apparently has no syntax errors, why it doesn’t work yet?
Because different vendors have their own ideas, because the implementations are buggy and because the hardware differs. It’s a shame, but GLSL, while being a “standard”, isn’t just standard enough…
Yes, I completely share your concern… GLSL is a standard in my opinion but not pushed further enough. It looks like IHV, can’t agree on standards and always put their fancy functionnalities to make the difference…this is a shame and the cause of many headaches for game developers.
And, putting the array initialization in a function like main, resolved the problem or not? If it doesn’t it may works all the same using in your application. I don’t know how GLSL validate works but for instance the Cg compiler gives me more information about the syntax error.
I meant that you can keep the gaussFilter array as a global variable and do the initialization in a function, but if you don’t need a global variable let your shader like this.
For the next problem, I don’t see the cause, what is the error?
EDIT:
On some hardware, indexing arrays with variables causes problems like on some ATIs but works fine on nvidia ones. I have myself problems to understand this disparities.
What is amazing is the line just before that is very similar to the commented one and don’t causes any compilation errors…