8.5 Points to Note about Semi-transparent Fog

Since Fog is a function realized in the Blender, it may seem at first glance that the process has no effect on the Combiner, but you need to be careful when vertex alphas are used in the Combiner. An explanation using a concrete example will be done. In the sample we just talked about (with __FOG__ defined), the combine mode is set so that

(1 - 0) * TEXEL0 + 0

is output for the alpha value of the second cycle.

List8-7

  gDPSetCombineLERP(glistp++, SHADE,   0, TEXEL0,        0,
                                  0,   0,      0,        0,
                                  0,   0,      0, COMBINED,
                                  1,   0, TEXEL0,        0);

There is a reason why the shade alpha is not specified as the input alpha source in the same way as the color. The reason is that when fog is applied, the Z value is written in the location of the vertex buffer's alpha by the RSP, so you cannot be certain of the value of the vertex alpha. Consequently, when applying fog to a semi-transparent object, you need to be careful and not use the vertex alpha when rendering.

Also, the fog parameters stored in the vertex alpha region are calculated inside the RSP when vertices are calculated. Thus, when you change vertex colors with the gSPModifyVertex command, there is a chance that the calculated fog parameters will be affected in a negative way. For this reason, when you are using the Fog function it is a good idea not to use the gSPModifyVertex command.

When you define __FOG__ on line 26 of the gfx8.c sample program and also define __VERTEX_ALPHA__ on line 40, then fog is enabled and the combine mode is set to use vertex alphas. This has been prepared strictly for learning purposes, and you should take care not to use this as a model when you put together actual N64 applications.