Measter
Measter

Reputation: 68

How do I Blend Colours like This?

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:

Which results in this:


(source: serayen.com)

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

Upvotes: 1

Views: 490

Answers (1)

Nick Udell
Nick Udell

Reputation: 2501

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.

Upvotes: 0

Related Questions