Beispiel #1
0
        public ViewportRenderEngine(uint docRuntimeSerialNumber, Guid pluginId, ViewInfo view) : base(pluginId, docRuntimeSerialNumber, view, null, true)
        {
            Client = new Client();
            State  = State.Rendering;

            Database.ViewChanged += Database_ViewChanged;

            ChangesReady += ViewportRenderEngine_ChangesReady;

            #region create callbacks for Cycles
            m_update_callback             = UpdateCallback;
            m_update_render_tile_callback = null;
            m_write_render_tile_callback  = null;
            if (!RcCore.It.CanUseDrawOpenGl())
            {
                m_write_render_tile_callback = WriteRenderTileCallback;
            }
            m_test_cancel_callback    = null;
            m_display_update_callback = null;
            m_logger_callback         = ViewportLoggerCallback;

            CSycles.log_to_stdout(false);
            //CSycles.set_logger(Client.Id, m_logger_callback);
            #endregion
        }
Beispiel #2
0
        static public void StatusUpdateCallback(uint sessionId)
        {
            float  progress;
            double total_time, render_time, tile_time;

            CSycles.progress_get_progress(Client.Id, sessionId, out progress, out total_time, out render_time, out tile_time);
            var  status    = CSycles.progress_get_status(Client.Id, sessionId);
            var  substatus = CSycles.progress_get_substatus(Client.Id, sessionId);
            uint samples;
            uint num_samples;

            CSycles.tilemanager_get_sample_info(Client.Id, sessionId, out samples, out num_samples);

            if (status.Equals("Finished"))
            {
                Console.WriteLine("wohoo... :D");
            }

            status = "[" + status + "]";
            if (!substatus.Equals(string.Empty))
            {
                status = status + ": " + substatus;
            }
            Console.WriteLine("C# status update: {0} {1} {2} {3} <|> {4:N}s {5:P}", CSycles.progress_get_sample(Client.Id, sessionId), status, samples, num_samples, total_time, progress);
        }
Beispiel #3
0
 protected override void OnShutdown()
 {
     RhinoApp.Initialized -= RhinoApp_Initialized;
     /* Clean up everything from C[CS]?ycles. */
     CSycles.shutdown();
     base.OnShutdown();
 }
Beispiel #4
0
 internal override void SetDirectMembers(uint clientId, uint shaderId)
 {
     CSycles.shadernode_set_member_float(clientId, shaderId, Id, Type, "offset", Offset);
     CSycles.shadernode_set_member_int(clientId, shaderId, Id, Type, "offset_frequency", OffsetFrequency);
     CSycles.shadernode_set_member_float(clientId, shaderId, Id, Type, "squash", Squash);
     CSycles.shadernode_set_member_int(clientId, shaderId, Id, Type, "squash_frequency", SquashFrequency);
 }
Beispiel #5
0
 /// <summary>
 /// Create a new session using the given SessionParameters and Scene
 /// </summary>
 /// <param name="sessionParams">Previously created SessionParameters to create Session with</param>
 /// <param name="scene">Previously created Scene to create Session with</param>
 public Session(Client client, SessionParameters sessionParams, Scene scene)
 {
     Client        = client;
     SessionParams = sessionParams;
     Scene         = scene;
     Id            = CSycles.session_create(Client.Id, sessionParams.Id, scene.Id);
 }
Beispiel #6
0
 internal override void SetEnums(uint clientId, uint shaderId)
 {
     //CSycles.shadernode_set_attribute_string(clientId, shaderId, Id, "color_space", ColorSpace.ToString());
     //CSycles.shadernode_set_attribute_string(clientId, shaderId, Id, "projection", Projection.ToString());
     CSycles.shadernode_set_enum(clientId, shaderId, Id, Type, "color_space", ColorSpace.ToString());
     CSycles.shadernode_set_enum(clientId, shaderId, Id, Type, "projection", Projection.ToString());
 }
