Exemplo n.º 1
0
        public override void Process(SceneReaderContext context)
        {
            context.VerifyWorld("ObjectInstance");

            if (context.RenderOptions.CurrentInstance != null)
                throw new InvalidOperationException("ObjectInstance can't be called inside instance definition.");
            if (!context.RenderOptions.Instances.ContainsKey(Name))
                throw new InvalidOperationException("Unable to find instance named '" + Name + "'.");

            var instances = context.RenderOptions.Instances[Name];
            if (instances.Count == 0)
                return;

            if (instances.Count > 1 || !instances[0].CanIntersect)
            {
                // Refine instance primitives and create aggregate.
                var accelerator = Factories.MakeAccelerator(
                    context.RenderOptions.AcceleratorName,
                    context.RenderOptions.AcceleratorParams,
                    instances);
                instances.Clear();
                instances.Add(accelerator);
            }

            var worldToInstance0 = Transform.Invert(context.CurrentTransform[0]);
            var worldToInstance1 = Transform.Invert(context.CurrentTransform[1]);
            var animatedWorldToInstance = new AnimatedTransform(
                worldToInstance0, context.RenderOptions.TransformStartTime,
                worldToInstance1, context.RenderOptions.TransformEndTime);
            context.RenderOptions.Primitives.Add(new TransformedPrimitive(
                instances[0], animatedWorldToInstance));
        }
Exemplo n.º 2
0
        public static Camera MakeCamera(string name, ParamSet parameters,
            TransformSet cameraToWorldSet, float transformStart, float transformEnd,
            Film film)
        {
            var animatedCameraToWorld = new AnimatedTransform(
                cameraToWorldSet[0], transformStart,
                cameraToWorldSet[1], transformEnd);

            switch (name)
            {
                case "perspective" :
                {
                    var shutterOpen = parameters.FindSingle("shutteropen", 0.0f);
                    var shutterClose = parameters.FindSingle("shutterclose", 1.0f);
                    if (shutterOpen < shutterClose)
                        MathUtility.Swap(ref shutterOpen, ref shutterClose);
                    var lensRadius = parameters.FindSingle("lensradius", 0.0f);
                    var focalDistance = parameters.FindSingle("focaldistance", 1e30f);
                    var frame = parameters.FindSingle("frameaspectratio", film.XResolution / (float) film.YResolution);
                    var screenWindow = parameters.FindSingleList("screenwindow");
                    if (screenWindow.Length != 4)
                        screenWindow = (frame > 1.0f)
                            ? new[] { -frame, frame, -1, 1 }
                            : new[] { -1, 1, -1 / frame, 1 / frame };
                    var fieldOfView = parameters.FindSingle("fov", 90.0f);

                    return new PerspectiveCamera(animatedCameraToWorld, screenWindow, shutterOpen, shutterClose,
                        lensRadius, focalDistance, fieldOfView, film);
                }
                default :
                    throw new ArgumentException("Unknown camera: " + name);
            }
        }
Exemplo n.º 3
0
 protected Camera(AnimatedTransform cameraToWorld,
     float shutterOpen, float shutterClose,
     Film film)
 {
     _cameraToWorld = cameraToWorld;
     _shutterOpen = shutterOpen;
     _shutterClose = shutterClose;
     _film = film;
 }
Exemplo n.º 4
0
 public PerspectiveCamera(
     AnimatedTransform cameraToWorld, float[] screenWindow, 
     float shutterOpen, float shutterClose, 
     float lensRadius, float focalDistance, 
     float fieldOfView,
     Film film)
     : base(cameraToWorld, Transform.Perspective(fieldOfView, 1e-2f, 1000.0f), screenWindow, shutterOpen, shutterClose, lensRadius, focalDistance, film)
 {
     // Compute differential changes in origin for perspective camera rays
     _dxCamera = RasterToCamera.TransformPoint(new Point(1, 0, 0)) - RasterToCamera.TransformPoint(new Point(0, 0, 0));
     _dyCamera = RasterToCamera.TransformPoint(new Point(0, 1, 0)) - RasterToCamera.TransformPoint(new Point(0, 0, 0));
 }
Exemplo n.º 5
0
        protected ProjectiveCamera(AnimatedTransform cameraToWorld, Transform cameraToScreen,
            float[] screenWindow, float shutterOpen, float shutterClose,
            float lensRadius, float focalDistance, Film film)
            : base(cameraToWorld, shutterOpen, shutterClose, film)
        {
            _cameraToScreen = cameraToScreen;
            _lensRadius = lensRadius;
            _focalDistance = focalDistance;

            // Compute projective camera screen transformations
            _screenToRaster = Transform.Scale(film.XResolution, film.YResolution, 1.0f)
                * Transform.Scale(1.0f / (screenWindow[1] - screenWindow[0]), 1.0f / (screenWindow[2] - screenWindow[3]), 1.0f)
                * Transform.Translate(new Vector(-screenWindow[0], -screenWindow[3], 0.0f));
            _rasterToScreen = Transform.Invert(_screenToRaster);
            _rasterToCamera = Transform.Invert(_cameraToScreen) * _rasterToScreen;
        }
Exemplo n.º 6
0
 public TransformedPrimitive(Primitive primitive, AnimatedTransform worldToPrimitive)
 {
     _primitive = primitive;
     _worldToPrimitive = worldToPrimitive;
 }
Exemplo n.º 7
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);
            }
        }