CreateCyclesShader() private method

Create a CyclesShader based on given Material m
private CreateCyclesShader ( Rhino.Render.RenderMaterial rm, float gamma ) : CyclesShader
rm Rhino.Render.RenderMaterial Material to convert to CyclesShader
gamma float gamma to use for this shader
return CyclesShader
        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);
        }