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

Andreas Plesch andreasplesch at gmail.com
Tue Oct 13 12:25:28 PDT 2020


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



More information about the x3d-public mailing list