Sak
Sak

Reputation: 279

How to replicate adding/mixing of HSV values in RGB space

At the moment I'm doing a colourizing effect using additive blending in HSV space. Have a diff value in HSV space which is added to an image texture's individual pixels to get the desired color effect. But this is turning out to be expensive as the fragment shader has to do two costly conversions to do the addition

  1. RGB -> HSV
  2. HSV addition
  3. HSV -> RGB

Is there a better way to do this? The diff value will be provided in HSV only. And the final color representation is in RGB to draw.

Many Thanks,

Sak

Upvotes: 0

Views: 536

Answers (1)

user1118321
user1118321

Reputation: 26395

You can get a similar effect to HSV manipulations by using a color matrix in RGB. For example, a rotation around the r=g=b axis is similar to a hue addition. (Adding x degrees in the hue channel is similar to a rotation of x degrees around r=g=b in RGB.) A translation along the r=g=b axis is similar to a value addition. (I believe that adding x to the value channel should be similar to adding x to all of r, g, and b.) And a uniform scale perpendicular to the r=g=b axis is similar to a saturation addition. I don't know off the top of my head the exact translation between adding x to saturation and scaling in RGB, but it shouldn't be too hard to work out. You should be able to compose these matrixes into a single matrix, and implement it as a single matrix multiply by the RGB value.

Upvotes: 1

Related Questions