Problem with fragment.position, ATI specific


I have a simple pair of programs, and basically I output the fragment.position / viewport size as the fragment color, simply to check the values that are returned by the shader.

On any NV hardware, using fragment.position or f[WPOS] does not make any problem. The resulting coordinates are accurate and can be used to sample the appropriate texel in a RECT texture, or a 2D texture after normalization.

On my ATI configuration X800 PRO/GTO, Catalyst 6.4, the fragment value is not correct all the times: there’s an offset added to the result, that rely on the rendered geometry (as if it was a low accuracy interpolation of the vertex coordinates after the MVP): Two different geometries at different depths don’t produce neighboring fragment.positions at neighboring pixels on screen.

I can’t figure out any reason for that. Anyone has an idea or ever met such a problem ?

Thanks in advance.

The X800 doesn’t have the VPOS register, so it will be implemented by interpolating and doing a division in the fragment shader. With 24bit precision and an RCP instruction that I think is actually a bit or two less precise than that I guess there may be some slight error. How big offset are we talking about?

Hmmm, I was guessing that, but I was not aware of the real accuracy beyond. I’ve tried the manual interpolation and I got exactly the same result as for fragment.position.

The resulting offset is in the [0-2] pixel range. This is very problematic, because the image composition we do uses a lot of screen space textures (you can see our product on nvidia hardware at . There’s a trial version that you can download: It’s a real-time ray tracer working within a regular 3d engine).
For example, I render shadows on a separate screen space texture and read it at the current window pixel coordinates at the time I render the geometry pass for a given light. This because we have many different ways to compute shadows (shadow maps, ray traced, area shadows, etc…). This why I need - amongst other usages - an access to correct window coordinates for every rendered fragment.

Could you tell me the versions of ATI boards that have a VPOS register implementation ? Or do you have an idea on the way to bypass this lack of accuracy ?


The X1300 and up supports the VPOS register. Not sure if there’s any way to work around the accuracy problem on older cards. Floating point numbers give best accuracy around zero though, so one thing that might want to try is to interpolate in clip space coordinates (-1 to 1) instead, then scale and bias in the fragment shader, rather than have that baked into the interpolation from the vertex shader.

Thanks for your quick reply !
I’ll try getting closer to 0 to see if that works.

Ooops, one thing I forgot to ask you… Do you know which of the FireGL cards support VPOS ?
Thanks again !

The FireGL V7300 and up should support it.

Thanks !

The interpolator for fragment color is limited to about 12 bits on many (all?) ATI cards. Use a texture coordinate instead of the fragment color. It will have much higher accuracy.