Exemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            // Initialize GL settings
            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.CullFace = true;
            GLState.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha);
            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, -1);
            camera.SetAsCurrent(); // Use this camera for rendering

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

            // Load shaders
            ShaderManager.LoadCollection("Shaders/collection.xml");
            var shader = ShaderManager.Get("cubemappedmodel");

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

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

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

            // set up rendering queue
            renderQueue = new RenderQueue();
            renderQueue.AllowInstancing = false;
        }
Exemplo n.º 2
0
        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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected override void OnLoad(EventArgs e)
        {
            // Initialize GL settings
            GPUCapabilities.Initialize();
            GLState.DepthTest = true;
            GLState.AlphaBleding = false;
            GLState.CullFace = true;
            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, 100);
            camera.Target = new Vector3(0, 0, -1);
            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/concreteslabs.tex", true);
            texture.Quality.Mipmaps = true;
            texture.Quality.TextureWrapMode = TextureWrapMode.Repeat;

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

            // Create base material
            materials = new MaterialManager();
            materials.Insert("uniformexamplematerial.mat", new Material()
            {
                UniformData = new List<IUniformData>()
                {
                    new UniformDataFloat() {
                        Name = "time",
                        Data = 0.0f
                    },
                    new UniformDataVector2() {
                        Name = "toffset",
                        Data = Vector2.Zero
                    },
                    new UniformDataVector4() {
                        Name = "color",
                        Data = Vector4.One
                    }
                }
            });

            // Construct a model from shader, texture and mesh, with default material
            model = new Model()
            {
                Shader = ShaderManager.Get("uniformexamplemodel"),
                Texture = texture,
                Mesh = mesh,
                Material = materials.Get("uniformexamplematerial.mat")
            };

            model2 = new Model()
            {
                Shader = ShaderManager.Get("uniformexamplemodel"),
                Texture = texture,
                Mesh = mesh,
                Material = materials.Get("uniformexamplematerial.mat")
            };

            model3 = new Model()
            {
                Shader = ShaderManager.Get("uniformexamplemodel"),
                Texture = texture,
                Mesh = mesh,
                Material = materials.Get("uniformexamplematerial.mat")
            };

            model.Transform.Position += new Vector3(-1, 0.5f, 0);
            model2.Transform.Position += new Vector3(1, 0.5f, 0);
            model3.Transform.Position += new Vector3(0, -0.75f, 0);

            model.Transform.Rotation *= new Quaternion(0, (float)Math.PI, 0);

            // set up rendering queue
            renderQueue = new RenderQueue();
            renderQueue.AllowInstancing = false;
        }
Exemplo n.º 4
0
        void LoadMeshStuff()
        {
            // 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(); // Use this camera for rendering

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

            // Load shaders
            var modelshader = ShaderManager.Get("transparentmodel");

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

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

            var lucyMaterial = new Material();

            lucyMaterial.Textures.Add("textureSampler", texture);
            lucyMaterial.ShaderProgram = modelshader;

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

            // set up rendering queue
            renderQueue = new RenderQueue()
            {
                AllowInstancing = false
            };
        }
Exemplo n.º 5
0
        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;
        }