本文整理汇总了C#中Tracer.IsShadowed方法的典型用法代码示例。如果您正苦于以下问题:C# Tracer.IsShadowed方法的具体用法?C# Tracer.IsShadowed怎么用?C# Tracer.IsShadowed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tracer
的用法示例。
在下文中一共展示了Tracer.IsShadowed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Shade
public FloatColour Shade(Tracer tracer, Ray tRay, float fDistance, int nDepth)
{
// declare return colour
FloatColour tColour = new FloatColour(0, 0, 0);
// get surface normal at point of intersection
Vector3 tIntersection = tRay.Position + tRay.Direction * fDistance;
Vector3 tNormal = CalculateNormal(tIntersection);
// calculate reflected ray
Ray tReflectedRay;
tReflectedRay.Direction = Vector3.Reflect(tRay.Direction, tNormal);
tReflectedRay.Position = tIntersection;
// add lighting components
foreach (Light light in tracer.Scene.Lights)
{
// get vector from surface to light
Vector3 tSurfaceToLight = light.GetDirectionToLight(tIntersection);
float fDistanceToLight = tSurfaceToLight.Length();
tSurfaceToLight.X /= fDistanceToLight;
tSurfaceToLight.Y /= fDistanceToLight;
tSurfaceToLight.Z /= fDistanceToLight;
// check whether point is in shadow
Ray tRayToLight;
tRayToLight.Position = tIntersection;
tRayToLight.Direction = tSurfaceToLight;
float fLightFactor;
if (tracer.IsShadowed(this, tRayToLight, fDistanceToLight))
{
// shadowed - little bit of ambient light
fLightFactor = 0.1f;
}
else
{
// get amount of light diffuse at intersection point
fLightFactor = Vector3.Dot(tSurfaceToLight, tNormal);
if (fLightFactor < 0) fLightFactor = 0;
}
// calculate specular component
float fSpecular = Vector3.Dot(tRayToLight.Direction, tReflectedRay.Direction);
if (fSpecular > 0)
{
float Shininess = 100.0f;
float SpecularCoefficient = 1.0f;
fSpecular = (float) Math.Pow(fSpecular, Shininess) * SpecularCoefficient;
}
else
{
fSpecular = 0;
}
// add light effect to colour
tColour += (Material.GetColour(tIntersection) * fLightFactor + new FloatColour(fSpecular)) * light.Colour;
}
// calculate reflection colour (if needed)
if (Reflectivity != 0)
{
// calculate the reflected colour
FloatColour tReflectedColour = tracer.TraceRay(this, tReflectedRay, nDepth + 1);
// calculate total colour components
tColour += tReflectedColour * Reflectivity;
}
if (tColour.R > 255) tColour.R = 255;
if (tColour.G > 255) tColour.G = 255;
if (tColour.B > 255) tColour.B = 255;
return tColour;
}