GLSL Integer Modulus Operation

I notice the C modulus operator “%” doesn’t work without GL_EXT_gpu_shader4 enabled, which I would prefer not to do. Furthermore, I don’t know if that would be eqivalent the basic C modulus function. I see there are a few versions of the “mod” function:

genType mod(genType x, genType y);
genDType mod(genDType x, genDType y);

The specification describes these functions as taking float values. I don’t understand the type specifiers “genType” and “genDType” referenced before.

How can I do a simple modulus operation? The Equivalent C code would be:

int sourceNumber  = 97;
int oddEven = sourceNumber%2;

which I would prefer not to do.

Then you’re not going to get integer operations. Either you’re using GL 3.x+ hardware (which can do integer operations), or you’re not and you’ll have to make do with floating-point.

I don’t understand the type specifiers “genType” and “genDType” referenced before.

The spec is pretty clear about what those mean. Just go to the top of the document and search for “genType”; the first hit defines it. FYI: it means any floating-point vector or float.

Basically, you can pass two vec4’s to mod and get back the mod applied component-wise.

Thanks Alfonse. I enabled the extension it compiles fine with C-style modulus code.