public override Vec3 Shade(ShadeRec sr) { Vec3 wo = sr.Ray.D * -1; Vec3 L = ambient.RHO(sr, wo) * sr.World.AmbientLight.L(sr); foreach (var light in sr.World.Lights) { Vec3 wi = light.GetDirection(sr); float ndotwi = (float)sr.Normal.Dot(wi); if (ndotwi > 0.0) { bool inShadow = false; if (light.Shadows) { Ray shadowRay = new Ray(sr.HitPoint, wi); inShadow = light.InShadow(shadowRay, sr); } if (!inShadow) { L += (Diffuse.F(sr, wi, wo) + specular.F(sr, wi, wo)) * light.L(sr) * ndotwi; } } } return(L); }
public override Vector3 Shade(ShadeRec sr) { Vector3 wo = -sr.Ray.Direction; Vector3 L = ambient.RHO(sr, wo) * sr.World.AmbientLight.L(sr); int num_lights = sr.World.Lights.Count; for (int j = 0; j < num_lights; j++) { Vector3 wi = sr.World.Lights[j].GetDirection(sr); float ndotwi = Vector3.Dot(sr.Normal, wi); if (ndotwi > 0.0) { if (Shadows) { bool in_shadow = false; if (sr.World.Lights[j].Shadows) { Ray shadowRay = new Ray(sr.HitPoint, wi); in_shadow = sr.World.Lights[j].InShadow(shadowRay, sr); } if (!in_shadow) { L += (diffuse.F(sr, wo, wi) + specular.F(sr, wo, wi)) * sr.World.Lights[j].L(sr) * ndotwi; } } else { L += (diffuse.F(sr, wo, wi) + specular.F(sr, wo, wi)) * sr.World.Lights[j].L(sr) * ndotwi; } } } return(L); }
public override RGBColor Shade(ShadeRec shadeRec) { Vector3d wo = -shadeRec.Ray.Direction; RGBColor L = ambientBRDF.Rho(shadeRec, wo) * shadeRec.World.AmbientLight.L((shadeRec)); for (int i = 0; i < shadeRec.World.Lights.Count; i++) { Vector3d wi = shadeRec.World.Lights[i].GetDirection(shadeRec); double NdotWi = Vector3d.Dot(shadeRec.Normal, wi); if (NdotWi > 0) { L = L + diffuseBRDF.F(shadeRec, wo, wi) + glossySpecularBRDF.F(shadeRec, wo, wi) * shadeRec.World.Lights[i].L(shadeRec) * NdotWi; } } return(L); }