Shader derivatives
category: code [glöplog]
the output of the shader derivative functions (fDx and fDy) looks like shit. it's half the original texture res, and it doesn't look very precise. am I doing it wrong, or should I calculate it manually?
RTFM
JFGI
WWJD
TOGTFO
xernobyl - as decipher so eloquently put it: they are exactly half res, as they are done by simple differencing between the 2x2 of pixels rendered.
DDX DDY FWIDTH
@Decipher I prefer the twitter version.
like hornet nicely did it.
You can't do the derivative yourself, at least not in general.
Yeah I was also wondering about it, if you can calculate the derivative of a function from a single value on the function graph, well get ready for the Nobel or something.
I can have several textures you know?
Read: I can have several half-sized derivatives \o/ party.
Quote:
if you can calculate the derivative of a function from a single value on the function graph, well get ready for the Nobel or something.
Fields Medal.
There's a funny story about that... apparently there's no Nobel for math because Nobel's wife was having an affair with a mathematician.
Quote:
apparently there's no Nobel for math because Nobel's wife was having an affair with a mathematician.
Full of win.
Why should it be half size?
shouldn't it be just -1px from the side and -1px from the top or bottom?
shouldn't it be just -1px from the side and -1px from the top or bottom?
yeah, it could be done on full reso.
It has to do with hardware sampling, the hardware always takes 4 samples. That's why you have the fetch4 / gather4 instruction.
even then, why isn't it upscaled (and interpolated) to full size?
Maybe because that'd be trivial to a user? :)
xenobyl - The 2x2-rendering is bound to how the rasterizer works, not the sampler, so it's unrelated to fetch4.
xrl: basically the rasterizer does everything in 2x2 quads that are computed in one step. Back in the day this way the simplest solution to get an approximation of the texture coordinate derivatives for determining which mipmap level to use. And then in SM3 they were all like "if every GPU rasterizes 2x2 pixels in parallel anyway we can simply add an instruction that gets you the derivative of any value in the shader 'for free'" and then went on rejoicing.
Hurray! Joy to the world
and afaik, that's why rasterizing polygons that are smaller than two pixels is so inefficient - the HW is always shading a minimum of 2x2 pixels.