Ejemplo n.º 1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(-0.2f, 0, 1) * 14;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera);
            var rootNode = new GroupNode();

            this.scene.RootNode = rootNode;
            {
                var sphere   = new Sphere2();//(1, 40, 80);
                var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                sphere.DumpObjFile(filename, "sphere2");
                var          parser = new ObjVNFParser(false, true);
                ObjVNFResult result = parser.Parse(filename);
                if (result.Error != null)
                {
                    Console.WriteLine("Error: {0}", result.Error);
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    // render rows*column number of spheres with varying metallic/roughness values scaled by rows and columns respectively
                    for (int row = 0; row < nrRows; ++row)
                    {
                        for (int col = 0; col < nrColumns; ++col)
                        {
                            var node = PBRNode.Create(model, model.GetSize(),
                                                      ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal, ObjVNF.strTangent);
                            node.Metallic = (float)row / (float)nrRows;
                            // we clamp the roughness to 0.025 - 1.0 as perfectly smooth surfaces (roughness of 0.0) tend to look a bit off
                            // on direct lighting.
                            node.Roughness     = glm.clamp((float)col / (float)nrColumns, 0.05f, 1.0f);
                            node.WorldPosition = new vec3(
                                (col - (nrColumns / 2)) * spacing,
                                (row - (nrRows / 2)) * spacing,
                                0.0f);
                            rootNode.Children.Add(node);
                        }
                    }
                }
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 2
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(-0.2f, 0, 1) * 14;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera);
            var rootNode = new GroupNode();

            this.scene.RootNode = rootNode;

            Texture albedoMap    = GetTexture(@"Textures\albedo.png", 0);
            Texture normalMap    = GetTexture(@"Textures\normal.png", 1);
            Texture metallicMap  = GetTexture(@"Textures\metallic.png", 2);
            Texture roughnessMap = GetTexture(@"Textures\roughness.png", 3);
            Texture aoMap        = GetTexture(@"Textures\ao.png", 4);

            {
                var sphere   = new Sphere2(); // Sphere(1, 40, 80);
                var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                sphere.DumpObjFile(filename, "sphere2");
                var          parser = new ObjVNFParser(false, true);
                ObjVNFResult result = parser.Parse(filename);
                if (result.Error != null)
                {
                    Console.WriteLine("Error: {0}", result.Error);
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    // render rows*column number of spheres with varying metallic/roughness values scaled by rows and columns respectively
                    for (int row = 0; row < nrRows; ++row)
                    {
                        for (int col = 0; col < nrColumns; ++col)
                        {
                            var node = PBRNode.Create(model, model.GetSize(),
                                                      ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal);
                            node.AlbedoMap     = albedoMap;
                            node.NormalMap     = normalMap;
                            node.MetallicMap   = metallicMap;
                            node.RoughnessMap  = roughnessMap;
                            node.AOMap         = aoMap;
                            node.WorldPosition = new vec3(
                                (col - (nrColumns / 2)) * spacing,
                                (row - (nrRows / 2)) * spacing,
                                0.0f);
                            rootNode.Children.Add(node);
                        }
                    }
                }
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 3
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(9.3968f, -0.7408f, 2.9288f);
            var center   = new vec3(-0.0710f, -2.2829f, 1.3023f);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera);
            var rootNode = new GroupNode();

            this.scene.RootNode = rootNode;

            Texture texBRDF = LoadBRDFTexture();

            texBRDF.TextureUnitIndex = 2;
            Texture prefilterMap = LoadPrefilterMap();

            prefilterMap.TextureUnitIndex = 1;
            Texture irradianceMap = LoadIrradianceMap();

            irradianceMap.TextureUnitIndex = 0;
            Texture envCubemap = LoadEnvCubeMap();
            Texture texHDR     = LoadHDRTexture("environment.hdr");

            {
                var node = CubemapNode.Create(envCubemap, texHDR);
                rootNode.Children.Add(node);
            }
            {
                var node = IrradianceNode.Create(irradianceMap, envCubemap);
                rootNode.Children.Add(node);
            }
            {
                var node = PrefilterNode.Create(prefilterMap, envCubemap);
                rootNode.Children.Add(node);
            }
            {
                var node = BRDFNode.Create(texBRDF);
                rootNode.Children.Add(node);
            }
            {
                var textureGroups = new string[] { "cerberus", "cerberus", "gold", "grass", "plastic", "rock", "rusted_iron", "wall", "wood" };
                var models        = new ObjVNF[textureGroups.Length];
                {
                    var          filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "cerberus.obj_");
                    var          parser   = new ObjVNFParser(false, false);
                    ObjVNFResult result   = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        MessageBox.Show(string.Format("Error: {0}", result.Error));
                        return;
                    }
                    ObjVNFMesh mesh = result.Mesh;
                    // scale it to 0.1 percent.
                    for (int i = 0; i < mesh.vertexes.Length; i++)
                    {
                        mesh.vertexes[i] = mesh.vertexes[i] / 10;
                    }
                    //// Dump texture coordinates' layout.
                    //{
                    //    vec2[] texCoords = mesh.texCoords;
                    //    int polygon = (mesh.faces[0] is ObjVNFTriangle) ? 3 : 4;
                    //    int index = 0;
                    //    var indices = new uint[polygon * mesh.faces.Length];
                    //    foreach (var face in mesh.faces) {
                    //        foreach (var vertexIndex in face.VertexIndexes()) {
                    //            indices[index++] = vertexIndex;
                    //        }
                    //    }
                    //    var bmp = TexCoordAnalyzer.DumpLines(texCoords, indices, 1024);
                    //    bmp.Save("cerberus.texCoords.png");
                    //}
                    var model = new ObjVNF(mesh);
                    models[0] = model;
                }
                {
                    var sphere   = new Sphere2();//(1, 40, 80);
                    var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                    sphere.DumpObjFile(filename, "sphere2");
                    var          parser = new ObjVNFParser(false, true);
                    ObjVNFResult result = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        MessageBox.Show(string.Format("Error: {0}", result.Error));
                        return;
                    }
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    for (int i = 1; i < textureGroups.Length; i++)
                    {
                        models[i] = model;
                    }
                }

                for (int i = 0; i < textureGroups.Length; i++)
                {
                    ObjVNF model = models[i];
                    string group = textureGroups[i];
                    var    node  = PBRNode.Create(model, model.GetSize(),
                                                  ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal);
                    node.IrradianceMap = irradianceMap;
                    node.PrefilterMap  = prefilterMap;
                    node.texBRDF       = texBRDF;
                    Texture albedo = GetTexture(string.Format(@"Textures\{0}\albedo.png", group), 3);
                    node.AlbedoMap = albedo;
                    Texture ao = GetTexture(string.Format(@"Textures\{0}\ao.png", group), 4);
                    node.AOMap = ao;
                    Texture metallic = GetTexture(string.Format(@"Textures\{0}\metallic.png", group), 5);
                    node.MetallicMap = metallic;
                    Texture normal = GetTexture(string.Format(@"Textures\{0}\normal.png", group), 6);
                    node.NormalMap = normal;
                    Texture roughness = GetTexture(string.Format(@"Textures\{0}\roughness.png", group), 7);
                    node.RoughnessMap = roughness;
                    if (i == 0)
                    {
                        node.WorldPosition = new vec3(0, -5, 0);
                    }
                    else
                    {
                        node.WorldPosition = new vec3(
                            0.0f,
                            0.0f,
                            ((textureGroups.Length / 2.0f) - i) * spacing);
                    }
                    rootNode.Children.Add(node);
                }
            }
            {
                var backgroundNode = BackgroundNode.Create(envCubemap);
                rootNode.Children.Add(backgroundNode);
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }