[2/2] wined3d: wined3d: Take abs() of vertex z coordinate as FFP fog coordinate

Stefan Dösinger stefandoesinger at gmail.com
Tue Oct 28 14:57:53 CDT 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I hope my answers are right, I'm a bit rusty on the topic of GL / D3D
coordinate systems. It may be a confusion about what "z" in your comment
means.

Am 2014-10-28 14:35, schrieb Joachim Priesner:
> If we assume fogstart and fogend refer to z coordinates, the top
> quad must have an unfogged middle (z=0=fogstart). If we assume they
> refer to w coordinates, it must have a half fogged middle (because
>  w=0.5=(fogstart+fogend)/2).
> 
> With vertex fog, we have an unfogged middle => vertex fog uses z 
> coordinates. With table fog, we have a half fogged middle => table
>  fog uses w coordinates. This is also true on Windows, so GL's 
> behavior should be insignificant here. So, what did I miss?
I think one of us mixed up the two cases. You wrote "Pixel fog will
therefore be calculated from z=-1 to z=1, whereas vertex fog will be
calculated from z=0 to z=1". Due to your projection matrix, the input
range for fog coordinates into the fog equation in the vertex fog case
is -1.0 to 1.0 if it weren't for the abs. The input range for fog
coordinates into the fog equation for the pixel fog case is 0.0 to 1.0

But maybe you meant this in the sense that you apply the inverse
projection matrix to fog start and fog end in the pixel fog case and
then look at fog in eye coordinates in both cases. In this case fog
start would indeed be -1.0.

> Okay, my train of thought was as follows: The upper quads' z 
> coordinates are -1.0 (left), 0.0 (middle) and 1.0 (right). These 
> coordinates are transformed (by the projection matrix) to 0.0, 0.5,
>  and 1.0, respectively (let's call these w coordinates).
"w coordinates" is a bad term because there's the homogenous w in each
vertex.

The OpenGL terms are "eye coordinates" for the coordinates before the
projection matrix is applied, "Clip coordinates" after the projection
matrix and before the perspective division (x=x/w, y=y/w, z=z/w,
rhw=1/w), and "normalized device coordinates" after the perspective
division. Since w is always 1.0 in your test there's no difference
between clip coordinates and normalized device coordinates. I cannot
find the D3D docs, but I think the names are the same. The coordinates
before the view matrix is applied are called "object coordinates", but
since your view matrix is the identity matrix object coordinates == eye
coordinates. (Btw, you could remove the view matrix and the associated
DP4s from the shader entirely since they're a no-op)

Since we're interested in the Z coordinate only I'd say eye_z and dev_z
are better terms.

In the vertex fog case, the fog coordinate is abs(eye_z). Your eye_z
ranges from -1.0 to 1.0 due to your projection matrix. Fog start and fog
end are therefore specified in eye coordinates as well, except that the
abs() causes slightly different behavior. Due to the abs eye_z=-1.0 is
fully fogged instead of unfogged. If you set fog_start=-1.0,
fog_end=1.0, the left side(z=-1.0) would be fully fogged, the middle
(z=0.0) half fogged and the right side (z=1.0) fully fogged. Without the
abs the left side would be unfogged.

In D3D, the far clip plane is at z = 1.0 and the near clip plane at z =
0.0. dev_z is therefore in the range of 0.0 and 1.0. In the w
coefficient [0,0,0,1] case dev_z is used. fog start and fog end are
therefore specified in device coordinates. If you specify a fog end >
1.0 you'll never get a fully fogged fragment because such a fragment
would be clipped.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJUT/VBAAoJEN0/YqbEcdMwYWwP/jtjf3PVSO7eZ484lWcG+G9n
iKTY7wmB4ktUAw9JRwtXYrMcCES5fQxBnJnFF0Al+WoEpQqifyjFqZ8pLuISBbQZ
/j55OYSlVbDTB1aOBaVxE1mVIwlNKxQIObiyDkyy6ORhtg61NTjBI7HttN+oMRfT
/UllfDRE+JVIfZzScCl/XoOrS0GoW7h3coHbDiqc3Gw42u1U5x3ml1oX6m9TuAOo
2vV3XuwbOdHkwMJzsOBdzo3UUeQ8eU4e/Fzxa4hbK9ovaT8PmgEiimX9RuU6wGqA
+pL122XQDXF5OgWsAN79cU4pmwxk5sd1DJpfvORoRrlXwLScMyno52RaJi1xgtMJ
fTQrtoRLAflFZ3r2hbIMOGSjl38qRgONykb8hlrPyfUfJpKoiL/sssUemUpItZcT
azzRoThTh9w8RuaLtkfv23Kjzqfd7cY9QOTiIp5dhZ9ilTkkdYL3NBRLHInZrWgQ
kKcw0M2a2LXV074pqy/HnCWYzy29D/wX23f8B9eEtxosLekGSV2weqSaKGUokYE3
hMENuyLdHDE8RDIGqOw4HzPggINwZCWKGEsVJTnPf2e4aE3qqbAgvmqnmA+35e9D
3wil2v4qAck3UN9XXFWrHJLy2kzzis2hwhUBTf1KRxYXrXgLIRdpdOthiuCUg/bp
Em2RgeswDi+QiofwTJJo
=JsS5
-----END PGP SIGNATURE-----



More information about the wine-devel mailing list