I want to know how colorised texture works exactly.
I read that the texture is first converted to gray scale and then the color is applied on top of it.
I tried doing that, multiplying color value with gray scale texture color values. This doesn’t work.
I also read that same hue from color is applied to the gray scale texture. Can anyone explain this?
Do we need to add colors in HSL space?
This is my understanding:
In case of Colorized Texture, the texture is first converted to gray scale and then the color value is multiplied with the gray scale values.
If you set a material color for a textured material via the Ruby API’s Sketchup::Material.color= it sets the type to Sketchup::Material::COLORIZE_TINT.
You can toggle the type using Sketchup::Material.colorize_type=
The UI have a checkbox:
For what is happening on our end:
Each pixel is processed one by one.
RGB value is converted to HLS.
Sketchup::Material::COLORIZE_SHIFT
Adjustment Hue is added to Pixel Hue
Hue ensured to be within 0-360 range by rolling around.
Adjustment Saturation is added to Pixel Saturation (clamped to 0.0-1.0).
Adjustment Lumination is added to Pixel Lumination (clamped to 0.01-1.0).
Sketchup::Material::COLORIZE_TINT
Pixel Hue is set to Adjustment Hue
Hue ensured to be within 0-360 range by rolling around.
Adjustment Saturation is added to Pixel Saturation (clamped to 0.0-1.0).
Adjustment Lumination is added to Pixel Lumination (clamped to 0.01-1.0).
Converting back to RGB
If the resulting Pixel Saturation is 0.0 the RGB is set to the Pixel Lumination
If not, regular HLS to RGB conversion
Maybe I should write this out into pseudo code or Ruby code…
Btw, I just noticed that the C API is lacking the properties to determine the deltas and colorization types. That will need to be added.
Yes - good catch. The color delta is used to adjust. It’s computed from the texture’s average color and the adjustment color.
Describing how the delta is derived is much easier if I just write it in pseudo-code. (I’ll have to get back on this - maybe tomorrow.) The Ruby API have a method for this already: Sketchup::Material.colorize_deltasClass: Sketchup::Material — SketchUp Ruby API Documentation
Afraid not - this was a long standing issue with the Ruby API - not being able to know the exact state of the material.
We’re constantly working on fleshing out the C API though - so it will come.
Sorry - things got really busy. Here’s a quick draft:
def get_deltas(shift = true)
from = texture.average_color
to = material.color
# Get HLS of base color.
base_h, base_s, base_l = from.get_hsl
# Get HLS of new color.
h, s, l = to.get_hsl
if to.is_monochrome? && from.is_monochrome?
h = 0
s = 0
l = l - base_l
else if to.is_monochrome?
h = 0
s = -1
l = l - base_l
else if from.is_monochrome?
l = l - base_l
else
l = l - base_l
s = s - base_s
if shift
h = h - base_h
end
end
return [h, s, l]
end
the pseudo code for calculating deltas and the actual logic of COLORIZE_SHIFT and COLORIZE_TINT you provided gives the full picture of colorized_texture.
Only problem is, Since I am using C SDK, I can’t differentiate between COLORIZE_SHIFT and COLORIZE_TINT.
For now, I assumed it is COLORIZE_TINT by default.