Пример #1
0
 /// <summary>
 /// Constructor for our changequeue implementation
 /// </summary>
 /// <param name="pluginId">Id of the plugin instantiating the render change queue</param>
 /// <param name="engine">Reference to our render engine</param>
 /// <param name="createPreviewEventArgs">preview event arguments</param>
 internal ChangeDatabase(Guid pluginId, RenderEngine engine, CreatePreviewEventArgs createPreviewEventArgs)
     : base(pluginId, createPreviewEventArgs)
 {
     _renderEngine = engine;
     _modalRenderer = true;
     _objectShaderDatabase = new ObjectShaderDatabase(_objectDatabase);
     _shaderConverter = new ShaderConverter(engine.Settings);
 }
        public bool GetShader(Shader sh, bool finalize)
        {
            blendit = new ccl.ShaderNodes.MixClosureNode($"blendit{Serial}");
            sh.AddNode(blendit);

            LinearWorkflow linearWorkflow = new LinearWorkflow();

            linearWorkflow.PostProcessGamma   = Gamma;
            linearWorkflow.PreProcessGamma    = Gamma;
            linearWorkflow.PostProcessGammaOn = Gamma != 1.0f;
            linearWorkflow.PreProcessColors   = linearWorkflow.PreProcessTextures = linearWorkflow.PostProcessGammaOn;

            RhinoCyclesCore.Converters.ShaderConverter sconv = new RhinoCyclesCore.Converters.ShaderConverter();
            CyclesShader    mat1sh      = null;
            CyclesShader    mat2sh      = null;
            ICyclesMaterial crm1        = null;
            ICyclesMaterial crm2        = null;
            ClosureSocket   crm1closure = null;
            ClosureSocket   crm2closure = null;

            if (Mat1Rm != null)
            {
                if (Mat1Rm is ICyclesMaterial)
                {
                    crm1       = Mat1Rm as ICyclesMaterial;
                    crm1.Gamma = Gamma;
                    crm1.GetShader(sh, false);
                    crm1closure = crm1.GetClosureSocket(sh);
                }
                else
                {
                    mat1sh       = sconv.CreateCyclesShader(Mat1Rm, linearWorkflow, Mat1Rm.RenderHashExclude(CrcRenderHashFlags.ExcludeLinearWorkflow, "", linearWorkflow), BitmapConverter, null);
                    mat1sh.Gamma = Gamma;
                    BitmapConverter.ReloadTextures(mat1sh);
                }
            }
            if (Mat2Rm != null)
            {
                if (Mat2Rm is ICyclesMaterial)
                {
                    crm2       = Mat2Rm as ICyclesMaterial;
                    crm2.Gamma = Gamma;
                    crm2.GetShader(sh, false);
                    crm2closure = crm2.GetClosureSocket(sh);
                }
                else
                {
                    mat2sh       = sconv.CreateCyclesShader(Mat2Rm, linearWorkflow, Mat2Rm.RenderHashExclude(CrcRenderHashFlags.ExcludeLinearWorkflow, "", linearWorkflow), BitmapConverter, null);
                    mat2sh.Gamma = Gamma;
                    BitmapConverter.ReloadTextures(mat2sh);
                }
            }

            RhinoCyclesCore.Shaders.RhinoFullNxt fnMat1 = null;
            ClosureSocket fnMat1Closure = null;

            if (mat1sh != null)
            {
                fnMat1        = new RhinoCyclesCore.Shaders.RhinoFullNxt(null, mat1sh, sh, false);
                fnMat1Closure = fnMat1.GetClosureSocket();
            }

            RhinoCyclesCore.Shaders.RhinoFullNxt fnMat2 = null;
            ClosureSocket fnMat2Closure = null;

            if (mat2sh != null)
            {
                fnMat2        = new RhinoCyclesCore.Shaders.RhinoFullNxt(null, mat2sh, sh, false);
                fnMat2Closure = fnMat2.GetClosureSocket();
            }

            ccl.ShaderNodes.TextureCoordinateNode texco = new ccl.ShaderNodes.TextureCoordinateNode($"texcos{Serial}");
            sh.AddNode(texco);

            ccl.ShaderNodes.DiffuseBsdfNode diffuse1Bsdf = new ccl.ShaderNodes.DiffuseBsdfNode();
            diffuse1Bsdf.ins.Color.Value = Mat1;
            ccl.ShaderNodes.DiffuseBsdfNode diffuse2Bsdf = new ccl.ShaderNodes.DiffuseBsdfNode();
            diffuse2Bsdf.ins.Color.Value = Mat2;
            sh.AddNode(diffuse1Bsdf);
            sh.AddNode(diffuse2Bsdf);

            blendit.ins.Fac.Value = Blend.Amount;

            ccl.ShaderNodes.ValueNode blendValue = new ccl.ShaderNodes.ValueNode("blendValue");
            sh.AddNode(blendValue);
            blendValue.Value = Blend.Amount;

            GraphForSlot(sh, blendValue.outs.Value, Blend.On, Blend.Amount, BlendTex, blendit.ins.Fac.ToList(), texco, true);

            var sock1 = fnMat1Closure ?? crm1closure ?? diffuse1Bsdf.outs.BSDF;

            sock1.Connect(blendit.ins.Closure1);
            var sock2 = fnMat2Closure ?? crm2closure ?? diffuse2Bsdf.outs.BSDF;

            sock2.Connect(blendit.ins.Closure2);

            blendit.outs.Closure.Connect(sh.Output.ins.Surface);

            if (finalize)
            {
                sh.FinalizeGraph();
            }
            return(true);
        }
Пример #3
0
 /// <summary>
 /// Constructor for our changequeue implementation
 /// </summary>
 /// <param name="pluginId">Id of the plugin instantiating the render change queue</param>
 /// <param name="engine">Reference to our render engine</param>
 /// <param name="doc">Document runtime serial number</param>
 /// <param name="view">Reference to the RhinoView for which this queue is created.</param>
 /// <param name="modal">Set to true if rendering modal</param>
 internal ChangeDatabase(Guid pluginId, RenderEngine engine, uint doc, ViewInfo view, bool modal)
     : base(pluginId, doc, view, !modal)
 {
     _renderEngine = engine;
     _objectShaderDatabase = new ObjectShaderDatabase(_objectDatabase);
     _shaderConverter = new ShaderConverter(engine.Settings);
     _modalRenderer = modal;
 }