Beispiel #1
0
        public void LoadFrameDescription(FrameDescription frame)
        {
            this.Configuration.Merge(frame);
            this.OutputSettings = new OutputSettingsInfo(frame);
            this.QualitySettings = new QualitySettingsInfo(frame);

            this.FrameName = frame.FrameName;
            var width = frame.Get<int>("ImageWidth");
            var height = frame.Get<int>("ImageHeight");

            Directory.SetCurrentDirectory(frame.WorkingDir);
            /*
            foreach (var frameElement in frame.Elements.Where(frameElement => frameParsers.ContainsKey(frameElement.GetType()))) {
                frameParsers[frameElement.GetType()](frameElement);
            }*/

            if (Scene == null)
            {
                SceneGraphService svc = new SceneGraphService();
                svc.Populate(new GlobalIndexObjLoader(), new MaterialLoader());

                //svc.OpenFrame(frame);
                _builder = new SceneBuilder() { SGService = svc };
                _builder.Setup();
                this.Scene = _builder.OpenFrame(frame, AreaLightAsMeshLight);
                this.Scene.DefaultLightGain = Configuration.Get("LightGain", new RgbSpectrum(1.0f));
                this.Scene.MaxPathDepth = Configuration.Get("MaxPathDepth", 5);
                this.Scene.RussianRuletteImportanceCap = Configuration.Get("RRImportanceCap", 0.75f);
                this.Scene.MaxPaths = Configuration.Get("PathBufferSize", 65536 >> 10);
                this.Scene.ShadowRayCount = Configuration.Get("ShadowRayCount", 1);
                this.Scene.TextureSamplingQuality = this.QualitySettings.TextureSamplingQuality;
                this.Scene.LightSamplingStrategy = LightSamplingStrategy.UniformOneLight;

                var scene = _builder.SceneGeo;

                var sceneBound = new AABB(scene.BoundingSphereCenter - scene.BoundingSphereRadius,
                                          scene.BoundingSphereCenter + scene.BoundingSphereRadius);
                sceneBound.Expand(1f);

                //var viewBound = new AABB(Scene.Camera.Target - 5f, Scene.Camera.Target + 5f);
                var c = new Point(Scene.Camera.Target);
                var bb = new AABB(c - 1f, c + 1f);
                var volumeBound = sceneBound;
                Scene.VolumeIntegrator = new SingleScatteringIntegrator(volumeBound,
                                                                         volumeBound.Size.Length / 10f, //step
                                                                         0.005f, //Probability
                                                                         RgbSpectrum.UnitSpectrum() * 0.095f,  //Inscatering
                                                                         new RgbSpectrum(0.00005f)             //Emission
                                                                       );
            }

            this.Context = new EngineContext() { RenderThreads = Configuration.Get("RenderThreadsCount", 1), FrameConfiguration = frame, Scene = this.Scene };
            this.Initialize();
        }
