Hello. I have custom glsl fragment shader files and am drawing them using rect(). I want the shader to be drawn as if it was an image, which means all the information should be present when drawn, and it should stretch depending on the dimensions passed in rect() and to the shader.
As it stands the shaders are being drawn relative to the canvas. The same pixels in the canvas will always have the same color regardless of the size and position of the rect(), as if the shader was being masked. Changing the size of the canvas stretches the shader.
From what I could find online, passing the dimensions information to the shader and normalizing the pixel values should do it. But the resolution variable is having no effect on the shader whatsoever. What am I missing?
gl_FragCoord.xy gives the window coordinates of the pixel independent of whatever triangle it is drawn from. It’s convenient to use when you want a full-screen fragment shader, but not what you want for arbitrary textured geometry. For that, you need to use texture coordinates. Processing generates vec4 texCoord coordinates for its geometry. For a rect(), they go from 0 to 1 in the xy channels. (I’m not sure what, if anything, is stored in the zw channels.)