Difference in behavior of "cell" in jit.gen vs jit.gl.pix? Strange results!

catniptwinz's icon

Okay, I should definitely be asleep right now, but this has got me scratching my head.

I'm in the process of porting some jit.gen stuff to jit.gl.pix and was getting confusing results in a few cases, which led me to construct the following patch as a simple test case. It features an empty 4-plane float32 10x8 matrix feeding two identical patches, one in jit.gen (which behaves as expected) and one in jit.gl.pix (which does not). The patch SHOULD simply count the pixels in each frame from left to right, beginning at the top left corner and wrapping around at the end of every line.

jit.gen does this just fine, beginning at 0 and counting to 79, as you can see in the associated jit.cellblock. jit.gl.pix, however, seems to have an offset of 5.5 on each dimension. I tested the same patch with an 8x8 matrix and a 16x16 matrix and the offsets were 4.5 and 8.5, so I assume that the offset is always equal to 0.5 * dim.0 + 0.5

Max Patch
Copy patch and select New From Clipboard in Max.

I've visualized the output of jit.gl.pix by reading the texture back into a jit.matrix and looking at it in jit.cellblock, but I can also scale the values between 0 and 1 inside jit.gl.pix and observe the same issue in a pwindow. Am I missing some inherent aspect of working with jit.gl.pix? I'd love a better understanding of what's going on why!

catniptwinz's icon

Bump for more concise and lucid example.

The root issue is that texture coordinates produced by the cell object in jit.gl.pix appear to start from (0.5, 0.5) rather than (0, 0). Can anyone offer any insight into why this is? As with most things OpenGL, I assume that I've forgotten to set some obscure attribute…

Max Patch
Copy patch and select New From Clipboard in Max.

The attached patch shows a very simple example of this offset in action; a simple computation of cell coordinates in jit.gen, jit.pix, and jit.gl.pix that seems like it should return equivalent results, but doesn't.

Jim Bastow's icon

I've come across the same behaviour for the [norm] operator, and was wondering if there is an explanation for it anywhere?

I would expect the same results from the [norm] and [cell] operators inside jit.gen vs jit.gl.pix, but it seems that for jit.gl.pix, [norm] starts after [0, 0] and ends before [1, 1].

See patch for clarity:

Max Patch
Copy patch and select New From Clipboard in Max.