/// <summary> /// Create a new scene with the given SceneParameters and Device /// </summary> /// <param name="client">The client from C[CS]ycles API</param> /// <param name="sceneParams">The SceneParameters to create scene with</param> /// <param name="device">The Device to create scene for</param> public Scene(Client client, SceneParameters sceneParams, Device device) { Client = client; Id = CSycles.scene_create(Client.Id, sceneParams.Id, device.Id); Background = new Background(this); Camera = new Camera(this); Integrator = new Integrator(this); Film = new Film(this); Device = device; /* add simple wrappers for shadermanager created default shaders */ var surface = Shader.WrapDefaultSurfaceShader(client); var light = Shader.WrapDefaultLightShader(client); var background = Shader.WrapDefaultBackgroundShader(client); var empty = Shader.WrapDefaultEmptyShader(client); /* register the wrapped shaders with scene */ m_shader_in_scene_ids.Add(surface, surface.Id); m_shader_in_scene_ids.Add(background, background.Id); m_shader_in_scene_ids.Add(light, light.Id); m_shader_in_scene_ids.Add(empty, empty.Id); DefaultSurface = surface; // set ourself to client as reference client.Scene = this; }
public void RenderScene(string scenename) { var dev = Device.FirstGpu; Console.WriteLine("Using device {0} {1}", dev.Name, dev.Description); var scene_params = new SceneParameters(Client, ShadingSystem.SVM, BvhType.Static, false, false, false); var scene = new Scene(Client, scene_params, dev); var xml = new CSyclesXmlReader(Client, scenename); xml.Parse(false); var width = (uint)scene.Camera.Size.Width; var height = (uint)scene.Camera.Size.Height; var session_params = new SessionParameters(Client, dev) { Experimental = false, Samples = (int) samples, TileSize = new Size(64, 64), StartResolution = 64, Threads = (uint)(dev.IsCpu ? 0 : 0), ShadingSystem = ShadingSystem.SVM, Background = true, ProgressiveRefine = false, Progressive = false, TileOrder = TileOrder.HilbertSpiral }; var Session = new Session(Client, session_params, scene); Session.Reset(width, height, samples); g_write_render_tile_callback = WriteRenderTileCallback; Session.WriteTileCallback = g_write_render_tile_callback; /*if (!silent) { Session.UpdateCallback = g_update_callback; Session.UpdateTileCallback = g_update_render_tile_callback; Session.WriteTileCallback = g_write_render_tile_callback; } CSycles.set_logger(Client.Id, g_logger_callback); */ Session.Start(); Session.Wait(); uint bufsize; uint bufstride; CSycles.session_get_buffer_info(Client.Id, Session.Id, out bufsize, out bufstride); var pixels = CSycles.session_copy_buffer(Client.Id, Session.Id, bufsize); var bmp = new ed.Bitmap((int)width, (int)height, Eto.Drawing.PixelFormat.Format32bppRgba); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var i = y * (int)width * 4 + x * 4; bmp.SetPixel(x, y, new ed.Color(Math.Min(pixels[i], 1.0f), Math.Min(pixels[i + 1], 1.0f), Math.Min(pixels[i + 2], 1.0f), Math.Min(pixels[i + 3], 1.0f))); } } bmp.Save("test.png", Eto.Drawing.ImageFormat.Png); Result = bmp; Session.Destroy(); Console.WriteLine("Cleaning up :)"); }
static void Main(string[] args) { var file = ""; if (args.Length < 1 || args.Length > 2) { Console.WriteLine("Wrong count parameter: csycles_tester [--quiet] file.xml"); return; } var s = args[args.Length-1]; if (!File.Exists(s)) { Console.WriteLine("File {0} doesn't exist.", s); return; } var silent = args.Length == 2 && "--quiet".Equals(args[0]); file = Path.GetFullPath(s); Console.WriteLine("We get file path: {0}", file); var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? ""; var userpath = Path.Combine(path, "userpath"); CSycles.path_init(path, userpath); CSycles.initialise(); const uint samples = 50; g_update_callback = StatusUpdateCallback; g_update_render_tile_callback = UpdateRenderTileCallback; g_write_render_tile_callback = WriteRenderTileCallback; g_logger_callback = LoggerCallback; var client = new Client(); Client = client; if (!silent) { CSycles.set_logger(client.Id, g_logger_callback); } foreach (var adev in Device.Devices) { Console.WriteLine("{0}", adev); } Console.WriteLine("All device capabilities: {0}", Device.Capabilities); var dev = Device.FirstCuda; Console.WriteLine("Using device {0} {1}", dev.Name, dev.Description); var scene_params = new SceneParameters(client, ShadingSystem.SVM, BvhType.Static, false, false, false, false); var scene = new Scene(client, scene_params, dev); Console.WriteLine("Default surface shader {0}", scene.DefaultSurface.Name); #region background shader var background_shader = new Shader(client, Shader.ShaderType.World) { Name = "Background shader" }; var bgnode = new BackgroundNode(); bgnode.ins.Color.Value = new float4(0.7f); bgnode.ins.Strength.Value = 1.0f; background_shader.AddNode(bgnode); bgnode.outs.Background.Connect(background_shader.Output.ins.Surface); background_shader.FinalizeGraph(); scene.AddShader(background_shader); scene.Background.Shader = background_shader; scene.Background.AoDistance = 0.0f; scene.Background.AoFactor = 0.0f; scene.Background.Visibility = PathRay.AllVisibility; #endregion #region diffuse shader var diffuse_shader = create_some_setup_shader(); scene.AddShader(diffuse_shader); scene.DefaultSurface = diffuse_shader; #endregion #region point light shader var light_shader = new Shader(client, Shader.ShaderType.Material) { Name = "Tester light shader" }; var emission_node = new EmissionNode(); emission_node.ins.Color.Value = new float4(0.8f); emission_node.ins.Strength.Value = 10.0f; light_shader.AddNode(emission_node); emission_node.outs.Emission.Connect(light_shader.Output.ins.Surface); light_shader.FinalizeGraph(); scene.AddShader(light_shader); #endregion var xml = new XmlReader(client, file); xml.Parse(silent); var width = (uint)scene.Camera.Size.Width; var height = (uint)scene.Camera.Size.Height; var session_params = new SessionParameters(client, dev) { Experimental = false, Samples = (int) samples, TileSize = new Size(64, 64), StartResolution = 64, Threads = 0, ShadingSystem = ShadingSystem.SVM, Background = true, ProgressiveRefine = false }; Session = new Session(client, session_params, scene); Session.Reset(width, height, samples); /*if (!silent) { Session.UpdateCallback = g_update_callback; Session.UpdateTileCallback = g_update_render_tile_callback; Session.WriteTileCallback = g_write_render_tile_callback; }*/ Session.Start(); Session.Wait(); uint bufsize; uint bufstride; CSycles.session_get_buffer_info(client.Id, Session.Id, out bufsize, out bufstride); var pixels = CSycles.session_copy_buffer(client.Id, Session.Id, bufsize); var bmp = new Bitmap((int)width, (int)height); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var i = y * (int)width * 4 + x * 4; var r = ColorClamp((int)(pixels[i] * 255.0f)); var g = ColorClamp((int)(pixels[i + 1] * 255.0f)); var b = ColorClamp((int)(pixels[i + 2] * 255.0f)); var a = ColorClamp((int)(pixels[i + 3] * 255.0f)); bmp.SetPixel(x, y, Color.FromArgb(a, r, g, b)); } } bmp.Save("test.png", ImageFormat.Png); Console.WriteLine("Cleaning up :)"); CSycles.shutdown(); Console.WriteLine("Done"); }
/// <summary> /// create a ccl.Scene /// </summary> /// <param name="client">Client to create scene for</param> /// <param name="render_device">Render device to use</param> /// <param name="cycles_engine">Engine instance to create for</param> /// <returns></returns> protected static Scene CreateScene(Client client, Device render_device, RenderEngine cycles_engine) { #region set up scene parameters var scene_params = new SceneParameters(client, ShadingSystem.SVM, BvhType.Dynamic, false, false, false); #endregion #region create scene var scene = new Scene(client, scene_params, render_device) { #region integrator settings Integrator = { MaxBounce = cycles_engine.Settings.MaxBounce, MinBounce = cycles_engine.Settings.MinBounce, TransparentMinBounce = cycles_engine.Settings.TransparentMinBounce, TransparentMaxBounce = cycles_engine.Settings.TransparentMaxBounce, MaxDiffuseBounce = cycles_engine.Settings.MaxDiffuseBounce, MaxGlossyBounce = cycles_engine.Settings.MaxGlossyBounce, MaxTransmissionBounce = cycles_engine.Settings.MaxTransmissionBounce, MaxVolumeBounce = cycles_engine.Settings.MaxVolumeBounce, NoCaustics = cycles_engine.Settings.NoCaustics, TransparentShadows = cycles_engine.Settings.TransparentShadows, DiffuseSamples = cycles_engine.Settings.DiffuseSamples, GlossySamples = cycles_engine.Settings.GlossySamples, TransmissionSamples = cycles_engine.Settings.TransmissionSamples, AoSamples = cycles_engine.Settings.AoSamples, MeshLightSamples = cycles_engine.Settings.MeshLightSamples, SubsurfaceSamples = cycles_engine.Settings.SubsurfaceSamples, VolumeSamples = cycles_engine.Settings.VolumeSamples, AaSamples = cycles_engine.Settings.AaSamples, FilterGlossy = cycles_engine.Settings.FilterGlossy, IntegratorMethod = cycles_engine.Settings.IntegratorMethod, SampleAllLightsDirect = cycles_engine.Settings.SampleAllLights, SampleAllLightsIndirect = cycles_engine.Settings.SampleAllLightsIndirect, SampleClampDirect = cycles_engine.Settings.SampleClampDirect, SampleClampIndirect = cycles_engine.Settings.SampleClampIndirect, SamplingPattern = SamplingPattern.CMJ, Seed = cycles_engine.Settings.Seed } #endregion }; scene.Film.SetFilter(FilterType.Gaussian, 1.5f); scene.Film.Exposure = 1.0f; scene.Film.Update(); #endregion #region background shader // we add here a simple background shader. This will be repopulated with // other nodes whenever background changes are detected. var background_shader = new Shader(client, Shader.ShaderType.World) { Name = "Rhino Background" }; var bgnode = new BackgroundNode("orig bg"); bgnode.ins.Color.Value = new float4(0.7f); bgnode.ins.Strength.Value = 1.0f; background_shader.AddNode(bgnode); bgnode.outs.Background.Connect(background_shader.Output.ins.Surface); background_shader.FinalizeGraph(); scene.AddShader(background_shader); scene.Background.Shader = background_shader; scene.Background.AoDistance = 0.0f; scene.Background.AoFactor = 0.0f; scene.Background.Visibility = PathRay.AllVisibility; #endregion return scene; }