Beispiel #2
0
        public void Populate(int width, int height, SceneGraphInfo scg)
        {
            var svc = new SceneGraphService();
            svc.Populate(new GlobalIndexObjLoader(), new MaterialLoader());
            var cameras = new List<LtCamera>();
            var geometry = new List<LtGeoObject>();
            var lights = new List<LtLightsource>();
            var volumes = new List<LtVolume>();
            var solidMats = new List<SolidMaterial>();
            var matInfos = new List<MaterialInfo>();
            var lightInfos = new List<LightsourceInfo>();

            svc.SceneGraph.Visit((s) =>
            {
                if (s is GeometryGroupNode)
                {
                    sceneGeoInfo = (SceneGeometryInfo)scg.ResolveDataNode<SceneGeometryDataNode>(s as GeometryGroupNode).GetDataItem();
                }
                else if (s is LightsourceNode)
                {
                    var li = (LightsourceInfo)s.GetDataItem();
                    lightInfos.Add(li);
                }
                else if (s is CameraNode)
                {
                    var ci = (CameraInfo)s.GetDataItem();
                    cameras.Add(new LtCamera(new BasicPerspectiveCamera(ci.Position, ci.Direction, ci.Up, width, height, ci.Fov), ci));
                }
                else if (s is SceneMaterialDataNode)
                {
                    var mi = (MaterialInfo)s.GetDataItem();
                    matInfos.Add(mi);
                    Trace.TraceInformation("Loading textures for "+mi.Name);
                    Tracer.TraceLine("Loading textures for " + mi.Name);
                    foreach (var textureInfo in new[] { mi.Diffuse, mi.Alpha, mi.BumpMap, mi.NormalMap, mi.Specular })
                    {
                        TextureManager.Instance.LoadTexture(textureInfo);
                    }
                }
            });

            bool hasAreaLights = lightInfos.Any(item => item.Type == LightSourceTypes.Area);
            var solids = new Dictionary<string, SolidMaterial>();
            //Materials building 
            foreach (var materialInfo in matInfos)
            {
                var bsdf = SolidMaterialFactory.Instance.CreateMaterial(materialInfo);
                bsdf.Alpha = TextureManager.Instance.GetByInfo(materialInfo.Alpha);
                bsdf.Diffuse = TextureManager.Instance.GetByInfo(materialInfo.Diffuse);
                bsdf.Specular = TextureManager.Instance.GetByInfo(materialInfo.Specular);
                bsdf.Bump = TextureManager.Instance.GetByInfo(materialInfo.BumpMap);
                bsdf.Normal = TextureManager.Instance.GetByInfo(materialInfo.NormalMap);
                solidMats.Add(bsdf);
                bsdf.scene = scene;
                solids.Add(materialInfo.Name.ToLowerInvariant(), bsdf);
            }
            //Geometry
            foreach (var triangleMeshInfo in sceneData.Meshes)
            {
                if (VolumeSampler.IsVolume(triangleMeshInfo))
                {
                    var volumeObject = new LtVolume(new MeshShape(triangleMeshInfo), new VolumeProfile());
                    volumes.Add(volumeObject);
                }
                else
                {
                    var geoObject = new LtGeoObject(triangleMeshInfo,
                        solids[triangleMeshInfo.MaterialName.ToLowerInvariant()]);
                    geometry.Add(geoObject);
                }
                /*
                if (hasAreaLights)
                {
                    if (LightSampler.IsLight(triangleMeshInfo.MeshName))
                    {
                        
                    }
                }
                 */
            }

            //Lights

            foreach (var lightsourceInfo in lightInfos)
            {
                switch (lightsourceInfo.Type)
                {
                    case LightSourceTypes.Point:
                        lights.Add(new LtLightsource(new PointLightsource(), new EmissionProfile()));
                        break;
                }
            }

        }
        public void OpenFrame(FrameDescription frame)
        {
            this.config.Merge(frame);
            this.OutputSettings = new OutputSettingsInfo(frame);
            this.QualitySettings = new QualitySettingsInfo(frame);

            this.FrameName = frame.FrameName;
            width = frame.Get<int>("ImageWidth");
            height = frame.Get<int>("ImageHeight");
            if (!string.IsNullOrWhiteSpace(frame.WorkingDir))
                Directory.SetCurrentDirectory(frame.WorkingDir);
   
            if (Scene == null) {
                var svc = new SceneGraphService();
                svc.Populate(new GlobalIndexObjLoader(), new MaterialLoader());

                var builder = new SceneBuilder() { SGService = svc };
                builder.Setup();
                this.Scene = builder.OpenFrame(frame, AreaLightAsMeshLight);
                this.Scene.DefaultLightGain = config.Get("LightGain", new RgbSpectrum(1.0f));
                this.Scene.MaxPathDepth = config.Get("MaxPathDepth", 15);
                this.Scene.RussianRuletteImportanceCap = config.Get("RRImportanceCap", 0.75f);
                this.Scene.MaxPaths = config.Get("PathBufferSize", 65536 >> 10);
                this.Scene.ShadowRayCount = config.Get("ShadowRayCount", 16);
                this.Scene.TextureSamplingQuality = this.QualitySettings.TextureSamplingQuality;
                this.Scene.AreaLightAsMesh = this.AreaLightAsMeshLight;
                this.Scene.MatLib = new OptimizedBsdfLibrary();

                this.Scene.MatLib.Populate(builder.MaterialInfos.ToArray());

                (this.Scene.MatLib as OptimizedBsdfLibrary) .Replace("Object_MaterialView_Test", this.ObjectMaterial);
                (this.Scene.MatLib as OptimizedBsdfLibrary).Replace("Plane_Material", this.PlaneMaterial);

                foreach (var brdf in ObjectMaterial.Where(brdf => brdf != null))
                {
                    builder.ProcessMaterial(0, brdf.MaterialData);
                }
                foreach (var brdf in PlaneMaterial.Where(brdf => brdf != null))
                {
                    builder.ProcessMaterial(1, brdf.MaterialData);
                }

                RenderThreadsCount = config.Get("RenderThreadsCount",1);
                this.scene = builder.SceneGeo;

                var sceneBound = new AABB(scene.BoundingSphereCenter - scene.BoundingSphereRadius,
                                          scene.BoundingSphereCenter + scene.BoundingSphereRadius);
                sceneBound.Expand(1f);

                //var viewBound = new AABB(Scene.Camera.Target - 5f, Scene.Camera.Target + 5f);
                Scene.VolumeIntegrator = new SingleScatteringIntegrator(sceneBound, sceneBound.Size.Length / 10f, 0.15f, RgbSpectrum.UnitSpectrum()*0.095f, new RgbSpectrum(0.0005f));
            }
         

            this.Initialize();

        }
