def shade(self, stroke): it = stroke.stroke_vertices_begin() func = MaterialF0D() xn = 0.312713 yn = 0.329016 Yn = 1.0 un = 4. * xn / (-2. * xn + 12. * yn + 3.) vn = 9. * yn / (-2. * xn + 12. * yn + 3.) while not it.is_end: mat = func(Interface0DIterator(it)) r = mat.diffuse[0] g = mat.diffuse[1] b = mat.diffuse[2] X = 0.412453 * r + 0.35758 * g + 0.180423 * b Y = 0.212671 * r + 0.71516 * g + 0.072169 * b Z = 0.019334 * r + 0.119193 * g + 0.950227 * b if (X, Y, Z) == (0, 0, 0): X = 0.01 Y = 0.01 Z = 0.01 u = 4. * X / (X + 15. * Y + 3. * Z) v = 9. * Y / (X + 15. * Y + 3. * Z) L = 116. * pow((Y / Yn), (1. / 3.)) - 16 U = 13. * L * (u - un) V = 13. * L * (v - vn) if L > self._threshold: L = L / 1.3 U = U + 10 else: L = L + 2.5 * (100 - L) / 5. U = U / 3.0 V = V / 3.0 u = U / (13. * L) + un v = V / (13. * L) + vn Y = Yn * pow(((L + 16.) / 116.), 3.) X = -9.0 * Y * u / ((u - 4.0) * v - u * v) Z = (9.0 * Y - 15.0 * v * Y - v * X) / (3.0 * v) r = 3.240479 * X - 1.53715 * Y - 0.498535 * Z g = -0.969256 * X + 1.875991 * Y + 0.041556 * Z b = 0.055648 * X - 0.204043 * Y + 1.057311 * Z r = max(0, r) g = max(0, g) b = max(0, b) it.object.attribute.color = (r, g, b) it.increment()
def __init__(self, threshold=50): StrokeShader.__init__(self) self._threshold = threshold self._func = MaterialF0D()