当前位置: 首页>>代码示例>>C#>>正文


C# Material.Copy方法代码示例

本文整理汇总了C#中Material.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# Material.Copy方法的具体用法?C# Material.Copy怎么用?C# Material.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Material的用法示例。


在下文中一共展示了Material.Copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnLoad

        protected override void OnLoad(EventArgs e)
        {
            PackageManager.BasePath = "../../Assets/";

            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.CullFace = true;
            GL.ClearColor(0.25f, 0.25f, 0.25f, 1.0f);

            ShaderManager.LoadCollection("Shaders/collection.xml");

            SceneManager.Initialize(500, 5, 20, Vector3.Zero);
            SceneManager.CullByObject = false;

            renderQueue = new RenderQueue();
            renderQueue.AllowInstancing = true;

            meshes = new MeshManager();

            camera = new Hatzap.Camera(this);
            camera.SetAsCurrent();
            camera.Position = new Vector3(0, 1, 1);
            camera.Target = new Vector3(-1, 0, 0);
            camera.Update(0);
            camera.Rotate(new Vector2(-(float)Math.PI / 2.5f, 0));

            var rand = new Hatzap.Utilities.Random();

            int n = 8;
            float sizeScale = 10.0f;

            // All objects will have the same material
            Material material = new Material();

            material.ShaderProgram = ShaderManager.Get("instancedmodel");

            // To disable instancing, use these:
            //material.ShaderProgram = ShaderManager.Get("simplemodel");
            //renderQueue.AllowInstancing = false;

            for (int x = -n; x <= n; x++)
            {
                for (int y = -n; y <= n; y++)
                {
                    for (int z = -n; z <= n; z++)
                    {
                        var instancedObject = new Model();

                        // Set shader, mesh and material (no texture)
                        instancedObject.Mesh = meshes.Get("Meshes/suzanne.mesh", true);
                        instancedObject.Material = material.Copy();

                        // Set transform
                        instancedObject.Transform.Position = new Vector3(
                            (x + (float)(rand.NextDouble() - 0.5)) * sizeScale,
                            (y + (float)(rand.NextDouble() - 0.5)) * sizeScale,
                            (z + (float)(rand.NextDouble() - 0.5)) * sizeScale);
                        instancedObject.Transform.Rotation = Quaternion.FromEulerAngles(
                            x * 360.0f / n / (float)Math.PI,
                            y * 360.0f / n / (float)Math.PI,
                            z * 360.0f / n / (float)Math.PI);

                        float color = 1f;
                        color = color - ((y + n) / (n * 2.0f));

                        instancedObject.Material.Add(new UniformDataVector4(){
                            Data = new Vector4(color, color, color, 1),
                            Name = "Color",
                        });

                        // Don't calculate matrices on every frame
                        instancedObject.Transform.Static = true;

                        // Insert model in the scene octree. (Because I'm lazy and didn't want
                        // to write code to update all these meshes in the queue by hand. Also
                        // culling is done by scene automatically.)
                        SceneManager.Insert(instancedObject);
                    }
                }
            }
        }
开发者ID:Lazzu,项目名称:Hatzap,代码行数:81,代码来源:InstancingExampleWindow.cs

示例2: OnLoad

        protected override void OnLoad(EventArgs e)
        {
            // Initialize GL settings
            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.CullFace = true;
            GLState.BlendFunc(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(0.25f, 0.25f, 0.25f, 1.0f);

            // Set up camera
            camera = new Camera(this);
            camera.Perspective(Width, Height, (float)Math.PI / 4, 1f, 1000);
            camera.Position = new Vector3(0, 20, 200);
            camera.Target = new Vector3(0, 0, 0);
            camera.SetAsCurrent();

            // Set up PackageManager
            PackageManager.BasePath = "../../Assets/";

            // Load shaders
            ShaderManager.LoadCollection("Shaders/collection.xml");

            // Load texture
            textures = new TextureManager();
            var texture = textures.Get("Textures/lucymetal.tex", true);
            texture.Quality.Mipmaps = true;

            var groundtexture = textures.Get("Textures/concreteslabs.tex", true);
            groundtexture.Quality.Mipmaps = true;
            groundtexture.Quality.TextureWrapMode = TextureWrapMode.Repeat;

            // Load up a mesh
            MeshManager meshManager = new MeshManager();
            var mesh = meshManager.Get("Meshes/lucy.mesh", true);
            var groundmesh = meshManager.Get("Meshes/plane.mesh", true);

            var modelMaterial = new Material()
                {
                    ShaderProgram = ShaderManager.Get("transparentmodel"),
                    Transparent = false,
                    UniformData = new List<IUniformData>()
                    {
                        new UniformDataVector4() {
                            Name = "color",
                            Data = new Vector4(1,1,1,0.75f),
                        },
                        new UniformDataFloat() {
                            Name = "specularIntensity",
                            Data = 0.5f,
                        }
                    }
                };

            modelMaterial.Textures.Add("textureSampler", texture);

            // Construct a model from shader, texture and mesh, with default material
            model = new Model()
            {
                Mesh = mesh,
                Material = modelMaterial
            };

            var modelMaterial2 = modelMaterial.Copy();
            modelMaterial2.Transparent = true;

            // Construct a model from shader, texture and mesh, with default material
            model2 = new Model()
            {
                Mesh = mesh,
                Material = modelMaterial2
            };

            var groundMaterial = modelMaterial.Copy();
            groundMaterial.Textures["textureSampler"] = groundtexture;

            // Construct a model from shader, texture and mesh, with default material
            groundplane = new Model()
            {
                Mesh = groundmesh,
                Material = groundMaterial
            };

            model.Transform.Position += new Vector3(1, 0, 0);
            model2.Transform.Position += new Vector3(-1, 0, 0);
            groundplane.Transform.Position += new Vector3(0, -1, 0);

            // set up rendering queue
            renderQueue = new RenderQueue();
            renderQueue.AllowInstancing = false;
        }
开发者ID:Lazzu,项目名称:Hatzap,代码行数:90,代码来源:TransparencyExampleWindow.cs


注:本文中的Material.Copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。