protected Vec3 GetRgb(int x, int y)
{
Vec3 retVal = new Vec3(0, 0, 1); // blau
PixelInfo pInfo = pData.Points[x, y];
if (pInfo == null)
{
return new Vec3(backColorRed, backColorGreen, backColorBlue);
}
Vec3 light = new Vec3(0, 0, 0);
Vec3 normal = null;
normal = normalesSmooth1[x, y];
if (normal == null) { normal = pInfo.Normal; }
// Testweise original Normale verwenden
// normal = pInfo.Normal;
// TODO: Obiges auskommentieren
if (normal == null)
return new Vec3(0, 0, 0);
// tempcoord2 enthält die umgerechnete Oberflächennormale.
double tfac = 1000;
Vec3 coord = formula.GetTransform(pInfo.Coord.X, pInfo.Coord.Y, pInfo.Coord.Z);
normal.Normalize();
Vec3 tempcoord2 = formula.GetTransform(pInfo.Coord.X + tfac * normal.X, pInfo.Coord.Y + tfac * normal.Y, pInfo.Coord.Z + tfac * normal.Z);
tempcoord2.X -= coord.X;
tempcoord2.Y -= coord.Y;
tempcoord2.Z -= coord.Z;
// Normalize:
tempcoord2.Normalize();
// debug only
tempcoord2 = normal;
if (pInfo.Normal != null)
{
light = GetLight(tempcoord2);
if (sharpShadow != null) { light = light.Mult(1 - sharpShadow[x, y]); }
}
retVal.X = light.X;
retVal.Y = light.Y;
retVal.Z = light.Z;
retVal.X = (lightIntensity * retVal.X + (1 - lightIntensity) * (1 - shadowPlane[x, y]));
retVal.Y = (lightIntensity * retVal.Y + (1 - lightIntensity) * (1 - shadowPlane[x, y]));
retVal.Z = (lightIntensity * retVal.Z + (1 - lightIntensity) * (1 - shadowPlane[x, y]));
if (retVal.X < 0)
retVal.X = 0;
if (retVal.Y < 0)
retVal.Y = 0;
if (retVal.Z < 0)
retVal.Z = 0;
if (retVal.X > 1)
retVal.X = 1;
if (retVal.Y > 1)
retVal.Y = 1;
if (retVal.Z > 1)
retVal.Z = 1;
double brightLightLevel = 0; // ParameterDict.Exemplar.GetDouble("Renderer.BrightLightLevel");
if (brightLightLevel > 0)
{
retVal.X = (1 - brightLightLevel) * retVal.X + brightLightLevel * light.X * (1 - shadowPlane[x, y]);
retVal.Y = (1 - brightLightLevel) * retVal.Y + brightLightLevel * light.Y * (1 - shadowPlane[x, y]);
retVal.Z = (1 - brightLightLevel) * retVal.Z + brightLightLevel * light.Z * (1 - shadowPlane[x, y]);
}
if (retVal.X < 0)
retVal.X = 0;
if (retVal.Y < 0)
retVal.Y = 0;
if (retVal.Z < 0)
retVal.Z = 0;
if (retVal.X > 1)
retVal.X = 1;
if (retVal.Y > 1)
retVal.Y = 1;
if (retVal.Z > 1)
retVal.Z = 1;
// Add surface color
bool useAdditionalColorinfo = true;
if (colorIntensity <= 0)
useAdditionalColorinfo = false;
if(pInfo.IsInside)
{
}
else
{
}
if (useAdditionalColorinfo && ((pInfo.IsInside&&_colorInside)||(!pInfo.IsInside && _colorOutside)))
{
if (pInfo != null && pInfo.AdditionalInfo != null)
{
// Normalise;
double r1 = colorFactorRed * Math.Pow(pInfo.AdditionalInfo.red, colorIntensity);
double g1 = colorFactorGreen * Math.Pow(pInfo.AdditionalInfo.green, colorIntensity);
double b1 = colorFactorBlue * Math.Pow(pInfo.AdditionalInfo.blue, colorIntensity);
if (r1 < 0)
r1 = -r1;
if (g1 < 0)
g1 = -g1;
if (b1 < 0)
b1 = -b1;
double norm = Math.Sqrt(r1 * r1 + g1 * g1 + b1 * b1) / Math.Sqrt(2.5);
r1 = r1 / norm;
g1 = g1 / norm;
b1 = b1 / norm;
for (int i = 0; i < 5; i++)
{
if (r1 > 1)
{
b1 += (r1 - 1) / 2.0;
g1 += (r1 - 1) / 2.0;
r1 = 1;
}
if (b1 > 1)
{
r1 += (b1 - 1) / 2.0;
g1 += (b1 - 1) / 2.0;
b1 = 1;
}
if (g1 > 1)
{
r1 += (g1 - 1) / 2.0;
b1 += (g1 - 1) / 2.0;
g1 = 1;
}
}
if (r1 > 1)
r1 = 1;
if (b1 > 1)
b1 = 1;
if (g1 > 1)
g1 = 1;
if (colorGreyness > 0)
{
r1 = colorGreyness + (1 - colorGreyness) * r1;
g1 = colorGreyness + (1 - colorGreyness) * g1;
b1 = colorGreyness + (1 - colorGreyness) * b1;
}
if (r1 > 1)
r1 = 1;
if (b1 > 1)
b1 = 1;
if (g1 > 1)
g1 = 1;
if (norm != 0)
{
switch (rgbType)
{
case 1:
retVal.X *= r1;
retVal.Y *= g1;
retVal.Z *= b1;
break;
case 2:
retVal.X *= r1;
retVal.Y *= b1;
retVal.Z *= g1;
break;
case 3:
retVal.X *= g1;
retVal.Y *= r1;
retVal.Z *= b1;
break;
case 4:
retVal.X *= g1;
retVal.Y *= b1;
retVal.Z *= r1;
break;
case 5:
retVal.X *= b1;
retVal.Y *= r1;
retVal.Z *= g1;
break;
case 6:
retVal.X *= b1;
retVal.Y *= g1;
retVal.Z *= r1;
break;
default:
retVal.X *= r1;
retVal.Y *= g1;
retVal.Z *= b1;
break;
}
}
}
}
if (contrast != 1)
{
retVal.X = Math.Pow(retVal.X, contrast);
retVal.Y = Math.Pow(retVal.Y, contrast);
retVal.Z = Math.Pow(retVal.Z, contrast);
}
if (brightness > 1)
{
retVal.X *= brightness;
retVal.Y *= brightness;
retVal.Z *= brightness;
}
if (retVal.X < 0)
retVal.X = 0;
if (retVal.X > 1)
retVal.X = 1;
if (retVal.Y < 0)
retVal.Y = 0;
if (retVal.Z < 0)
retVal.Z = 0;
if (retVal.Y > 1)
retVal.Y = 1;
if (retVal.Z > 1)
retVal.Z = 1;
return retVal;
}