This section documents a problem related to single-texturing behavior,
that is connected with some multi-texturing troubles.
Note that (at the time of X3D 3) this was the one and only place
where our engine deliberately did something different than X3D specification,
because we felt that the X3D specification behavior is really not useful.
In our engine, the texture color is by default multiplied by the material color.
This issue is
fixed in X3D 4.0,
where I introduced prose/equations that match my recommended behavior (and match what CGE is doing).
VRML 2 / X3D specifications
say that RGB textures should by default REPLACE the material color (as opposed
to MODULATE).
This is when no multi-texturing is used.
This is said by the specification at tables
"Table 17.2 — Unlit colour and alpha mapping" and
"Table 17.3 — Lit colour and alpha mapping": note that RGB and RGBA texture
colors are not multiplied by color from Material.diffuseColor
or Color nodes.
Also spec about Color nodes (11.4.2 Color, 11.4.3 ColorRGBA) says explicitly
that "RGB or RGBA textures take precedence over colours; specifying both
an RGB or RGBA texture and a Color* node for geometric shape will
result in the Color* node being ignored.".
Problems with the specification text:
-
It makes Material.diffuseColor and Color
useless with RGB textures, which is a shame. GPUs do not have such limitations.
-
It is inconsistent with MultiTexture behavior,
when the modulate mode is the default — regardless if we have
RGB or grayscale texture.
-
In case of our Gouraud shading,
the texture color has to be mixed with the whole lighting calculation.
Using the "replace" mode by default would mean that shapes are unlit
when you use RGB textures.
Thus the problem would be very noticeable in Gouraud shading (if only X3D browsers would actually honor
this part of X3D specification to the letter).
A separate problem is that browsers are already
inconsistent in the implementation of this rule, see test results.
That’s understandable, because the spec behavior is a little useless.
That’s why we propose to change the specification:
simply always MODULATE (component-wise multiply on RGBA channels).
In other words, treat a grayscale texture exactly like an RGB texture
with all color components (red, green, blue) equal.
Our engine and Castle Model Viewer already implement this behavior.