Question: Are texture samples specified to be taken at a corner or center?
When calling, e.g., textureSampleGrad(tex, sampler, st, dst_dx, dst_dy), is the effective sampled area of the texture a patch with "origin" at st, e.g. st + J * xy, with xy in [0,1]^2 and J the Jacobian to sample? Or is st the center of the sampled patch, with st in [-0.5, 0.5]`? Or something else?
What does the spec say? I couldn't find anything explicit, but I might not be searching for the right keywords.
Maybe this helps: https://docs.pygfx.org/stable/_gallery/validation/validate_image1.html (the texture coords of a plane geometry are [0..1]).
When you sample from a texture, the st represents the "center" of the sample. E.g. with linear interpolation you'd get the exact pixel value when st is exactly on top of a pixel, but if it's in between two pixels, you get the mean.
Does this make sense? Or are you asking for a specific detail for the Grad-variant of texture sampling? I'm not 100% sure I understand the question.
A, B, or C?
It sounds like maybe "B"?
It's A but y flipped.
See the version at the bottom of the readme here https://github.com/gfx-rs/wgpu?tab=readme-ov-file#coordinate-systems
@Vipitis I'm worried you might be answering a question I'm not asking, since in this diagram the blue and yellow vectors are user specified and can point in any direction.
Just to restate here, I am not asking about the coordinate system of the entire texture (that's easy enough to find), I'm asking about the coordinate system and origin of a differential patch of texture when taking a single texture sample using textureGrad(). What I expect is that the returned sample value will be an approximate integral over a small finite area of the texture, related to the vectors dst_dx and dst_dy. So a component of that question is whether the sampled point st is in the middle of the differential area to be integrated, or at the corner.
So to double check, is that what you are answering?
I think the answer you're looking for is C, though I may be misunderstanding your notation.
The sample "box" is centered at st, and has the size of the dpdx and dpdy vectors.
How this translates to exact samples can get a little mind bendy and in the case of antisotropic filtering is actually implementation defined
Is the center + size behavior guaranteed by the spec, or part of the "implementation defined" behavior?
I don't fully understand the question. I guess this is also because I've never used textureSampleGrad and have not yet found what it actually does with the gradients. I presume it uses them to determine the lod and thus the appropriate mip level to sample.
Perhaps you can code an example that will actually show what happens. You can then also try it on different hardware to see if its consistent.
ah, now I get the question. I recently saw this video which makes use of this sampling method. So it seems answer C is correct, it's normalized to [-1..1]
I recently saw this video
Wow, that video explains a lot. It's also really well done 🤩 Thanks for sharing!