Beispiel #7
0
 internal void SetSockets(uint clientId, uint shaderId)
 {
     /* set node attributes */
     if (inputs != null)
     {
         foreach (var socket in inputs.Sockets)
         {
             var float_socket = socket as FloatSocket;
             if (float_socket != null)
             {
                 CSycles.shadernode_set_attribute_float(clientId, shaderId, Id, float_socket.Name, float_socket.Value);
             }
             var int_socket = socket as IntSocket;
             if (int_socket != null)
             {
                 CSycles.shadernode_set_attribute_int(clientId, shaderId, Id, int_socket.Name, int_socket.Value);
             }
             var string_socket = socket as StringSocket;
             if (string_socket != null)
             {
                 CSycles.shadernode_set_attribute_string(clientId, shaderId, Id, socket.Name, string_socket.Value);
             }
             var float4_socket = socket as Float4Socket;
             if (float4_socket != null)
             {
                 CSycles.shadernode_set_attribute_vec(clientId, shaderId, Id, float4_socket.Name, float4_socket.Value);
             }
         }
     }
 }
Beispiel #8
0
 /// <summary>
 /// Create a new light.
 ///
 /// This constructor creates a Cycles light right away. The Id
 /// is from Cycles
 /// </summary>
 /// <param name="client"></param>
 /// <param name="scene"></param>
 /// <param name="lightShader"></param>
 public Light(Client client, Scene scene, Shader lightShader)
 {
     Client = client;
     Scene  = scene;
     Shader = lightShader;
     Id     = CSycles.create_light(Client.Id, Scene.Id, scene.GetShaderSceneId(lightShader));
 }
Beispiel #9
0
        /// <summary>
        /// Create a new mesh for the given client using shader as the default shader
        /// </summary>
        /// <param name="client"></param>
        /// <param name="shader"></param>
        public Mesh(Client client, Shader shader)
        {
            Client = client;
            Shader = shader;

            Id = CSycles.scene_add_mesh(Client.Id, Client.Scene.Id, Client.Scene.GetShaderSceneId(shader));
        }
        internal override void SetEnums(uint clientId, uint shaderId)
        {
            var projection = GetProjectionString(Projection);
            var colspace   = ColorSpace == TextureColorSpace.Color ? "Color" : "None";

            CSycles.shadernode_set_enum(clientId, shaderId, Id, Type, "projection", projection);
            CSycles.shadernode_set_enum(clientId, shaderId, Id, Type, "color_space", colspace);
        }
Beispiel #11
0
 /// <summary>
 /// Cancel the currently in progress render
 /// </summary>
 /// <param name="cancelMessage"></param>
 public void Cancel(string cancelMessage)
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.session_cancel(Client.Id, Id, cancelMessage);
 }
Beispiel #12
0
 /// <summary>
 /// Wait for the rendering session to complete
 /// </summary>
 public void Wait()
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.session_wait(Client.Id, Id);
 }
Beispiel #13
0
        internal override void SetDirectMembers(uint clientId, uint shaderId)
        {
            CSycles.shadernode_set_member_float(clientId, shaderId, Id, Type, "turbidity", Turbidity);
            CSycles.shadernode_set_member_float(clientId, shaderId, Id, Type, "ground_albedo", GroundAlbedo);
            var sd = SunDirection;

            CSycles.shadernode_set_member_vec(clientId, shaderId, Id, Type, "sun_direction", sd.x, sd.y, sd.z);
        }
Beispiel #14
0
 public void DrawNogl(int width, int height)
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.session_draw_nogl(Client.Id, Id, width, height, Scene.Device.IsGpu);
 }
Beispiel #15
0
 public void RhinoDraw(int width, int height)
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.session_rhinodraw(Client.Id, Id, width, height);
 }
Beispiel #16
0
 /// <summary>
 /// Set sample count for session to render. This can be used to increase the sample
 /// count for an interactive render session.
 /// </summary>
 /// <param name="samples"></param>
 public void SetSamples(int samples)
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.session_set_samples(Client.Id, Id, samples);
 }
Beispiel #17
0
        public void OneTimeSetUp()
        {
            var path     = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? "";
            var userpath = Path.Combine(path, "userpath");

            CSycles.path_init(path, userpath);
            CSycles.initialise();
        }
Beispiel #18
0
 /// <summary>
 /// Pause or un-pause a render session.
 /// </summary>
 /// <param name="pause"></param>
 public void SetPause(bool pause)
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.session_set_pause(Client.Id, Id, pause);
 }