Beispiel #4
0
        public virtual void Setup(IRayDenLibraryFrame newFrame)
        {
            var svc = new SceneGraphService();
            svc.Populate(new GlobalIndexObjLoader(), new MaterialLoader());
            sceneBuilder = new SceneBuilder() { SGService = svc };
            sceneBuilder.Setup(this);
            sceneBuilder.OpenFrame(newFrame);

        }
        public void OpenFrame(Library.Entity.Frames.FrameDescription frame)
        {
            this.CurrentFrame = new FrameConfiguration();

            this.config.Merge(frame);
            this.OutputSettings = new OutputSettingsInfo(frame);
            this.QualitySettings = new QualitySettingsInfo(frame);

            this.FrameName = frame.FrameName;

            if (!string.IsNullOrWhiteSpace(frame.WorkingDir))
                Directory.SetCurrentDirectory(frame.WorkingDir);
            /*
            foreach (var frameElement in frame.Elements.Where(frameElement => frameParsers.ContainsKey(frameElement.GetType()))) {
                frameParsers[frameElement.GetType()](frameElement);
            }*/

            if (Scene == null)
            {
                SceneGraphService svc = new SceneGraphService();
                svc.Populate(
                    //new ObjLoader(),
                    new GlobalIndexObjLoader(),
                    new MaterialLoader());

                //svc.OpenFrame(frame);
                _builder = new SceneBuilder() { SGService = svc };
                _builder.Setup();
                this.SceneGraph = _builder.SGService.SceneGraph;
                this.Scene = _builder.OpenFrame(frame, this.AreaLightAsMeshLight);

                this.Scene.DefaultLightGain = config.Get("LightGain", new RgbSpectrum(1.0f));
                this.Scene.MaxPathDepth = config.Get("MaxPathDepth", 10);
                this.Scene.RussianRuletteImportanceCap = config.Get("RRImportanceCap", 0.75f);
                this.Scene.MaxPaths = config.Get("PathBufferSize", 65536);
                this.Scene.ShadowRayCount = config.Get("ShadowRayCount", 1);
                this.Scene.TextureSamplingQuality = this.QualitySettings.TextureSamplingQuality;
                this.Scene.LightSamplingStrategy = this.QualitySettings.LightSamplingStrategy;
                RgbSpectrum.Gamma = true;
                /*
                if (GlobalConfiguration.Instance.SpectralRendering)
                {
                    this.Scene.SpectralMats = new BxDFLibrary(new LambertianBrdf(new[] { 0.5f, 0.5f, 0.5f }));
                    this.Scene.SpectralMats.Populate(_builder.MaterialInfos.ToArray());
                }
                else*/

                {
                    this.Scene.MatLib = this.dependencyManager.GetMaterialPlugin(_builder.MaterialInfos.ToArray());
                    if (_builder.FrameMaterialBuilder != null)
                    {
                        this.Scene.MatLib.Add(_builder.FrameMaterialBuilder.Materials);
                        _builder.FrameMaterialBuilder.CreateRayEngineMaterials(this.Scene);
                    }
                    //if (EnableMaterialOverrides) FrameMaterialBuilder.ApplyMaterialOverrides((this.Scene.MatLib as OptimizedBsdfLibrary).Materials, Scene);
                }


                RenderThreadsCount = config.Get("RenderThreadsCount", 1);
                this.scene = _builder.SceneGeo;

                var sceneBound = new AABB(scene.BoundingSphereCenter - scene.BoundingSphereRadius,
                                          scene.BoundingSphereCenter + scene.BoundingSphereRadius);
                sceneBound.Expand(1f);

                //var viewBound = new AABB(Scene.Camera.Target - 5f, Scene.Camera.Target + 5f);
                var c = new Point(Scene.Camera.Target);
                var bb = new AABB(c - 1f, c + 1f);
                var volumeBound = sceneBound;

                Scene.VolumeIntegrator = new SingleScatteringIntegrator(volumeBound,
                                                                         volumeBound.Size.Length / 10f, //step
                                                                         0.05f, //Probability
                                                                         RgbSpectrum.UnitSpectrum() * 0.05f,  //Inscatering
                                                                         new RgbSpectrum(0.000f)             //Emission

                                                                       );
                new RayEngineMaterialBuilder().BuildMaterials(this.Scene);
            }
            this.CurrentFrame.Width = frame.Get<int>("ImageWidth");
            this.CurrentFrame.Height = frame.Get<int>("ImageHeight");
            this.CurrentFrame.ImageSavePath = this.SavePath;
            this.CurrentFrame.LowLatency = lowLatency;
            this.CurrentFrame.MaxSamplesPerPixel = this.QualitySettings.SamplesPerPixel;

            this.Initialize();
            this.Scene.BuildPrimitives();
        }