What is the difference between "sample and "nearest" in jit.gl.pix?

mirrorboy's icon

Jitter / jit.gl.pix is my favorite for VJing. I don't notice any difference between the two. Is this a bug? If possible, I prefer the 'nearest' behavior not to interpolate.

Thank you.

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

👽'tW∆s ∆lienz👽's icon

i wondered about this too, and eventually thought maybe it was something i couldn't quite understand since i don't use any appropriate context to appreciate the difference, but that it was related to the original definitions of these functions sourced from OpenGL:

from that page, specifically found this helpful:

"This value can be GL_LINEAR or GL_NEAREST. If GL_NEAREST is used, then the implementation will select the texel nearest the texture coordinate; this is commonly called "point sampling". If GL_LINEAR is used, the implementation will perform a weighted linear blend between the nearest adjacent samples."

(the 'sample' op is using this OpenGL sampler object, with 'GL_TEXTURE_MAG_FILTER' set to 'GL_LINEAR', while 'nearest' op uses the same OpenGL sampler object but with the '...MAG_FILTER' set to 'GL_NEAREST'... this is just how i came to understand it, but someone correct me if i'm wrong 🤷)

mirrorboy's icon

Thank you for your response.

It seems like linear interpolation from GL_LINEAR is affecting both cases.

Is it an issue with implementing the OpenGL specifications in Max, or is GL_NEAREST being ignored or not properly implemented at driver level?

yaniki's icon

Sample vs nearest is a mistery to me too. I presumed, that “nearest” is quantised to the nearest pixel, but it’s not ;-)

Rob Ramirez's icon

Since the sampling operators take normalized coordinates in the range [0, 1], differently sized input textures will still be properly sampled using the norm operator since its value is independent of varying input sizes. However, in jit.gl.pix the sample and nearest operators behave differently than with jit.pix . How a texture is sampled is determined by the properties of the texture. As a consequence, sample and nearest behave the same injit.gl.pix . To enable nearest sampling, set the @filter attribute to nearest. For linear interpolation, set @filter to linear (the default).

sendoutput filter none

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

👽'tW∆s ∆lienz👽's icon

(oh my bad, i always forget this part too: "However, in jit.gl.pix the sample and nearest operators behave differently than with jit.pix")

Thank You, Rob!🏅

mirrorboy's icon

Thanks, Rob!

Your example helped me understand how to get input textures without interpolation.

One request: instead of setting "sendoutput filter none," which is complicated and easy to forget, it would be great if "nearest" didn't interpolate and "sample" did.