Exemplo n.º 1
0
        public static PBRNode Create(IBufferSource model, vec3 size, string position, string texCoord, string normal)
        {
            //var model = new NormalMappingModel();
            var vs    = new VertexShader(vertexCode);
            var fs    = new FragmentShader(fragmentCode);
            var array = new ShaderArray(vs, fs);
            var map   = new AttributeMap();

            map.Add("aPos", position);
            map.Add("aTexCoords", texCoord);
            map.Add("aNormal", normal);
            //map.Add("inTangent", tangent);
            var builder = new RenderMethodBuilder(array, map);
            var node    = new PBRNode(model, builder);

            node.ModelSize = size;
            node.Initialize();

            return(node);
        }
Exemplo 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);
        }