1

I'm writing a tool to assist with modding new characters into the game Crusader Kings II and I'm a bit stuck on colouring the hair and beards.

The game starts with a texture like this:


(source: serayen.com)

It then blends it with three colours - a shadow, a base, and a highlight, such as:

  • Dark: 10, 10, 10
  • Base: 125, 85, 56
  • Highlight: 255, 255, 255

Which results in this:


(source: serayen.com)

What kind of blending is it using? How would I go about doing it in C#?

Community
  • 1
  • 1
Measter
  • 68
  • 2
  • 8
  • As a guess I'd say it's performing colour multiplication, selecting which of the three colours to multiply a pixel by based on the pixel's overall intensity, possibly using linear interpolation between the three. You'll struggle to correctly replicate this unless you know the thresholds that constitute a dark, base or highlight pixel for multiplication. – Nick Udell Apr 18 '12 at 16:37

1 Answers1

0

Decided to make this a full answer as it's easier to format and provide examples here.

As a guess I'd say it's performing colour multiplication, selecting which of the three colours to multiply a pixel by based on the pixel's overall intensity, possibly using linear interpolation between the three. You'll struggle to correctly replicate this unless you know the thresholds that constitute a dark, base or highlight pixel for multiplication.

So I assume their algorithm is:

(pixel(x,y).color * dark.color * THRESHDARK - min(pixel(x,y).intensity, THRESHDARK) //dark blending + 
(pixel(x,y).color * base.color * (pixel(x,y).intensity - THRESHDARK) / (THRESHLIGHT-THRESHDARK)) //middle blending +
(pixel(x,y).color * highlight.color * pixel(x,y).intensity - THRESHLIGHT) //light blending

Or something similar. Hope this helps.

Nick Udell
  • 2,420
  • 5
  • 44
  • 83
  • If that multiply is similar to how Photoshop does it, then it'll be quite a bit darker than what the game ends up with. Also, what's the pixel intensity in that example? I tried implementing that in the program, but couldn't figure out what it was. – Measter Apr 20 '12 at 09:19
  • Sorry that was more a ballpark guess. As I said, it's going to be very difficult to perfectly reproduce their values due to weightings and such, but you can probably get close with trial and error. In that example, the pixel's intensity is calculated by averaging the values for r, g and b components at that pixel. There are somewhat better ways of getting pixel intensity, due to the fact the eye picks up light in different ways, but a simple average is a good start – Nick Udell Apr 25 '12 at 10:57