public RColor Coloring(P3 p, Ray r, SceneObject so) { P2 textureLoc = so.shape.toP2(p); RColor textureColor = so.texture.texture(textureLoc); RColor sumOfLights = new RColor(0, 0, 0); RColor lightColor; foreach (Light lightSource in Form1.lights) { lightColor = lightSource.illumination(p,so); sumOfLights = sumOfLights.add(lightColor); } return RColor.multiplyColor(textureColor, sumOfLights); }
public RColor add(RColor c) { return new RColor(c.r + r, c.g + g, c.b + b); }
public static RColor multiplyColor(RColor c, RColor c2) { return new RColor(c.r * c2.r, c.b * c2.b, c.g * c2.g); }
public Directional(RColor color, P3 direction) { this.color = color; this.direction = direction.normalize(); }
public Ambient(RColor color) { this.color = color; }
public SolidTexture(RColor c) { this.c = c; }
//public static SceneObject shootRay(Ray r, out double d) //{ // float dist; // SceneObject obj = closest(r); // if (obj == null) // { // return null; // } // dist = obj.distance(r); // if (dist == infinity) // { // return null; // } // else // { // return obj; // } //} //public static SceneObject closest(Ray ray) //{ // SceneObject sceneObj = null; // float dist, smallestDist = infinity; // foreach (SceneObject obj in objects) // { // if ((dist = obj.distance(ray)) <= smallestDist) // { // smallestDist = dist; // sceneObj = obj; // } // } // return sceneObj; //} public void noName() { for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float size1 = size; P3 p = new P3(i / size1 * 2.0f - 1, 0, j / size1 * 2.0f - 1); Ray r = new Ray(camera, p.sub(camera).normalize()); float distance = sphere.intersect(r); if (distance != -1) { P3 sp = r.travel(distance); P3 n = sphere.normal(sp); float intensity = n.dotProduct(direction); if (intensity < 0) { intensity = 0; } pixels[i, j] = directional.scalarMultiply(intensity); } else { pixels[i, j] = new RColor(0, 0, 0); } } } panel.Refresh(); }