Just after putting my shader at work I discovered that my fragment shader doesn’t evaluate the + and - signs while it correctly evaluates the * and / signs.
So if I use
pos.x = pos.x + 10
pos.x is unaffected, while
pos.x = pos.x / 2
pos.x is affected.
I define the shader source as string in C# and after reading the following article I start to be concerned about the source code string encoding.
Yes this is what I suggested to you, but I don’t know if it would be different.
I don’t understand why the compiler would skip operator +, there must be a syntax error somewhere else and this would be more visible in a text file.
Just a question, why do you code a shader in a string in the middle of C# code? This is awkward I think.
If you have Nvidia card you can use the NVemulate tool (maybe the GLExpert can do that too, I am currently not sure) to force the driver to write both source (as the driver sees it) and compiled shader + compilation logs into files put into application directory.
It says what you see below. By the way if I uncomment the commented line I see the texture altered while the line “pos.x = pos.x + 20.0;” don’t affect my texture. Does another reason exist? It is a problem to query a .st value out of the texture size?
//== PROGRAM LINK STATUS = TRUE
//== PROGRAM VALIDATE STATUS = TRUE
/*== INFO LOG ==
Fragment shader(s) linked, no vertex shader(s) defined.d == INFO LOG END ==*/
//======================================================
// Fragment Shader 1
//======================================================
//== SHADER COMPILE STATUS = TRUE
/*== INFO LOG ==
Fragment shader was successfully compiled to run on hardware. == INFO LOG END ==*/
// maximum size supported by this shader
const int MaxKernelSize = 49;
// size of kernel (width * height) for this execution
//uniform int KernelSize;
const int KernelSize = 49;
// array of offsets for accessing the base image
uniform vec2 Offset[MaxKernelSize];
// value for each location in the convolution kernel
uniform vec4 KernelValue[MaxKernelSize];
// image to be convolved
uniform sampler2D BaseImage;
void main()
{
int i = 0;
vec4 sum = vec4(0.0);
for (i = 0; i < KernelSize; i++)
{
vec4 tmp = texture2D(BaseImage, gl_TexCoord[0].st + Offset[i]);
sum += tmp * KernelValue[i];
}
vec2 pos = gl_TexCoord[0].st;
pos.x = pos.x + 20.0;
// pos.x = pos.x / 2;
gl_FragColor = texture2D(BaseImage, pos);
}
default texture wrap mode is GL_REPEAT for all texture cordinates. So the integer part of each coordinate is ignored.
That explains why adding a big round value like 20 doesn’t change anything.