apply method

List<Color> apply(
  1. Sp3dV3D nsn,
  2. double camTheta,
  3. Sp3dMaterial material
)

(en)Returns the color as a result of this light being applied to a particular surface.

(ja)特定の面にこのライトが適用された結果としての色を返します。

  • nsn : The normalized surface normal vector.
  • camTheta : With this, the light is always from the same direction as the camera.
  • material : The material to which light is applied.

Returns : Color(bg),Color(stroke).

Implementation

List<Color> apply(Sp3dV3D nsn, double camTheta, Sp3dMaterial material) {
  List<Color> r = [];
  // 光の計算
  // 正規化されたベクトル同士の内積を取ると結果がcosΘになるので、そこから光の拡散度合い(光の強さ)に変換する。
  // RGB値に掛け合わせて明度を変化させるために、内積をさらに0~1の範囲に補正。
  late double brightness;
  if (syncCam) {
    brightness = camTheta.clamp(0.0, 1.0);
  } else {
    brightness = Sp3dV3D.dot(nsn, direction).clamp(0.0, 1.0);
  }
  if (brightness < minBrightness) {
    brightness = minBrightness;
  }
  // ライトを適用
  final Color bg = material.bg;
  r.add(Color.fromARGB(bg.alpha, (brightness * bg.red).toInt(),
      (brightness * bg.green).toInt(), (brightness * bg.blue).toInt()));
  final Color sc = material.strokeColor;
  if (applyStroke) {
    r.add(Color.fromARGB(sc.alpha, (brightness * sc.red).toInt(),
        (brightness * sc.green).toInt(), (brightness * sc.blue).toInt()));
  } else {
    r.add(sc);
  }
  return r;
}