コード例 #1
0
        public override Scene CreateScene(Film film)
        {
            var camera = new PerspectiveCamera(film,
                1.0f, 100.0f, Vector3D.Forward, Vector3D.Up,
                new Point3D(0, 0, 15), MathUtility.PI_OVER_4);

            var surfaceIntegrator = new WhittedIntegrator(6);

            var sampler = new RegularSampler(
                new IntPoint2D(0, 0),
                new IntPoint2D(film.XRes, film.YRes));

            var shape = new Aether.Shapes.Sphere(new TranslateTransform(), 5);
            var material = new MatteMaterial(ColorsF.Red);
            var primitive = new GeometricPrimitive(shape, material);

            var lights = new List<Light>
            {
//                new PointLight(
//                    new TranslateTransform { OffsetX = 10, OffsetY = 10, OffsetZ = 10},
//                    new ColorF(0.5f))
                new DirectionalLight(new RotateTransform3D(), Vector3D.Down, new ColorF(0.5f))
            };

            return new Scene(camera, surfaceIntegrator, sampler, primitive,
                             lights);
        }
コード例 #2
0
        private void ProcessShape(SceneReaderContext context)
        {
            Primitive prim = null;
            AreaLight area = null;
            if (!context.CurrentTransform.IsAnimated)
            {
                // Create primitive for static shape.

                var shape = Factories.MakeShape(ImplementationType,
                    context.CurrentTransform[0], context.GraphicsState.ReverseOrientation,
                    Parameters);
                var material = context.GraphicsState.CreateMaterial(
                    Parameters, context.CurrentTransform[0]);

                // Possibly create area light for shape.
                if (!string.IsNullOrEmpty(context.GraphicsState.AreaLight))
                    area = Factories.MakeAreaLight(
                        context.GraphicsState.AreaLight,
                        context.CurrentTransform[0],
                        context.GraphicsState.AreaLightParams,
                        shape);
                prim = new GeometricPrimitive(shape, material, area);
            }
            else
            {
                // Create primitive for animated shape.

                var shape = Factories.MakeShape(ImplementationType, new Transform(),
                    context.GraphicsState.ReverseOrientation, Parameters);
                var material = context.GraphicsState.CreateMaterial(
                    Parameters, context.CurrentTransform[0]);

                // Get animatedWorldToObject transform for shape.
                var worldToObj0 = Transform.Invert(context.CurrentTransform[0]);
                var worldToObj1 = Transform.Invert(context.CurrentTransform[1]);
                var animatedWorldToObject = new AnimatedTransform(
                    worldToObj0, context.RenderOptions.TransformStartTime,
                    worldToObj1, context.RenderOptions.TransformEndTime);

                Primitive basePrim = new GeometricPrimitive(shape, material, null);
                if (!basePrim.CanIntersect)
                {
                    // Refine animated shape and create BVH if more than one shape created.
                    var refinedPrimitives = basePrim.FullyRefine();
                    if (refinedPrimitives.Count == 0)
                        return;
                    basePrim = (refinedPrimitives.Count > 1)
                        ? new BoundingVolumeHierarchyAccelerator(refinedPrimitives) 
                        : refinedPrimitives[0];
                }
                prim = new TransformedPrimitive(basePrim, animatedWorldToObject);
            }

            // Add primitive to scene or current instance.
            if (context.RenderOptions.CurrentInstance != null)
            {
                context.RenderOptions.CurrentInstance.Add(prim);
            }
            else
            {
                context.RenderOptions.Primitives.Add(prim);
                if (area != null)
                    context.RenderOptions.Lights.Add(area);
            }
        }