Vector4 getReflectance(Vector3 outDir, Vector3 inDir)

Returns the reflectance for the associated Primitive at the associated hitpoint and and for the given direction vectors.

The parameter outDir is the vector from the hit point in direction of its origin. The parameter inDir is vector from the hit point in direction of the light source.

Returns the zero vector, if the shader does not support reflectance.

Source

Vector4 getReflectance(Vector3 outDir, Vector3 inDir) {
  Vector4 Cs = this.specCoeff;
  Vector4 Cd = this.difCoeff;
  double Ce = this.specExp;

  Vector3 halfVect = (inDir.normalize() + outDir.normalize()).normalize();
  double specCoeff = Math.max(halfVect.dot(normal), 0.0);
  specCoeff = Math.exp(Math.log(specCoeff) * Ce);
  double diffCoeff = Math.max(normal.dot(inDir.normalize()), 0.0);

  return
      new Vector4(diffCoeff, diffCoeff, diffCoeff, diffCoeff).multiply(Cd)
      + new Vector4(specCoeff, specCoeff, specCoeff, specCoeff).multiply(Cs);
}