当前位置: 首页>>代码示例>>C#>>正文


C# Tracer.IsShadowed方法代码示例

本文整理汇总了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;
        }
开发者ID:tgjones,项目名称:rasteracer,代码行数:74,代码来源:Primitive.cs


注:本文中的Tracer.IsShadowed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。