It is possible to convert an image or other output to CIE Lab color model using GLSL? Does it require compute shaders or can be done using only vertex shaders?
-
What do you mean by "convert an image"? Are you trying to read pixels of an image, do some math on them, and write data in a different format to some other storage? Are you trying to do this in-situ within an image? Or do you want to simply do a transformation when you read a texel, then use that in some rendering operation? – Nicol Bolas Jan 26 '22 at 17:02
-
Read pixels to change its colors. – vaunnaut Jan 26 '22 at 20:04
1 Answers
The direct answer to your question is yes: you can use glsl to convert a pixel value between different color models such as RGB and CIELAB, although you have to consider how your RGB space matches to XYZ tristimulus values, but that's a bit outside the scope of this question.
Basically, as long as you have a closed function to convert between color models, you can leverage a GPU to do this for you, and you can use GLSL to do so.
Ultimately, whether or not it makes sense to do this with a GPU, and which type of shader stage to use, is up to what you want to do with the conversion.
If you simply want to convert one file from one model to another, you should consider using existing software such as Photoshop or Gimp. If you need to convert many files, these tools have methods for automating the conversion process.
Alternatively you can make a regular program, for example in C# to do transformations as needed. I particularly like using the System.Drawing library for manipulating images in an easy way.
If you want to do the conversion for drawing the image on the screen, then you can definitely leverage the graphics pipeline to help you do this. The most natural place to do this is in the fragment shader, but depending on what you're doing, you may also want to consider doing this in a compute shader. The code will basically be the same, but the code to prepare the pipeline will be different.
Without knowing what is it exactly that you want to do, it's quite difficult to give more concrete advice though.

- 111
- 2