/*public ColorRgb Radiance(PointLight light, HitInfo hit) * { * Vector3 inDirection = (light.Position - hit.HitPoint).Normalised; * double diffuseFactor = inDirection.Dot(hit.Normal); * * if (diffuseFactor < 0) { return ColorRgb.Black; } * * ColorRgb result = light.Color * materialColor * diffuseFactor * diffuseCoeff; * double phongFactor = PhongFactor(inDirection, hit.Normal, -hit.Ray.Direction); * * if(phongFactor != 0) * { result += materialColor * specular * phongFactor; } * * return result; * }*/ public ColorRgb Shade(Raytracer tracer, HitInfo hit) { ColorRgb totalColor = ColorRgb.Black; foreach (var light in hit.World.Lights) { Vector3 inDirection = (light.Position - hit.HitPoint).Normalised; double diffuseFactor = inDirection.Dot(hit.Normal); if (diffuseFactor < 0) { return(ColorRgb.Black); } if (hit.World.AnyObstacleBetween(hit.HitPoint, light.Position)) { continue; } ColorRgb result = light.Color * materialColor * diffuseFactor * diffuseCoeff; double phongFactor = PhongFactor(inDirection, hit.Normal, -hit.Ray.Direction); if (phongFactor != 0) { result += materialColor * specular * phongFactor; } totalColor += result; } return(totalColor); }
Color StripColor(ColorRgb colorInfo) { colorInfo.R = colorInfo.R < 0 ? 0 : colorInfo.R > 1 ? 1 : colorInfo.R; colorInfo.G = colorInfo.G < 0 ? 0 : colorInfo.G > 1 ? 1 : colorInfo.G; colorInfo.B = colorInfo.B < 0 ? 0 : colorInfo.B > 1 ? 1 : colorInfo.B; return(Color.FromArgb((int)(colorInfo.R * 255), (int)(colorInfo.G * 255), (int)(colorInfo.B * 255))); }
public Phong(ColorRgb materialColor, double diffuse, double specular, double specularExponent) { this.materialColor = materialColor; this.diffuseCoeff = diffuse; this.specular = specular; this.specularExponent = specularExponent; }
public ColorRgb Shade(Raytracer tracer, HitInfo hit) { Vector3 toCameraDirection = -hit.Ray.Direction; ColorRgb radiance = direct.Shade(tracer, hit); Vector3 reflectionDirection = Vector3.Reflect(toCameraDirection, hit.Normal); Ray reflectedRay = new Ray(hit.HitPoint, reflectionDirection); ColorRgb reflected = tracer.ShadeRay(hit.World, reflectedRay, hit.Depth) * reflectionColor * reflectivity; radiance += tracer.ShadeRay(hit.World, reflectedRay, hit.Depth) * reflectionColor * reflectivity; return(radiance); }
/*public ColorRgb Radiance(PointLight light, HitInfo hit) { * Vector3 inDirection = (light.Position - hit.HitPoint).Normalised; * double diffuseFactor = inDirection.Dot(hit.Normal); * if (diffuseFactor < 0) { return ColorRgb.Black; } * return light.Color * materialColor * diffuseFactor; * }*/ public ColorRgb Shade(Raytracer tracer, HitInfo hit) { ColorRgb totalColor = ColorRgb.Black; foreach (var light in hit.World.Lights) { Vector3 inDirection = (light.Position - hit.HitPoint).Normalised; double diffuseFactor = inDirection.Dot(hit.Normal); if (diffuseFactor < 0) { continue; } if (hit.World.AnyObstacleBetween(hit.HitPoint, light.Position)) { continue; } totalColor += light.Color * materialColor * diffuseFactor; } return(totalColor); }
public PointLight(Vector3 position, ColorRgb color) { this.Position = position; this.Color = color; }
public Light(Vector3 vector, bool Directed, ColorRgb color) { this.Vector = vector; this.Directed = Directed; this.Color = color; }
public PerfectDiffuse(ColorRgb materialColor) { this.materialColor = materialColor; }
public Reflective(ColorRgb materialColor, double diffuse, double specular, double exponent, double reflectivity) { this.direct = new Phong(materialColor, diffuse, specular, exponent); this.reflectivity = reflectivity; this.reflectionColor = materialColor; }