예제 #1
0
        public override Vector3 Shade(ShadeRec sr)
        {
            Vector3 wo         = -sr.ray.dir;
            Vector3 L          = ambientBRDF.rho(sr, wo) * sr.context.ambientLight.L(sr);
            int     lightCount = sr.context.lights.Count;

            for (int j = 0; j < lightCount; j++)
            {
                var     light  = sr.context.lights[j];
                Vector3 wi     = light.GetDirection(sr);
                float   nDotWi = sr.normal.Nor().Dot(wi.Nor());
                if (nDotWi > 0)
                {
                    bool inshadow = false;
                    if (light.CAST_SHADOW)
                    {
                        Ray shadowRay = new Ray(sr.localHitPoint + sr.normal * TracerConst.kEpsilon, wi);
                        inshadow = light.ShadowCheck(shadowRay, sr);
                    }
                    if (!inshadow)
                    {
                        L += light.L(sr) * nDotWi * diffuseBRDF.F(sr, wo, wi);
                    }
                }
            }

            return(L);
        }
예제 #2
0
        public override Vector3 Shade(ShadeRec sr)
        {
            Vector3 wo = -sr.ray.dir;
            Vector3 L  = m_ambientBRDF.rho(sr, wo) * sr.context.ambientLight.L(sr);

            int lc = sr.context.lights.Count;

            for (int i = 0; i < lc; i++)
            {
                var light = sr.context.lights[i];

                Vector3 wi = light.GetDirection(sr).Nor();

                AreaLight al = light as AreaLight;
                if (al != null && al.GEOMETRY.GetNormal(Vector3.Zero).Dot(wi) > 0)
                {
                    //判定单向
                    continue;
                }

                float ndotwi = sr.normal.Dot(wi);
                if (ndotwi > 0)
                {
                    bool inshadow = false;
                    if (light.CAST_SHADOW)
                    {
                        Ray shadowRay = new Ray(sr.localHitPoint + sr.normal * TracerConst.kEpsilon, wi);
                        inshadow = light.ShadowCheck(shadowRay, sr);
                    }


                    if (!inshadow)
                    {
                        L += (m_diffuseBRDF.F(sr, wo, wi) + m_specularBRDF.F(sr, wo, wi)) * light.L(sr) * ndotwi * light.G(sr) / light.PDF(sr);
                    }
                }
            }

            return(L);
        }