public override RenderThread CreateRenderThread(int threadIndex, IntersectionEngine intersectionDevice, RayEngineScene scene, IImageFilm flm,IFrameManager manager, SamplingContext samplingContext) { if (this.film == null) film = flm; return new SpectralRenderThread(threadIndex, intersectionDevice, scene, samplingContext.LowLatency, this.film, samplingContext, manager,sceneManager); }
public SpectralRenderingEngine(RayEngineScene scene) : base(scene) { sceneManager = new SceneManager(scene); sceneManager.Build(); new HitManager(sceneManager); }
public override void EvaluateIllumination(RayEngineScene scn, float u0, float u1, float u2, float u3, float u4, out RayData ray, out float pdf, out IColorType radiance) { Vector dir = MC.UniformSampleSphere(u0, u1); ray = new RayData(ref Position, ref dir, 1e-4f, 1e4f); pdf = MathLab.INV4PI; radiance = (power.Mul(MathLab.M_PI * 4f)); }
protected DeviceRenderThreadBase(int index, IIntersectionEngine device, RayEngineScene scn, bool lowLatency, IImageFilm pixelDevice, ISampler sampler, SurfaceSampler ss) : base(index, scn) { this.Init(device, lowLatency, pixelDevice, sampler, ss); }
public SceneManager(RayEngineScene scn) { this.Scene = scn; this.solidMaterials = new Dictionary<string, SolidMaterial>(); this.lightMaterials = new Dictionary<string, LightMaterial>(); this.Objects = new SolidObject[scn.Meshes.Length]; this.Lights = new LightsourceObject[scn.Lights.Length]; if (EngineConfiguration.Instance.SceneManager == null) { EngineConfiguration.Instance.SceneManager = this; } }
public override void Init(int maxPaths, RayEngineScene scene, Core.Interface.IImageFilm agg, SamplingContext sc) { this.maxPaths = maxPaths; this.surfaceSampler = (SurfaceSampler)sc.SurfaceSampler; this.Sampler = sc.PrimarySpaceSampler; this.Scene = scene; this.film = agg; this.sampleBuffer = film.GetFreeSampleBuffer(); this.paths = new [] { new List<PathSamplerBase>(scene.MaxPaths + 1), new List<PathSamplerBase>(scene.MaxPaths + 1), }; }
public TriangleMeshLight(LightMaterial mt, RayEngineScene scene, TriangleMeshInfo mesh) : base(mt) { this.scene = scene; this.mesh = mesh; this.rnd = new FastRandom(); triangleSampleData = new TriangleSample[this.mesh.TrianglesCount]; for (int i = mesh.StartTriangle, j = 0; i < mesh.EndTriangle; i++, j++) { triangleSampleData[j] = new TriangleSample(scene.Triangles[i].AreaV(scene.Vertices), NormalModifier * scene.Triangles[i].ComputeNormal(scene.Vertices)); } triangleSampleData.PartialSort((a, b) => a.Item1.CompareTo(a.Item1), 0, triangleSampleData.Length); }
public MegarayIntersectionDevice(RayEngineScene scene, NVContext ctx) { this.scene = scene; wallclock = new Stopwatch(); this.todoRayBuffers = new InputRayBufferCollection<RayBuffer>(); this.doneRayBuffers = new OutputRayBufferCollection<RayBuffer>(); this.started = false; if (ctx != null) { this.cudaContext = ctx; } else { this.cudaContext = new NVContext() { Context = new CudaContext(CudaContext.GetMaxGflopsDeviceId()) }; } using (var sr = new StreamReader(@"H:\Git\RayDen\CudaMegaRay\x64\Release\MegarayKernels.cu.ptx")) { intersectKernel = cudaContext.Context.LoadKernelPTX(sr.BaseStream, "Intersect"); } this.rays = new CudaDeviceVariable<RayRecord>(RayBuffer.RayBufferSize); this.hits = new CudaDeviceVariable<RayHit>(RayBuffer.RayBufferSize); verts = scene.Vertices.ToArray(); tris=scene.Triangles.Select(i => i.GetInfo()).ToArray(); if (GlobalConfiguration.Instance.UseSceneCaching && scene.Cache != null) { bvh = scene.Cache.BvhData; nodesCount = scene.Cache.BvhData.Length; } else { var da = new BvhDataAdapter(scene); var treeData = da.BuildData(); bvh = treeData; nodesCount = treeData.Length; } Tracer.TraceLine("BVH Data Size {0:F3} MBytes", (nodesCount * 32f) / (1024f * 1024f)); }
public abstract void EvaluateIllumination(RayEngineScene scn, float u0, float u1, float u2, float u3, float u4, out RayData ray, out float pdf, out IColorType radiance);
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(); }
protected BaseMaterial(MaterialInfo mi, RayEngineScene scene) { this.mi = mi; this.Exponent = mi.Exponent; this.IndexOfRefraction = (ConstWavelengthDependentValue)mi.MediumInfo.IoR; if (mi.DiffuseTexture != null) { Diffuse = TextureFactory.Instance.CreateImageTexture( (RgbSpectrumTexture)scene.Query(mi.MaterialName, TextureType.Diffuse)); } else { Diffuse = TextureFactory.Instance.CreateConstTexture(ref mi.Kd); } if (mi.Specular != null) { Specular = TextureFactory.Instance.CreateImageTexture( (RgbSpectrumTexture)scene.Query(mi.MaterialName, TextureType.Specular)); } else { Specular = TextureFactory.Instance.CreateConstTexture(ref mi.Kr); } if (mi.AlphaTexture != null) { Alpha = TextureFactory.Instance.CreateImageTexture( (RgbSpectrumTexture)scene.Query(mi.MaterialName, TextureType.Alpha)); } var zeroSpectrum = RgbSpectrum.ZeroSpectrum(); var zeroTex = TextureFactory.Instance.CreateConstTexture(ref zeroSpectrum); if (mi.BumpTexture != null && scene.OptTextures.Contains(mi.BumpTexture)) { Bump = TextureFactory.Instance.CreateImageTexture( (RgbSpectrumTexture)scene.Query(mi.MaterialName, TextureType.Bump)); } //else //{ // Bump = zeroTex; //} if (!mi.GlossReflectance.IsBlack()) { Glossy = TextureFactory.Instance.CreateConstTexture(ref mi.Ks); } //else //{ // Glossy = zeroTex; //} if (!mi.Kt.IsBlack()) { Transmission = TextureFactory.Instance.CreateConstTexture(ref mi.Kt); } //else //{ // Transmission = zeroTex; //} if (!mi.Reflectance.IsBlack()) { Reflectance = TextureFactory.Instance.CreateConstTexture(ref mi.Reflectance); } //else //{ // Reflectance = zeroTex; //} }
public void Initialize(RayEngineScene scene) { EngineConfiguration.Instance.Mode = ColorMode.Rgb; ColorManager.Instance.Mode = ColorMode.Rgb; }
public WavefrontPathTracer(RayEngineScene scene) : base(scene) { }
public SolidMaterial(int id, MaterialInfo mi, RayEngineScene scn, BrdfBase brdf) : base(mi, scn) { this.Id = id; this.brdf = brdf; }
public void OpenFrame(FrameDescription frame) { this.config = frame; this.FrameName = frame.FrameName; Width = frame.Get<int>("ImageWidth"); 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); } primitives = new List<GLScenePrimitive>(); bboxes = new List<AABB>(); var helper = new BoundingVolumeHierarchyAccelerationHelper(); var s = new RayEngineScene(); //(scene, null); helper.Init( s, s.Meshes.ToArray()); bboxes.AddRange(helper.nodes.Select(item=>item.Bounds)); }
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(); }
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); /* 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", 32); 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.Initialize(); ExportConfiguration(frame).Save(@"F:\Dev\Frames\Config\" + Path.GetFileNameWithoutExtension(FrameName) + ".sceneconfig"); }
protected DeviceRenderThreadBase(int index, RayEngineScene scene) : base(index, scene) { }
public void OpenSceneConfiguration(string configPath) { Scene = new RayEngineScene(); this.Scene.DefaultLightGain = config.Get("LightGain", new RgbSpectrum(1.75f)); this.Scene.MaxPathDepth = config.Get("MaxPathDepth", 10); this.Scene.RussianRuletteImportanceCap = config.Get("RRImportanceCap", 0.75f); this.Scene.MaxPaths = config.Get("PathBufferSize", 65536 >> 1); this.Scene.ShadowRayCount = config.Get("ShadowRayCount", 1); var loader = new SceneConfigurationLoader(); loader.Load(configPath, Scene); this.width = ValueReader.Convert<int>(loader.Config.ReadFrame("width").ToString()); this.height = ValueReader.Convert<int>(loader.Config.ReadFrame("height").ToString()); this.AreaLightAsMeshLight = Scene.AreaLightAsMesh; this.Scene.MatLib = this.dependencyManager.GetMaterialPlugin(loader.MaterialInfos); if (loader.Materials.Any()) { this.Scene.MatLib.Merge(loader.Materials.ToArray()); } RenderThreadsCount = config.Get("RenderThreadsCount", 1); this.scene = loader.SceneGeo; var sceneBound = new AABB(scene.BoundingSphereCenter - scene.BoundingSphereRadius, scene.BoundingSphereCenter + scene.BoundingSphereRadius); sceneBound.Expand(1f); var volumeBound = sceneBound; this.FrameName = loader.Config.ReadFrame("name").ToString(); Scene.VolumeIntegrator = new SingleScatteringIntegrator(volumeBound, volumeBound.Size.Length / 10f, //step 0.05f, //Probability RgbSpectrum.UnitSpectrum() * 0.05f, //Inscatering new RgbSpectrum(0.0005f) //Emission ); foreach (var triangleMeshInfo in Scene.sceneData.Meshes) { triangleMeshInfo.MaterialID = ((MaterialInfoContainer)Scene.MaterialProvider).GetMaterialID(triangleMeshInfo.MaterialName); } this.QualitySettings = loader.qualitySettings; this.OutputSettings = loader.outputSettings; this.Initialize(); }
public static BaseRenderingEngine CreateEngine(RenderingEngines type, RayEngineScene scene, bool lowLatency) { try { foreach (var definedType in AppDomain.CurrentDomain.GetAssemblies().SelectMany(pt => pt.DefinedTypes)) { if (Attribute.IsDefined(definedType, typeof(RenderingEngineAttribute))) { var attrVal = Attribute.GetCustomAttribute(definedType, typeof(RenderingEngineAttribute)) as RenderingEngineAttribute; if (attrVal != null && attrVal.EngineType == type) { var re = Activator.CreateInstance(definedType, scene) as BaseRenderingEngine; if (re != null) { re.LowLatencySampling = lowLatency; return re; } } } } } catch { } switch (type) { case RenderingEngines.Direct: return new DirectLightEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.PPM: return new ProgressivePhotonMappingEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.BDPT: return new BDPTEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.PathTracer: return new PathTracerEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.PhotonMapping: return new PhotonMapRenderer(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.AO: return new AmbientOcclusionEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.VolumePathTracer: return new VolumePathTracerEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.SpectralPathTracer: return new SpectralPathTracerEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.MISPathTracer: return new MisPathTracerEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.MCMCPathTracer: return new MCMCPathTracerEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.MLPT: return new MLEngine(scene) { LowLatencySampling = lowLatency }; case RenderingEngines.LightTracer: return new LightTracerEngine(scene) { LowLatencySampling = lowLatency }; } throw new NotImplementedException(); }
protected BaseRenderingEngine(RayEngineScene scene) { LowLatencySampling = true; RenderThread.DeviceRenderBufferCount = this.MaxBufferPerThread; }
public void SetScene(IRayEngineScene scn) { Tracer.TraceLine("Setting scene"); this.scene = (RayEngineScene)scn; verts = scene.Vertices.ToArray(); tris = scene.Triangles.Select(i => i.GetInfo()).ToArray(); if (GlobalConfiguration.Instance.UseSceneCaching && scene.Cache != null) { bvh = scene.Cache.BvhData; nodesCount = scene.Cache.BvhData.Length; } else { var da = new BvhDataAdapter(scene); var treeData = da.BuildData(); bvh = treeData; nodesCount = treeData.Length; } }
public abstract RenderThread CreateRenderThread(int threadIndex, IntersectionEngine intersectionDevice, RayEngineScene scene, IImageFilm film, IFrameManager manager, SamplingContext samplingContext);
public override void EvaluateIllumination(RayEngineScene scn, float u0, float u1, float u2, float u3, float u4, out RayData ray, out float pdf, out IColorType radiance) { throw new System.NotImplementedException(); }
public virtual void Preprocess(RayEngineScene scene, IntersectionEngine ie) { }