Beispiel #19
0
        internal override void SetDirectMembers(uint clientId, uint shaderId)
        {
            var tfm = Transform;

            CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, Type, "tfm_x", tfm.x.x, tfm.x.y, tfm.x.z, tfm.x.w, 0);
            CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, Type, "tfm_y", tfm.y.x, tfm.y.y, tfm.y.z, tfm.y.w, 1);
            CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, Type, "tfm_z", tfm.z.x, tfm.z.y, tfm.z.z, tfm.z.w, 2);
            CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, Type, "tfm_w", tfm.w.x, tfm.w.y, tfm.w.z, tfm.w.w, 3);
        }
Beispiel #20
0
 /// <summary>
 /// Reset a Session
 /// </summary>
 /// <param name="width">Width of the resolution to reset with</param>
 /// <param name="height">Height of the resolutin to reset with</param>
 /// <param name="samples">The amount of samples to reset with</param>
 public void Reset(uint width, uint height, uint samples)
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.progress_reset(Client.Id, Id);
     CSycles.session_reset(Client.Id, Id, width, height, samples);
 }
Beispiel #21
0
 /// <summary>
 /// Start the rendering session. After this one should Wait() for
 /// the session to complete.
 /// </summary>
 public void Start()
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.progress_reset(Client.Id, Id);
     CSycles.session_start(Client.Id, Id);
 }
Beispiel #22
0
 /// <summary>
 /// Destroy the session and all related.
 /// </summary>
 public void Destroy()
 {
     if (Destroyed)
     {
         return;
     }
     CSycles.session_destroy(Client.Id, Id);
     Destroyed = true;
 }
Beispiel #23
0
 /// <summary>
 /// Retrieve the buffer information for this Session
 /// </summary>
 /// <param name="bufferSize">Contains the buffer size in floats</param>
 /// <param name="bufferStride">Contains the stride to use in the buffer</param>
 public void BufferInfo(out uint bufferSize, out uint bufferStride)
 {
     if (Destroyed)
     {
         bufferSize   = 0;
         bufferStride = 0;
         return;
     }
     CSycles.session_get_buffer_info(Client.Id, Id, out bufferSize, out bufferStride);
 }
Beispiel #24
0
        protected override LoadReturnCode OnLoad(ref string errorMessage)
        {
            RhinoApp.Initialized += RhinoApp_Initialized;
            RcCore.It.InitializeResourceManager();

            // code got moved to separate DLL so use that to register from.
            var rccoreass = typeof(RcCore).Assembly;

            RenderContent.RegisterContent(rccoreass, Id);

            RenderContent.ContentFieldChanged += RenderContentOnContentFieldChanged;

            var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";

            RcCore.It.PluginPath = path;
            var kernelPath = Path.Combine(path, "RhinoCycles");

            RcCore.It.KernelPath = kernelPath;
            var appPath = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);

            RcCore.It.AppPath            = appPath;
            kernelPath                   = RcCore.GetRelativePath(appPath, kernelPath);
            RcCore.It.KernelPathRelative = kernelPath;

            var dataPath = SettingsDirectory;
            var userPath = Path.Combine(dataPath, "..", "data");

            userPath = RcCore.GetCanonicalizedPath(userPath);

            RcCore.It.DataUserPath = userPath;

            CSycles.path_init(RcCore.It.KernelPath, RcCore.It.DataUserPath);

            if (RhinoApp.RunningOnVMWare())
            {
                CSycles.debug_set_opencl_device_type(0);
            }
            else
            {
                CSycles.debug_set_opencl_device_type(RcCore.It.EngineSettings.OpenClDeviceType);
            }
            CSycles.debug_set_opencl_kernel(RcCore.It.EngineSettings.OpenClKernelType);
            CSycles.debug_set_opencl_single_program(RcCore.It.EngineSettings.OpenClSingleProgram);
            CSycles.debug_set_cpu_kernel(RcCore.It.EngineSettings.CPUSplitKernel);

            RcCore.It.Initialised = false;
            AsyncInitialise();

            m_page = new ViewportPropertiesPage();

            RhinoView.SetActive += RhinoView_SetActive;

            return(LoadReturnCode.Success);
        }
Beispiel #25
0
 /// <summary>
 /// Initialise Cycles if necessary.
 /// </summary>
 public void InitialiseCSycles()
 {
     lock (InitialiseLock)
     {
         if (!RcCore.It.Initialised)
         {
             CSycles.initialise();
             RcCore.It.Initialised = true;
             RcCore.It.TriggerInitialisationCompleted(this);
         }
     }
 }
