public RhinoGltfMetallicRoughnessConverter(System.Drawing.Bitmap bmp, Rhino.RhinoDoc doc, string name)
        {
            System.Drawing.Bitmap metalnessBitmap = new System.Drawing.Bitmap(bmp.Width, bmp.Height);

            System.Drawing.Bitmap roughnessBitmap = new System.Drawing.Bitmap(bmp.Width, bmp.Height);

            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {
                    System.Drawing.Color color = bmp.GetPixel(i, j);

                    byte metalness = color.B;
                    byte roughness = color.G;

                    metalnessBitmap.SetPixel(i, j, System.Drawing.Color.FromArgb(metalness, metalness, metalness));
                    roughnessBitmap.SetPixel(i, j, System.Drawing.Color.FromArgb(roughness, roughness, roughness));
                }
            }

            MetallicTexture = Rhino.Render.RenderTexture.NewBitmapTexture(metalnessBitmap, doc);

            MetallicTexture.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program);

            MetallicTexture.Name = name + "-Metallic";

            MetallicTexture.EndChange();

            RoughnessTexture = Rhino.Render.RenderTexture.NewBitmapTexture(roughnessBitmap, doc);

            RoughnessTexture.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program);

            RoughnessTexture.Name = name + "-Roughness";

            RoughnessTexture.EndChange();
        }
Exemplo n.º 2
0
        public bool Use()
        {
            var prg = GetShaderProgram();

            if (lastUserProgram == null)
            {
                lastUserProgram = ShaderProgram.Current;
            }
            ShaderProgram.SwitchResult res = prg.Use();

            //prg.SetUniform("MaterialIndex", BufferOffset);
            prg.SetUniform("IsTessellatedTerrain", Type == MaterialType.TessellatedTerrain);
            prg.SetUniform("TessellationMultiplier", TessellationMultiplier);
            prg.SetUniform("InvertUVy", InvertUVy);
            prg.SetUniform("IsBillboard", IsBillboard);

            prg.SetUniform("SpecularColor", SpecularColor);
            prg.SetUniform("DiffuseColor", DiffuseColor);
            prg.SetUniform("ParallaxHeightMultiplier", ParallaxHeightMultiplier);
            prg.SetUniform("Roughness", Roughness);
            prg.SetUniform("Alpha", Alpha);

            prg.SetUniform("NormalTexEnabled", NormalsTexture != null);
            prg.SetUniform("BumpTexEnabled", BumpTexture != null);
            prg.SetUniform("AlphaTexEnabled", AlphaTexture != null);
            prg.SetUniform("RoughnessTexEnabled", RoughnessTexture != null);
            prg.SetUniform("DiffuseTexEnabled", DiffuseTexture != null);
            prg.SetUniform("SpecularTexEnabled", SpecularTexture != null);

            if (NormalsTexture != null)
            {
                NormalsTexture.Use(prg.getConstInt("normalsTexBind"));
            }

            if (BumpTexture != null)
            {
                BumpTexture.Use(prg.getConstInt("bumpTexBind"));
            }

            if (AlphaTexture != null)
            {
                AlphaTexture.Use(prg.getConstInt("alphaTexBind"));
            }

            if (RoughnessTexture != null)
            {
                RoughnessTexture.Use(prg.getConstInt("roughnessTexBind"));
            }

            if (DiffuseTexture != null)
            {
                DiffuseTexture.Use(prg.getConstInt("diffuseTexBind"));
            }

            if (SpecularTexture != null)
            {
                SpecularTexture.Use(prg.getConstInt("specularTexBind"));
            }

            return(true);
        }