예제 #1
0
파일: Shape.cs 프로젝트: qrush/q-tracer
        public override Color3 colorNormal(Color3 existing, Ray r, Hit h, Shape s, Light bulb)
        {
            switch (shader)
             {
            case ProcShading.Circle:
               return mapCircle(h);

            case ProcShading.Texture:
               return mapTexture(h);

            default:
               return mapSquare(h);
             }
        }
예제 #2
0
파일: Tracer.cs 프로젝트: qrush/q-tracer
        // spawn a shadow ray from the intersection point to the light source.
        private static bool spawnShadow(Light bulb, Hit finalHit, Shape hitShape, Shape fromShape)
        {
            Ray shadowRay = new Ray();
             shadowRay.start = finalHit.intersect;
             shadowRay.direction = Point3.vectorize(shadowRay.start, bulb.Location);
             double shadowDist = Point3.distance(shadowRay.start, bulb.Location);

             foreach (Shape s in layout.Shapes)
             {
            // If this is the object we're checking from, ignore. Duh.
            if (s.Equals(hitShape) || s.Equals(fromShape) || s.Material.Kt > 0)
               continue;

            Hit shadowHit = s.intersect(shadowRay);

            if (shadowHit.intersect.z == Constants.FAR_AWAY)
               continue;

            // We need to check if hitShape object is in FRONT OF the current one. if it is, we need to ignore this current shape.
            Vector3 frontTest = Point3.vectorize(shadowHit.intersect, finalHit.intersect);

            if (frontTest.X > 0 && frontTest.Y > 0 && frontTest.Z > 0)
               continue;

            // something has to come between the light and the current shape.
            double shapeDist = Point3.distance(shadowRay.start, shadowHit.intersect);
            if (shapeDist < shadowDist)
            {
               return true;
            }
             }

             return false;
        }
예제 #3
0
파일: Shape.cs 프로젝트: qrush/q-tracer
 public override Color3 colorNormal(Color3 existing, Ray r, Hit h, Shape s, Light bulb)
 {
     return Color3.Black;
 }
예제 #4
0
파일: Shape.cs 프로젝트: qrush/q-tracer
 public abstract Color3 colorNormal(Color3 existing, Ray r, Hit h, Shape s, Light bulb);
예제 #5
0
파일: Color3.cs 프로젝트: qrush/q-tracer
        public static Color3 specular(Ray r, Hit h, Shape s, Light bulb)
        {
            Color3 specular = Black;
             Vector3 normal = s.calcNormal(h);

             Vector3 lightDir = Point3.vectorize(bulb.Location, h.intersect);
             Vector3 refDir = lightDir - (2 * (Vector3.DotProduct(lightDir, normal) / Math.Pow(normal.Abs(), 2)) * normal);
             double specularDot = Vector3.DotProduct(r.direction, refDir);

             if (specularDot >= 0)
            specular = (bulb.Color * s.Material.Specular) * Math.Pow(specularDot, s.Material.Ke);

             return specular;
        }
예제 #6
0
파일: Color3.cs 프로젝트: qrush/q-tracer
        public static Color3 diffuse(Hit h, Shape s, Light bulb)
        {
            Color3 diffuse = Black;
             Vector3 normal = s.calcNormal(h);
             Vector3 lightDir = Point3.vectorize(bulb.Location, h.intersect);
             double diffuseDot = Vector3.DotProduct(lightDir, normal);

             if (diffuseDot >= 0)
            diffuse = (bulb.Color * s.Material.Diffuse) * diffuseDot;

             return diffuse;
        }