Beispiel #26
0
        /// <summary>
        /// Copy the ccycles API level session buffer through CSycles into this Session.
        ///
        /// TODO: implement a way to do partial updates
        /// </summary>
        /// <returns></returns>
        public float[] CopyBuffer()
        {
            if (Destroyed)
            {
                return(null);
            }
            uint bufStride = 0;
            uint bufSize   = 0;

            BufferInfo(out bufSize, out bufStride);

            return(CSycles.session_copy_buffer(Client.Id, Id, bufSize));
        }
Beispiel #27
0
        internal override void SetDirectMembers(uint clientId, uint shaderId)
        {
            var val   = Interpolate;
            var color = new float4();

            CSycles.shadernode_set_member_bool(clientId, shaderId, Id, Type, "interpolate", val);

            for (var i = 0; i < RampTableSize; i++)
            {
                ColorBand.evaluate((float)i / (float)(RampTableSize - 1), color);
                CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, Type, "ramp", color.x, color.y, color.z, color.w, i);
            }
        }
Beispiel #28
0
        public void DisplayUpdateHandler(uint sessionId, int sample)
        {
            if (Session.IsPaused())
            {
                return;
            }
            // after first 10 frames have been rendered only update every third.
            if (sample > 10 && sample < (RcCore.It.EngineSettings.Samples - 2) && sample % 3 != 0)
            {
                return;
            }
            if (CancelRender)
            {
                return;
            }
            if (State != State.Rendering)
            {
                return;
            }
            // copy display buffer data into ccycles pixel buffer
            Session.DrawNogl(RenderDimension.Width, RenderDimension.Height);
            using (var channel = RenderWindow.OpenChannel(RenderWindow.StandardChannels.RGBA))
            {
                if (CancelRender)
                {
                    return;
                }
                if (channel != null)
                {
                    if (CancelRender)
                    {
                        return;
                    }
                    var pixelbuffer = new PixelBuffer(CSycles.session_get_buffer(Client.Id, sessionId));
                    var size        = RenderDimension;
                    var rect        = new Rectangle(0, 0, RenderDimension.Width, RenderDimension.Height);
                    if (CancelRender)
                    {
                        return;
                    }
                    channel.SetValues(rect, size, pixelbuffer);
                }
            }
            SaveRenderedBuffer(sample);

            if (CancelRender || sample >= maxSamples)
            {
                Session.Cancel("done");
            }
        }
        internal override void SetDirectMembers(uint clientId, uint shaderId)
        {
            CSycles.shadernode_set_member_bool(clientId, shaderId, Id, ShaderNodeType.TextureCoordinate, "use_transform", UseTransform);

            if (UseTransform)
            {
                var obt = ObjectTransform;

                CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, ShaderNodeType.TextureCoordinate, "object_transform_x", obt.x.x, obt.x.y, obt.x.z, obt.x.w, 0);
                CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, ShaderNodeType.TextureCoordinate, "object_transform_y", obt.y.x, obt.y.y, obt.y.z, obt.y.w, 1);
                CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, ShaderNodeType.TextureCoordinate, "object_transform_z", obt.z.x, obt.z.y, obt.z.z, obt.z.w, 2);
                CSycles.shadernode_set_member_vec4_at_index(clientId, shaderId, Id, ShaderNodeType.TextureCoordinate, "object_transform_w", obt.w.x, obt.w.y, obt.w.z, obt.w.w, 3);
            }
        }
        /// <summary>
        /// Construct a render engine for preview rendering
        /// </summary>
        /// <param name="createPreviewEventArgs"></param>
        /// <param name="pluginId">Id of the plugin for which the render engine is created</param>
        public PreviewRenderEngine(CreatePreviewEventArgs createPreviewEventArgs, Guid pluginId) : base(pluginId, createPreviewEventArgs, false)
        {
            Client = new Client();
            State  = State.Rendering;

            #region create callbacks for Cycles
            m_update_callback             = UpdateCallback;
            m_update_render_tile_callback = PreviewRendererUpdateRenderTileCallback;
            m_write_render_tile_callback  = PreviewRendererWriteRenderTileCallback;
            m_test_cancel_callback        = TestCancel;

            CSycles.log_to_stdout(false);
            #endregion
        }