[x3d-public] Which color space for Background color interpolation

Michalis Kamburelis michalis.kambi at gmail.com
Thu Oct 15 10:16:45 PDT 2020


Castle Game Engine right now uses RGB interpolation for Background
colors. So this seems to match the conclusion :)

I agree the interpolation method should be said in the X3D spec explicitly.

For CGE, we interpolate in RGB for implementation+simplicity reasons.
We just render sky and ground as a sphere mesh, with rings at
appropriate angles (corresponding to sky/ground angles in Background).
The colors specified at Background node are simply used for the mesh
vertexes, and then we allow GPU to interpolate them linearly as usual
for shader varying attributes. So, without really thinking, I
implemented interpolation in RGB space -- simply by letting GPU do it
in the simplest fashion.

Regards,
Michalis

śr., 14 paź 2020 o 04:49 Andreas Plesch <andreasplesch at gmail.com> napisał(a):
>
> As a result of this exploration, x3dom will use HSV space for
> ColorInterpolator as required, and RGB space for Background color
> interpolation. Since x3dom uses ColorInterpolator internally for
> Background, there will be an additional custom field for
> ColorInterpolator which lets an author choose to use RGB space there
> as well, SFBool "RGB" false. This option may be handy if gray scale
> colors need to be interpolated.
>
> Cheers, -Andreas
>
> On Tue, Oct 13, 2020 at 4:53 PM Andreas Plesch <andreasplesch at gmail.com> wrote:
> >
> > Tests indicate that just using Quaternion slerp for Hue interpolation
> > (seen as 3d rotations around a fixed axis)  works. Less code but some
> > useless overhead.
> >
> > I also tested Background color interpolation in HSV space with these
> > backgrounds:
> >
> > https://x3dgraphics.com/examples/X3dForAdvancedModeling/Visualization/BackgroundCollectionIndex.html
> >
> > Many involve pure grey scale colors which do not have a well defined
> > hue and therefore give unexpected results during interpolation. They
> > can be easily tweaked to shift the grey scale colors just a bit to the
> > expected hue (say very dark blue) and they then look like the short
> > descriptive name.
> >
> > But it seems that these examples were constructed with RGB color space
> > interpolation in mind. So this is probably what the spec. intended.
> >
> > So perhaps it is not too late to add "in RGB color space" to
> >
> > https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/enveffects.html#Backgrounds
> >
> > ?
> >
> > -Andreas
> >
> > On Tue, Oct 13, 2020 at 3:25 PM Andreas Plesch <andreasplesch at gmail.com> wrote:
> > >
> > > For the Background sphere x_ite just assigns the (closest) color to
> > > the row of vertices at the corresponding angle position on a
> > > constructed sphere and then lets GL do the interpolation:
> > >
> > > https://github.com/create3000/x_ite/blob/4a900d8b36bfb4aac66671554cc2f4db634efa37/src/x_ite/Components/EnvironmentalEffects/X3DBackgroundNode.js#L385
> > >
> > > So this means linear interpolation in RGB space.
> > >
> > > -Andreas
> > >
> > > On Tue, Oct 13, 2020 at 1:35 PM Andreas Plesch <andreasplesch at gmail.com> wrote:
> > > >
> > > > Thanks, Michalis. I should check x-ite also:
> > > >
> > > > https://github.com/create3000/x_ite/blob/382252fbc23115803a0fa621e4fae1326277e148/src/standard/Math/Numbers/Color3.js#L222
> > > >
> > > > It looks like it is also trying to do something like that.
> > > >
> > > > Is CGE interpolating in RGB space for skyColor/groundColor interpolation ?
> > > >
> > > > Thanks, -Andreas
> > > >
> > > > On Tue, Oct 13, 2020 at 9:03 AM Michalis Kamburelis
> > > > <michalis.kambi at gmail.com> wrote:
> > > > >
> > > > > CGE implementation takes care to interpolate hue along the shortest
> > > > > path (i.e. sometimes clockwise, sometimes counter-clockwise). See
> > > > > https://github.com/castle-engine/castle-engine/blob/master/src/base/castlecolors.pas#L373
> > > > > .
> > > > >
> > > > > Indeed the code is a little ugly, needs to look separately at 3 cases:
> > > > >
> > > > > - if HueDiff > 3 then
> > > > > - f HueDiff < -3 then
> > > > > - otherwise
> > > > >
> > > > > Regards,
> > > > > Michalis
> > > > >
> > > > > wt., 13 paź 2020 o 06:32 Andreas Plesch <andreasplesch at gmail.com> napisał(a):
> > > > > >
> > > > > > While trying to linearly interpolate in HSV space, a question came up
> > > > > > for me with regards to Hue. Hue is represented as an angle in a color
> > > > > > circle. This means there are two ways to linearly interpolate, in the
> > > > > > acute segment defined by the two hues, or in the obtuse segment. Say
> > > > > > the first hue is 10 degrees and the second 300. At a fraction of 0.5,
> > > > > > the interpolated value may be 155 ( in the obtuse segment ) or 335 (
> > > > > > in the acute segment ).
> > > > > >
> > > > > > One rule may be to always go counterclockwise in the circle, eg. from
> > > > > > 10 to 300 in the example. But then it is hard to predict if the
> > > > > > interpolation between two similar shades of a color (say for a blue
> > > > > > sky) results in similar shades, or actually goes around most of the
> > > > > > full color circle, generating a very colorful result.
> > > > > >
> > > > > > So a more reasonable rule may be to always interpolate in the acute
> > > > > > segment, clockwise or counterclockwise as necessary. I think slerp
> > > > > > always takes the shorter path as well.
> > > > > >
> > > > > > I hope that there is a more straightforward interpretation of what it
> > > > > > means to interpolate in HSV space, and I just overlooked something.
> > > > > >
> > > > > > -Andreas
> > > > > >
> > > > > > On Mon, Oct 12, 2020 at 6:17 PM Andreas Plesch <andreasplesch at gmail.com> wrote:
> > > > > > >
> > > > > > > The Background specification in
> > > > > > >
> > > > > > > https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/enveffects.html#Backgrounds
> > > > > > >
> > > > > > > states that
> > > > > > >
> > > > > > > "The sky colour is linearly interpolated between the specified
> > > > > > > skyColor values." and
> > > > > > > "The ground colour is linearly interpolated between the specified
> > > > > > > groundColor values."
> > > > > > >
> > > > > > > The ColorInterpolator specification in
> > > > > > >
> > > > > > > https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/interp.html#ColorInterpolator
> > > > > > >
> > > > > > > states that
> > > > > > >
> > > > > > > "A linear interpolation using the value of set_fraction as input is
> > > > > > > performed in HSV space."
> > > > > > >
> > > > > > > The ColorInterpolator language is more precise in giving the space in
> > > > > > > which linear interpolation should be performed.
> > > > > > >
> > > > > > > I think there is a need to also become more precise for Background
> > > > > > > color interpolation. The consistent approach would be to choose HSV
> > > > > > > space there as well:
> > > > > > >
> > > > > > > "The sky colour is linearly interpolated in HSV space between the
> > > > > > > specified skyColor values." and
> > > > > > > "The ground colour is linearly interpolated in HSV space between the
> > > > > > > specified groundColor values."
> > > > > > >
> > > > > > > HSV space probably also leads to more aesthetically pleasing backgrounds.
> > > > > > >
> > > > > > > [x3dom currently performs all color interpolation in RGB space].
> > > > > > >
> > > > > > > Do we need such a clarification ?
> > > > > > >
> > > > > > > -Andreas
> > > > > > > --
> > > > > > > Andreas Plesch
> > > > > > > Waltham, MA 02453
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Andreas Plesch
> > > > > > Waltham, MA 02453
> > > > > >
> > > > > > _______________________________________________
> > > > > > x3d-public mailing list
> > > > > > x3d-public at web3d.org
> > > > > > http://web3d.org/mailman/listinfo/x3d-public_web3d.org
> > > >
> > > >
> > > >
> > > > --
> > > > Andreas Plesch
> > > > Waltham, MA 02453
> > >
> > >
> > >
> > > --
> > > Andreas Plesch
> > > Waltham, MA 02453
> >
> >
> >
> > --
> > Andreas Plesch
> > Waltham, MA 02453
>
>
>
> --
> Andreas Plesch
> Waltham, MA 02453



More information about the x3d-public mailing list