예제 #1
0
        public override void Init()
        {
            base.Init();

            scene = new Scene
            {
                new DebugRenderer(),

                new Node("Camera", new vec3(0.0f, 0.0f, -20))
                {
                    new Camera
                    {
                        Fov     = glm.radians(60),
                        FarClip = 1000.0f
                    },
                },
            };

            {
                Shader shader = Resources.Load <Shader>("Shaders/Pbr.shader");

                AssimpModelReader importer = new AssimpModelReader();
                importer.SetVertexComponents(VertexComponent.Position, VertexComponent.Normal);
                var model = importer.Load("Models/sphere.gltf");

                const int GRID_DIM = 7;

                for (int y = 0; y < GRID_DIM; y++)
                {
                    for (int x = 0; x < GRID_DIM; x++)
                    {
                        vec3 pos         = new vec3((x - (GRID_DIM - 1) / 2.0f) * 2.5f, (y - (GRID_DIM - 1) / 2.0f) * 2.5f, 0.0f);
                        var  node        = scene.CreateChild("Model", pos);
                        var  staticModel = node.AddComponent <StaticModel>();
                        staticModel.SetModel(model);

                        var mat = new Material(shader);
                        materialDatas[materialIndex].Apply(mat);

                        mat.SetShaderParameter("metallic", glm.clamp(x / (float)(GRID_DIM - 1), 0.1f, 1.0f));
                        mat.SetShaderParameter("roughness", glm.clamp(y / (float)(GRID_DIM - 1), 0.05f, 1.0f));

                        staticModel.SetMaterial(mat);
                        materials.Add(mat);
                    }
                }
            }

            camera = scene.GetComponent <Camera>(true);
            MainView.Attach(camera, scene);
        }
예제 #2
0
        public override void Init()
        {
            scene = new Scene()
            {
                new Octree {
                },
                new DebugRenderer {
                },

                new Environment
                {
                    SunlightDir = glm.normalize(new vec3(-1.0f, -1.0f, 0.0f))
                },

                new Node("Camera", new vec3(0, 2, -10), glm.radians(10, 0, 0))
                {
                    new Camera
                    {
                        NearClip = 0.5f,
                        FarClip  = 100,
                    },
                },
            };

            camera = scene.GetComponent <Camera>(true);

            var importer = new AssimpModelReader(VertexComponent.Position, VertexComponent.Texcoord);

            {
                var node        = scene.CreateChild("Sky");
                var staticModel = node.AddComponent <StaticModel>();
                importer.scale = 5;
                var model = importer.Load("models/vegetation/skysphere.dae");
                staticModel.SetModel(model);
                staticModel.SetBoundingBox(new BoundingBox(-10000, 10000));
                var mat = new Material("shaders/SkySphere.shader");
                staticModel.SetMaterial(mat);
            }

            {
                var node        = scene.CreateChild("Plane");
                var staticModel = node.AddComponent <StaticModel>();
                var model       = GeometryUtil.CreatePlaneModel(100, 100, 32, 32, true);
                staticModel.SetModel(model);
                var mat = Resources.Load <Material>("materials/Grass.material");
                mat.SetTexture("NormalMap", Texture.Blue);
                mat.SetTexture("SpecMap", Texture.Black);
                staticModel.SetMaterial(mat);
            }

            {
                var node        = scene.CreateChild("vegetation");
                var staticModel = node.AddComponent <StaticModelGroup>();

                importer.scale = 0.0025f;
                importer.SetVertexComponents(VertexComponent.Position, VertexComponent.Normal, VertexComponent.Texcoord, VertexComponent.Color);

                var model = importer.Load("models/vegetation/plants.dae");
                staticModel.SetModel(model);

                var mat = new Material("shaders/Vegetation.shader");

                mat.Shader.Main.VertexLayout = new VertexLayout(importer.vertexComponents,
                                                                new[] { VertexComponent.Float3, VertexComponent.Float3, VertexComponent.Float1, VertexComponent.Int1 });

                Texture tex = Resources.Load <Texture>("models/vegetation/textures/texturearray_plants_bc3_unorm.ktx");
                mat.SetTexture("DiffMap", tex);
                staticModel.SetMaterial(mat);
            }

            MainView.Attach(camera, scene, renderer);
        }