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


C# HitInfo.GetReal方法代码示例

本文整理汇总了C#中HitInfo.GetReal方法的典型用法代码示例。如果您正苦于以下问题:C# HitInfo.GetReal方法的具体用法?C# HitInfo.GetReal怎么用?C# HitInfo.GetReal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HitInfo的用法示例。


在下文中一共展示了HitInfo.GetReal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Shade

        private ColorIntensity Shade(RealHitInfo hit, Line by, int recurse, double ratio, bool inside, int threadId)
        {
            #if DEBUG
            if (Gathering)
            {
                CurrentGather.Weight = ratio;
                CurrentGather.RealInfo = hit;
            }
            #endif
            ColorIntensity colors, shadowcolors;
            Material surf = hit.HitStuff;
            ColorIntensity pigment = hit.Pigment.GetTexture(hit.Normal, 0);
            ColorIntensity atten = new ColorIntensity();
            if (surf.Attenutive && inside)
            {
                double dist = hit.Normal.Start.LineTo(by.Start).Length;
                atten.R = Math.Exp(-(1.0 - surf.Attenuation[0]) * dist / surf.AttenuationDistance);
                atten.G = Math.Exp(-(1.0 - surf.Attenuation[1]) * dist / surf.AttenuationDistance);
                atten.B = Math.Exp(-(1.0 - surf.Attenuation[2]) * dist / surf.AttenuationDistance);
                ratio = ratio * (atten.R + atten.G + atten.B) / 3;
            }
            double rI = 0;
            double gI = 0;
            double bI = 0;
            Vector lightdir;
            Line newray = new Line();
            HitInfo hitnewray = new HitInfo();
            hit.Normal.Direct = hit.Normal.Direct.Scale(1 / hit.Normal.Direct.Length);
            Vector eye = by.Direct.Scale(-1 / by.Direct.Length);

            int lightCount = (allLightsArePhotons && photons) ? 0 : lights.Count;
            //lightCount = 0;
            for (int i = 0; i < lightCount; i++)
            {
                double lightdist = double.PositiveInfinity;
                switch (lights[i].LightType)
                {
                    case LightType.Ambient:
                        rI += lights[i].Color.R * surf.Ambient[0];
                        gI += lights[i].Color.G * surf.Ambient[1];
                        bI += lights[i].Color.B * surf.Ambient[2];
                        continue;
                    case LightType.Directional:
                        lightdir = lights[i].Direction.Direct.Scale(-1);
                        break;
                    case LightType.Point:
                        lightdir = hit.Normal.Start.LineTo(lights[i].Direction.Start);
                        lightdist = lightdir.Length;
                        break;
                    default:
                        continue;
                }
                // Add double illuminate flag or something to turn this off.
                if (true)
                {
                    if (lightdir.Dot(hit.Normal.Direct) <= 0.0)
                        continue;
                }
                newray.Direct = lightdir.Scale(1.0/lightdir.Length);
                if (newray.Direct.Dot(hit.Normal.Direct) >= 0)
                    newray.Start = hit.Normal.Start.MoveBy(newray.Direct.Scale(EPSILON * 10));
                else
                    newray.Start = hit.Normal.Start.MoveBy(newray.Direct.Scale(-EPSILON * 10));
                SetIn(ref newray.Start, threadId);
                HitInfo info = scene.Intersect(newray, false, threadId);
                if (!(info.HitDist == -1 || info.HitDist > lightdist))
                    continue;
                shadowcolors.R = 1.0;
                shadowcolors.G = 1.0;
                shadowcolors.B = 1.0;
                // Don't need to setIn again, seperate intersect cache for shadow vs non-shadow rays.
                hitnewray = scene.Intersect(newray, threadId);
                if (!photons)
                {
                    if (!(hitnewray.HitDist == -1 || hitnewray.HitDist > lightdist))
                    {
            #if DEBUG
                        GatherInfo last = null;
                        if (Gathering)
                        {
                            last = CurrentGather;
                            CurrentGather = new GatherInfo();
                        }
            #endif
                        shadowcolors = ShadowShade(hitnewray.GetReal(newray), newray, recurse + 1, ratio, inside, threadId, lightdist);
            #if DEBUG
                        if (Gathering)
                        {
                            last.LightChildren.Add(CurrentGather);
                            CurrentGather = last;
                        }
            #endif
                    }
                }
                else
                {
                    if (!(hitnewray.HitDist == -1 || hitnewray.HitDist > lightdist))
                        continue;
                }
                shadowcolors.R *= lights[i].Color.R;
//.........这里部分代码省略.........
开发者ID:Tilps,项目名称:Stash,代码行数:101,代码来源:ToyTracer.cs

示例2: PhotonShade

        private void PhotonShade(HitInfo hit, Line ray, int threadId, int depth, bool inside, ColorIntensity lightCol, Random rnd, double distance, double area)
        {
            if (depth > maxrecurse)
                return;
            if (lightCol.GreyScale() < minratio)
                return;
            RealHitInfo realHit = hit.GetReal(ray);
            Material surf = realHit.HitStuff;
            ColorIntensity pigment = realHit.Pigment.GetTexture(realHit.Normal, 0);
            double dist = realHit.Normal.Start.LineTo(ray.Start).Length;
            distance += dist;
            if (surf.Attenutive && inside)
            {
                lightCol.R *= Math.Exp(-(1.0 - surf.Attenuation[0]) * dist / surf.AttenuationDistance);
                lightCol.G *= Math.Exp(-(1.0 - surf.Attenuation[1]) * dist / surf.AttenuationDistance);
                lightCol.B *= Math.Exp(-(1.0 - surf.Attenuation[2]) * dist / surf.AttenuationDistance);
            }
            #if DEBUG
            Photon currentParent = PhotonParents[threadId];
            #endif
            if ((depth > 0 || allLightsArePhotons))
            {
                Photon photon = new Photon();
                photon.HitPos.X = (float)realHit.Normal.Start.X;
                photon.HitPos.Y = (float)realHit.Normal.Start.Y;
                photon.HitPos.Z = (float)realHit.Normal.Start.Z;
                photon.TravelDir.Dx = (float)ray.Direct.Dx;
                photon.TravelDir.Dy = (float)ray.Direct.Dy;
                photon.TravelDir.Dz = (float)ray.Direct.Dz;
                ColorIntensity photonColor = lightCol;
                if (realLighting || distance == double.PositiveInfinity)
                {
                    photonColor.R *= area / PhotonCount;
                    photonColor.G *= area / PhotonCount;
                    photonColor.B *= area / PhotonCount;
                }
                else
                {
                    photonColor.R *= distance * distance * area / PhotonCount;
                    photonColor.G *= distance * distance * area / PhotonCount;
                    photonColor.B *= distance * distance * area / PhotonCount;
                }
                photon.PhotonColorPower.R = (float)photonColor.R;
                photon.PhotonColorPower.G = (float)photonColor.G;
                photon.PhotonColorPower.B = (float)photonColor.B;
            #if DEBUG
                photon.parent = currentParent;
                PhotonParents[threadId] = photon;
            #endif
                Map.AddPhoton(photon, threadId);
            }
            ColorIntensity reflectance = new ColorIntensity();
            ColorIntensity transmitance = new ColorIntensity();
            Line refractRay = new Line();
            Line reflectRay = new Line();
            if (surf.Refractive || surf.Reflective)
            {
                ray.Direct = ray.Direct.Scale(1 / ray.Direct.Length);
                reflectance.R = surf.Reflective ? surf.Reflectance[0] : 0.0;
                reflectance.G = surf.Reflective ? surf.Reflectance[1] : 0.0;
                reflectance.B = surf.Reflective ? surf.Reflectance[2] : 0.0;
                if (surf.Refractive)
                {
                    double ni = inside ? surf.RefractIndex : 1.0;
                    double nt = (!inside) ? surf.RefractIndex : 1.0;
                    double cratio = ni / nt;
                    double ct1 = -ray.Direct.Dot(realHit.Normal.Direct);
                    double ct2sqrd = 1 - cratio * cratio * (1 - ct1 * ct1);
                    if (ct2sqrd <= 0)
                    {
                        reflectance.R = 1;
                        reflectance.G = 1;
                        reflectance.B = 1;
                    }
                    else
                    {
                        double ct2 = Math.Sqrt(ct2sqrd);
                        // fresnel equations for reflectance perp and parallel.
                        double rperp = (ni * ct1 - nt * ct2) / (ni * ct1 + nt * ct2);
                        double rpll = (nt * ct1 - ni * ct2) / (ni * ct2 + nt + ct1);
                        // assume unpolarised light always - better then tracing 2
                        // rays for both sides of every interface.
                        double reflectanceval = (rperp * rperp + rpll * rpll) / 2;
                        reflectance.R = Math.Min(1.0, reflectance.R + reflectanceval);
                        reflectance.G = Math.Min(1.0, reflectance.G + reflectanceval);
                        reflectance.B = Math.Min(1.0, reflectance.B + reflectanceval);
                        transmitance.R = 1 - reflectance.R;
                        transmitance.G = 1 - reflectance.G;
                        transmitance.B = 1 - reflectance.B;
                        refractRay.Direct = ray.Direct.Scale(cratio);
                        refractRay.Direct.Add(realHit.Normal.Direct.Scale(cratio * (ct1) - ct2));
                        refractRay.Start = realHit.Normal.Start.MoveBy(refractRay.Direct.Scale(EPSILON * 10));
                    }
                }
                reflectRay.Direct = new Vector(ray.Direct.Dx, ray.Direct.Dy, ray.Direct.Dz);
                reflectRay.Direct.Add(realHit.Normal.Direct.Scale(-2 * ray.Direct.Dot(realHit.Normal.Direct)));
                reflectRay.Start = realHit.Normal.Start.MoveBy(reflectRay.Direct.Scale(EPSILON * 10));
            }
            bool doReflect = false;
            bool doRefract = false;
//.........这里部分代码省略.........
开发者ID:Tilps,项目名称:Stash,代码行数:101,代码来源:ToyTracer.cs


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