示例#1
0
        public override void Init()
        {
            Environment.AmbientLight.Color.Set(0.2f, 0.15f, 0.1f, 1.0f);
            Environment.DirectionalLight.Direction.Set(1.9f, 0.35f, 1.9f).NormalizeStore();
            Environment.DirectionalLight.Color.Set(0.5f, 0.3f, 0.1f, 1.0f);
            ((PerspectiveCamera)Camera).FieldOfView = 75;

            ShadowMappingComponent smc;
            RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment));
            smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;

            Geometry landscape = ((Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\landscape\\map.obj")).GetChildGeom(0);
            rootNode.AddChild(landscape);

            landscape.SetShader(typeof(Terrain.TerrainShader));
            Material terrainMaterial = new Material();

            Texture grass = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass.jpg");
            Texture grass_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass_NRM.jpg");
            Texture dirt = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt.jpg");
            Texture dirt_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt_NRM.jpg");

            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE0, grass);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_SCALE_0, 16);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL0, grass_nrm);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE_SLOPE, dirt);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL_SLOPE, dirt_nrm);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_SCALE_SLOPE, 16);
            terrainMaterial.SetValue(Material.MATERIAL_CASTSHADOWS, false);
            terrainMaterial.SetValue(Material.SHININESS, 0.15f);
            terrainMaterial.SetValue(Material.ROUGHNESS, 0.8f);

            landscape.Material = terrainMaterial;

            landscape.SetLocalScale(new Math.Vector3f(3f, 2f, 3f));

            PhysicsWorld.AddObject(landscape, 0.0f);

            AddComponent(new SkydomeComponent());

              //  Rendering.NormalMapRenderer nmr;
              //  RenderManager.AddComponent(nmr = new Rendering.NormalMapRenderer(Environment, Camera));
             //   RenderManager.PostProcessor.PostFilters.Add(new Rendering.PostProcess.Filters.SSAOFilter(nmr));

            GrassPopulator grassPop;
            rootNode.AddController(grassPop = new GrassPopulator(PhysicsWorld, cam));
            grassPop.GenPatches(12, 3, 128);

            RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter());
        }
示例#2
0
        public override void Init()
        {
            ShadowMappingComponent smc;
            RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment, new int[] { 2048, 1024 }));
            smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;

              //  Node floor = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\scene.apx");
              //  rootNode.AddChild(floor);
              //  PhysicsWorld.AddObject(floor, 0);
            Geometry cube = new Geometry(MeshFactory.CreateCube(new Vector3f(-15, -0.5f, -15f), new Vector3f(15f, 0.5f, 15f)));
            rootNode.AddChild(cube);
            PhysicsWorld.AddObject(cube, 0);

            Node n = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\monkeyhq.obj");
            n.SetLocalTranslation(new Vector3f(0, 50, 0));
            rootNode.AddChild(n);
            //PhysicsWorld.AddObject(n, 5, Scene.Physics.PhysicsWorld.PhysicsShape.Box);
            PhysicsWorld.AddCharacter((DefaultCamera)cam, InputManager, n, 1);
        }
 public ShadowPostFilter(ShadowMappingComponent parent)
     : base(SHADER_CODE)
 {
     this.parent = parent;
     noiseMap = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\noise.png");
 }
示例#4
0
        public override void Init()
        {
            Environment.AmbientLight.Color.Set(0.1f, 0.1f, 0.1f, 1.0f);
            Environment.FogColor.Set(0.2f, 0.3f, 0.45f, 1.0f);
            Environment.DirectionalLight.Direction.Set(1f, 1, 1f).NormalizeStore();
            Environment.DirectionalLight.Color.Set(1.0f, 1.0f, 1.0f, 1.0f);
            ((PerspectiveCamera)Camera).FieldOfView = 75;
            Camera.Far = 330;

            ShadowMappingComponent smc;
            RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment, new int[] {2048,1024}));
            smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;

            /*Rendering.Light.PointLight pl = new Rendering.Light.PointLight();
            pl.Color = new Color4f(1f, 0.0f, 0.0f, 1.0f);
            pl.Position = new Vector3f(0.0f, 4.0f, 0.0f);
            Environment.PointLights.Add(pl);*/

              /*  Rendering.Light.PointLight pl2 = new Rendering.Light.PointLight();
            pl2.Color = new Color4f(0.9f, 0.3f, 0.2f, 1.0f);
            pl2.Position = new Vector3f(0.0f, 3.0f, 7.0f);
            Environment.PointLights.Add(pl2);*/

            Geometry skyboxGeom = new Geometry(MeshFactory.CreateCube(new Vector3f(-10), new Vector3f(10)));
            skyboxGeom.Material.SetValue(Material.MATERIAL_FACETOCULL, 1);
            skyboxGeom.Material.SetValue(Material.MATERIAL_CASTSHADOWS, false);
               // rootNode.AddChild(skyboxGeom);

            GameObject grid = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\grid\\grid.obj");
            rootNode.AddChild(grid);

            Node loadedApx = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\mitsuba.obj");
               // loadedApx.SetLocalTranslation(new Math.Vector3f(0f, 0, 0));

            Cubemap skybox = Cubemap.LoadCubemap(new string[] { AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_right.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_left.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_top.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_top.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_front.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_back.jpg" });

               // Texture nrm = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\normal_metal.jpg");

            Random rand = new Random();
            for (int x = 0; x < 5; x++)
            {
                for (int z = 0; z < 5; z++)
                {
                    Node thing = (Node)loadedApx.Clone();
                    thing.SetLocalTranslation(new Vector3f((x * 3) - 6, 5, (z * 3) - 6));
                    thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_ENV, skybox);
                    thing.GetChildGeom(0).Material.SetValue(Material.SHININESS, 0.5f);
                    thing.GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, 0.3f);
                    thing.GetChildGeom(0).UpdateShaderProperties();

                    thing.GetChildGeom(1).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(1f, 0f, 0f, 1.0f));
                    thing.GetChildGeom(1).Material.SetValue(Material.TEXTURE_ENV, skybox);
                    thing.GetChildGeom(1).Material.SetValue(Material.SHININESS, (x+1) / 5.0f);
                    thing.GetChildGeom(1).Material.SetValue(Material.ROUGHNESS, (z+1) / 5.0f);
                    thing.GetChildGeom(1).UpdateShaderProperties();
               //     thing.GetChildGeom(1).Material.SetValue(Material.TEXTURE_NORMAL, nrm);
                    rootNode.AddChild(thing);
                }
            }
               /* Node thing = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\pbr\\sibenik.obj");
            for (int i = 0; i < thing.Children.Count; i++)
            {
                thing.GetChildGeom(i).Material.SetValue(Material.TEXTURE_ENV, skybox);
                thing.GetChildGeom(i).Material.SetValue(Material.SHININESS, 0.2f);
                thing.GetChildGeom(i).Material.SetValue(Material.ROUGHNESS, 0.2f);
                thing.GetChildGeom(i).UpdateShaderProperties();
            }
            rootNode.AddChild(thing);*/

            RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter());
        }
示例#5
0
        public override void Init()
        {
            Environment.AmbientLight.Color.Set(0.4f, 0.25f, 0.1f, 1.0f);
            Environment.FogColor.Set(0.2f, 0.3f, 0.45f, 1.0f);
            Environment.DirectionalLight.Direction.Set(0.6f, 1, 0.6f).NormalizeStore();
            Environment.DirectionalLight.Color.Set(1.0f, 0.85f, 0.65f, 1.0f);
            ((PerspectiveCamera)Camera).FieldOfView = 75;
            Camera.Far = 330;

            ShadowMappingComponent smc;
            RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment, new int[] { 2048, 1024 }));
            smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;

            RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter());

            const float curb_scale_y = 0.4f;

            road = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road.jpg");
            roadnrm = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_nrm.jpg");
            roadCorner = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_corner.jpg");
            roadCornernrm = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_corner_nrm.jpg");
            curbModel = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb.obj");
            curbCorner = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb_corner.obj");
            curbCorner.SetLocalScale(new Vector3f(1, curb_scale_y, 1));

            Random rand = new Random();

            int xAmt = rand.Next(2, 7), zAmt = rand.Next(2, 7), scaleX = rand.Next(10, 30), scaleZ = rand.Next(10, 30);

            int offset = 3;

            AddRoadCorner(new Line(new Vector3f(0, 0, -2), new Vector3f(0, 0, 0)));

            for (int x = 0; x <= xAmt; x++)
            {
                for (int i = 0; i < zAmt; i++)
                {
                    AddRoad(new Line(new Vector3f(x * scaleX, 0, i * scaleZ), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2)));
                    AddRoadCorner(new Line(new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ)));

                    if (x == 0)
                    {
                        // long bar
                        Node curb2 = (Node)curbModel.Clone();
                        tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - 1);
                        tmpVec.y = HeightRoad(tmpVec);
                        curb2.SetLocalTranslation(tmpVec);
                        curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180));
                        curb2.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ));
                        curbNode.AddChild(curb2);

                    }
                    else if (x == (xAmt - 1))
                    {
                        Node curb2 = (Node)curbModel.Clone();
                        tmpVec.Set((x + 1) * scaleX + 1, 0, (i) * scaleZ - 1);
                        tmpVec.y = HeightRoad(tmpVec);
                        curb2.SetLocalTranslation(tmpVec);
                        curb2.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ));
                        curbNode.AddChild(curb2);
                    }

                    Node curb0 = (Node)curbModel.Clone();
                    tmpVec.Set(x * scaleX + 1, 0, i * scaleZ + 1);
                    tmpVec.y = HeightRoad(tmpVec);
                    curb0.SetLocalTranslation(tmpVec);
                    curb0.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ - offset - 1));
                    curbNode.AddChild(curb0);

                    Node curb1 = (Node)curbModel.Clone();
                    tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - offset);
                    tmpVec.y = HeightRoad(tmpVec);
                    curb1.SetLocalTranslation(tmpVec);
                    curb1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180));
                    curb1.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ - offset - 1));
                    curbNode.AddChild(curb1);

                    if (x != 0)
                    {
                        Node curbCorner1 = (Node)curbCorner.Clone();
                        tmpVec.Set((x) * scaleX - 2, 0, (i + 1) * scaleZ - offset + 1);
                        tmpVec.y = HeightRoad(tmpVec);
                        curbCorner1.SetLocalTranslation(tmpVec);
                        curbCorner1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90));
                        curbNode.AddChild(curbCorner1);
                    }

                    if (x != xAmt)
                    {
                        Node curbCorner0 = (Node)curbCorner.Clone();
                        tmpVec.Set(x * scaleX + 2, 0, i * scaleZ);
                        tmpVec.y = HeightRoad(tmpVec);
                        curbCorner0.SetLocalTranslation(tmpVec);
                        curbCorner0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 90));
                        curbNode.AddChild(curbCorner0);
                    }
                }
            }

            for (int z = 0; z <= zAmt; z++)
            {
                for (int i = 0; i < xAmt; i++)
                {
                    AddRoad(new Line(new Vector3f(i * scaleX + 1, 0, z * scaleZ - 1), new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ - 1)));
                    AddRoadCorner(new Line(new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ - 1), new Vector3f((i + 1) * scaleX + 1, 0, z * scaleZ - 1)));

                    // long pieces
                    if (z == 0)
                    {
                        // long bar
                        Node curb2 = (Node)curbModel.Clone();
                        tmpVec.Set(i * scaleX, 0, z * scaleZ - 2);
                        tmpVec.y = HeightRoad(tmpVec);
                        curb2.SetLocalTranslation(tmpVec);
                        curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90));
                        curb2.SetLocalScale(new Vector3f(scaleX, curb_scale_y, 1));
                        curbNode.AddChild(curb2);
                    }
                    else if (z == (zAmt - 1))
                    {
                        Node curb2 = (Node)curbModel.Clone();
                        tmpVec.Set((i + 1) * scaleX, 0, (z + 1) * scaleZ);
                        tmpVec.y = HeightRoad(tmpVec);
                        curb2.SetLocalTranslation(tmpVec);
                        curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90 + 180));
                        curb2.SetLocalScale(new Vector3f(scaleX, curb_scale_y, 1));
                        curbNode.AddChild(curb2);
                    }

                    Node curb0 = (Node)curbModel.Clone();
                    tmpVec.Set((i + 1) * scaleX - 2, 0, z * scaleZ);
                    tmpVec.y = HeightRoad(tmpVec);
                    curb0.SetLocalTranslation(tmpVec);
                    curb0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 90));
                    curb0.SetLocalScale(new Vector3f(scaleX - offset - 1, curb_scale_y, 1));
                    curbNode.AddChild(curb0);

                    Node curb1 = (Node)curbModel.Clone();
                    tmpVec.Set((i) * scaleX + offset - 1, 0, z * scaleZ - 2);
                    tmpVec.y = HeightRoad(tmpVec);
                    curb1.SetLocalTranslation(tmpVec);
                    curb1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90));
                    curb1.SetLocalScale(new Vector3f(scaleX - offset - 1, curb_scale_y, 1));
                    curbNode.AddChild(curb1);

                    if (z != zAmt)
                    {
                        Node curbCorner0 = (Node)curbCorner.Clone();
                        Vector3f curbVec1 = new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ + 1);
                        curbVec1.y = HeightRoad(curbVec1);
                        curbCorner0.SetLocalTranslation(curbVec1);
                        curbCorner0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180));
                        curbNode.AddChild(curbCorner0);
                    }
                    if (z != 0)
                    {
                        Node curbCorner1 = (Node)curbCorner.Clone();
                        Vector3f curbVec1 = new Vector3f((i) * scaleX + offset - 2, 0, z * scaleZ - 3);
                        curbVec1.y = HeightRoad(curbVec1);
                        curbCorner1.SetLocalTranslation(curbVec1);
                        curbCorner1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 360));
                        curbNode.AddChild(curbCorner1);
                    }
                }
            }

            Geometry roadMerged = new Geometry(MeshUtil.MergeMeshes(roadNode));
            Geometry curbMerged = new Geometry(MeshUtil.MergeMeshes(curbNode));

            rootNode.AddChild(curbMerged);

            roadMerged.Material.SetValue(Material.MATERIAL_CULLENABLED, false);
            roadMerged.Material.SetValue(Material.TEXTURE_DIFFUSE, road);
            roadMerged.Material.SetValue(Material.TEXTURE_NORMAL, roadnrm);
            roadMerged.Material.SetValue(Material.SHININESS, 0.3f);
            roadMerged.Material.SetValue(Material.ROUGHNESS, 0.3f);

            Geometry roadCornerMerged = new Geometry(MeshUtil.MergeMeshes(roadCornerNode));

            roadCornerMerged.Material.SetValue(Material.MATERIAL_CULLENABLED, false);
            roadCornerMerged.Material.SetValue(Material.TEXTURE_DIFFUSE, roadCorner);
            roadCornerMerged.Material.SetValue(Material.TEXTURE_NORMAL, roadCornernrm);
            roadCornerMerged.Material.SetValue(Material.SHININESS, 0.3f);
            roadCornerMerged.Material.SetValue(Material.ROUGHNESS, 0.3f);

            rootNode.AddChild(roadCornerMerged);
            rootNode.AddChild(roadMerged);

            /*

                        addroad(new line(new vector3f(0, 0, 0), new vector3f(0, 0, 10)));
                        AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(1, 0, 12)));
                        AddRoad(new Line(new Vector3f(1, 0, 12), new Vector3f(5, 0, 12)));*/

            /*

            for (int x = 0; x < 16; x ++)
            {
                    AddRoad(new Line(new Vector3f((float)System.Math.Sin(x)*13, 0, (float)System.Math.Cos(x) * 13), new Vector3f((float)System.Math.Sin(x+1) * 13, 0, (float)System.Math.Cos(x+1) * 13)));
            }
            */
            /*     AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(-3, 0, 11)));
                 AddRoad(new Line(new Vector3f(-3, 0, 11), new Vector3f(-4, 0, 12)));
                 AddRoad(new Line(new Vector3f(-4, 0, 12), new Vector3f(-5, 0, 13)));
                 AddRoad(new Line(new Vector3f(-5, 0, 13), new Vector3f(-6, 0, 14)));*/
            //    AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(10, 0, 10)));

            /*  for (int i = 0; i < 4; i++)
              {
                  Line myline = new Line(lastLine.To, lastLine.To.Add(new Vector3f(rand.Next(-15, 15),0, rand.Next(-15, 15))));
                  Geometry quad = new Geometry(QuadFromLine(myline));
                  quad.Material.SetValue(Material.MATERIAL_CULLENABLED, false);
                  quad.Material.SetValue(Material.TEXTURE_DIFFUSE, road);
                  quad.Material.SetValue(Material.SHININESS, 0.0f);
                  lastLine = myline;

                  rootNode.AddChild(quad);
              }
              */
        }
 public ShadowPostFilter(ShadowMappingComponent parent) : base(SHADER_CODE)
 {
     this.parent = parent;
     noiseMap    = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\noise.png");
 }
示例#7
0
        public override void Init()
        {
            Environment.AmbientLight.Color.Set(0.1f, 0.2f, 0.3f, 1.0f);
            Environment.FogColor.Set(0.1f, 0.2f, 0.3f, 1.0f);
            Environment.DirectionalLight.Direction.Set(0.3f, 1f,0.3f).NormalizeStore();
            Environment.DirectionalLight.Color.Set(1.0f, 0.7f, 0.4f, 1.0f);
            ((PerspectiveCamera)Camera).FieldOfView = 60;
            Camera.Far = 330;

            ShadowMappingComponent smc;
            RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment, new int[] {1024, 1024}));
            smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;

            /*Node house = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\house.obj");

            for (int i = 0; i < 1; i++)
            {
                GameObject house1 = house.Clone();
                rootNode.AddChild(house1);
                house1.SetLocalTranslation(new Vector3f(i * 7, -0.5f, 0));
            }*/

            /*
            tree = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\tree\\pine\\LoblollyPine.obj");
            tree.SetLocalScale(new Vector3f(0.35f));

            tree.GetChildGeom(1).Material.SetValue("tree_height", tree.GetLocalBoundingBox().Max.y);
            tree.GetChildGeom(1).SetShader(typeof(BarkShader));
            tree.GetChildGeom(1).DepthShader = ShaderManager.GetShader(typeof(BarkShader), new ShaderProperties().SetProperty("DEPTH", true));

            tree.GetChildGeom(2).Material.SetValue("tree_height", tree.GetLocalBoundingBox().Max.y);
            tree.GetChildGeom(2).Material.SetValue(Material.MATERIAL_BLENDMODE, 1);
            tree.GetChildGeom(2).Material.SetValue(Material.MATERIAL_CULLENABLED, false);
            tree.GetChildGeom(2).Material.SetValue(Material.MATERIAL_ALPHADISCARD, 0.7f);
            tree.GetChildGeom(2).Material.Bucket = Rendering.RenderManager.Bucket.Transparent;
            tree.GetChildGeom(2).SetShader(typeof(LeafShader));
            tree.GetChildGeom(2).DepthShader = ShaderManager.GetShader(typeof(LeafShader), new ShaderProperties().SetProperty("DEPTH", true));

            rootNode.AddChild(tree);*/

                        // Test an Apex Engine 3D model, with a material created in the material editor

                        // Test an OBJ model, with normal mapping
                        GameObject loadedObj = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\house.obj");
                      //  rootNode.AddChild(loadedObj);
                      //  PhysicsWorld.AddObject(loadedObj, 0.0f);

                        // rootNode.AddChild(new Geometry(Rendering.Util.MeshFactory.CreateCube(new Vector3f(-1,-1,-1), new Vector3f(1,1,1))));
                        //  loadedObj.SetLocalScale(new Math.Vector3f(2, 0.5f, 2f));
                        //  Rendering.Animation.AnimationController anim = (Rendering.Animation.AnimationController)loadedApx.GetController(typeof(Rendering.Animation.AnimationController));
                        //  anim.PlayAnimation(1);

                       /* AddComponent(new ApexEngine.Terrain.SimplexTerrain.SimplexTerrainComponent(PhysicsWorld));
                        //AddComponent(new ApexEngine.Terrain.ModelTerrain.ModelTerrainComponent(AssetManager.GetAppPath() + "\\models\\terrain", "terrain", "obj"));

                        Geometry quadGeom = new Geometry(Rendering.Util.MeshFactory.CreateCube(new Vector3f(-15f, 0.4f, -15f), new Vector3f(15f, 0.5f, 15f)));
                       // quadGeom.SetLocalTranslation(new Vector3f(0, -8, 0));
                       // rootNode.AddChild(quadGeom);
                       // PhysicsWorld.AddObject(quadGeom, 0.0f);
            */
                       /* Rendering.Light.PointLight pl = new Rendering.Light.PointLight();
                        pl.Color = new Color4f(2f, 1f, 0f, 1.0f);
                        pl.Position = new Vector3f(0.0f, 0.3f,0.0f);
                       Environment.PointLights.Add(pl);*/

                    //    Rendering.Light.PointLight pl2 = new Rendering.Light.PointLight();
                     //   pl2.Color = new Color4f(0.0f, 0.3f, 0.1f, 1.0f);
                      //  pl2.Position = new Vector3f(0.0f, 1.0f, 2.0f);
                      //    Environment.PointLights.Add(pl2);

                        Node loadedApx = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\sphere16.obj");//"\\models\\mitsuba.obj");
            loadedApx.SetLocalTranslation(new Math.Vector3f(0f, 0.0f, 0));

            Cubemap skybox = Cubemap.LoadCubemap(new string[] { AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_right.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_left.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_top.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_top.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_front.jpg",
                                                                 AssetManager.GetAppPath() + "\\textures\\lostvalley\\lostvalley_back.jpg" });

            /*
            for (int x = 0; x < 5; x++)
            {
                for (int z = 0; z < 5; z++)
                {
                    Node thing = (Node)loadedApx.Clone();
                    thing.SetLocalTranslation(new Vector3f(x * 4, 0, z * 4));
                    thing.GetChildGeom(0).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(0.5f, 0.5f, 0.5f, 1.0f));
                    thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_ENV, skybox);
                    thing.GetChildGeom(0).Material.SetValue(Material.SHININESS, 0.6f);
                    thing.GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, 0.2f);
                    thing.GetChildGeom(0).UpdateShaderProperties();

                    thing.GetChildGeom(1).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(0.901f, 0.808f, 0.502f, 1.0f));
                    thing.GetChildGeom(1).Material.SetValue(Material.TEXTURE_ENV, skybox);
                    thing.GetChildGeom(1).Material.SetValue(Material.SHININESS, (x + 1) / 5.0f);
                    thing.GetChildGeom(1).Material.SetValue(Material.ROUGHNESS, (z + 1) / 5.0f);
                    thing.GetChildGeom(1).UpdateShaderProperties();
                    //     thing.GetChildGeom(1).Material.SetValue(Material.TEXTURE_NORMAL, nrm);

                    rootNode.AddChild(thing);
                }
            }*/
            for (int x = 0; x < 10; x++)
            {
                    Node thing = (Node)loadedApx.Clone();
                    thing.SetLocalTranslation(new Vector3f(x * 3, 2, 0));
                    thing.GetChildGeom(0).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(1.0f, 0.0f, 0.0f, 1.0f));
                    thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_ENV, skybox);
                    thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_NORMAL, null);
                    thing.GetChildGeom(0).Material.SetValue(Material.SHININESS, (x + 1) / 10.0f);
                    thing.GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, (x + 1) / 10.0f);
                    thing.GetChildGeom(0).UpdateShaderProperties();
                    rootNode.AddChild(thing);
            }
            for (int x = 0; x < 10; x++)
            {
                Node thing = (Node)loadedApx.Clone();
                thing.SetLocalTranslation(new Vector3f(x * 3, 2, 3));
                thing.GetChildGeom(0).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(0.0f, 1.0f, 0.0f, 1.0f));
                thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_ENV, skybox);
                thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_NORMAL, null);
                thing.GetChildGeom(0).Material.SetValue(Material.SHININESS, (x + 1) / 10.0f);
                thing.GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, (x + 1) / 10.0f);
                thing.GetChildGeom(0).UpdateShaderProperties();
                rootNode.AddChild(thing);
            }
            for (int x = 0; x < 10; x++)
            {
                Node thing = (Node)loadedApx.Clone();
                thing.SetLocalTranslation(new Vector3f(x * 3, 2, 6));
                thing.GetChildGeom(0).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(0.0f, 0.0f, 1.0f, 1.0f));
                thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_ENV, skybox);
                thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_NORMAL, null);
                thing.GetChildGeom(0).Material.SetValue(Material.SHININESS, (x + 1) / 10.0f);
                thing.GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, (x + 1) / 10.0f);
                thing.GetChildGeom(0).UpdateShaderProperties();
                rootNode.AddChild(thing);
            }
            for (int x = 0; x < 10; x++)
            {
                Node thing = (Node)loadedApx.Clone();
                thing.SetLocalTranslation(new Vector3f(x * 3, 2, 9));
                thing.GetChildGeom(0).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(1.0f, 1.0f, 1.0f, 1.0f));
                thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_ENV, skybox);
                thing.GetChildGeom(0).Material.SetValue(Material.TEXTURE_NORMAL, null);
                thing.GetChildGeom(0).Material.SetValue(Material.SHININESS, (x + 1) / 10.0f);
                thing.GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, (x + 1) / 10.0f);
                thing.GetChildGeom(0).UpdateShaderProperties();
                rootNode.AddChild(thing);
            }

            /* Node terrainModel = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\landscape\\landscape.obj");
             Geometry terrainGeom = terrainModel.GetChildGeom(0);
             terrainGeom.SetShader(typeof(Terrain.TerrainShader));
             Material terrainMaterial = new Material();

             Texture grass = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass.jpg");
             Texture grass_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass_NRM.jpg");
             Texture dirt = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt.jpg");
             Texture dirt_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt_NRM.jpg");
             terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE0, grass);
             terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL0, grass_nrm);
             terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE_SLOPE, dirt);
             terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL_SLOPE, dirt_nrm);
             terrainMaterial.SetValue(Material.MATERIAL_CASTSHADOWS, false);
             terrainMaterial.SetValue(Material.SHININESS, 0.15f);
             terrainMaterial.SetValue(Material.ROUGHNESS, 0.1f);

             terrainGeom.Material = terrainMaterial;

             terrainModel.SetLocalScale(new Vector3f(1, 0.5f, 1));
             rootNode.AddChild(terrainModel);

             PhysicsWorld.AddObject(terrainModel, 0f);
             */

            terrain = new ApexEngine.Terrain.SimplexTerrain.SimplexTerrainComponent(PhysicsWorld);
            terrain.BiomesEnabled = true;
            terrain.ChunkAdded += new Terrain.TerrainComponent.ChunkAddedHandler(OnChunkAdd);
            terrain.ChunkRemoved += new Terrain.TerrainComponent.ChunkRemovedHandler(OnChunkRemove);

            AddComponent(terrain);

            AddComponent(new SkydomeComponent());

            //  tex = (Texture2D)AssetManager.Load(AssetManager.GetAppPath() + "\\textures\\apex3d.png");
            // Sprite sprite = new Sprite();
            // rootNode.AddChild(sprite);

            /*  ShadowMappingComponent smc;
              RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment));
              smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;
              */

            //        Rendering.NormalMapRenderer nmr;
            //        RenderManager.AddComponent(nmr = new Rendering.NormalMapRenderer(Environment, Camera));
            //        RenderManager.PostProcessor.PostFilters.Add(new Rendering.PostProcess.Filters.SSAOFilter(nmr));

            RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter());

               /* Node n = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\monkeyhq.obj");
            n.SetLocalTranslation(new Vector3f(0, 100, 0));
            n.GetChildGeom(0).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(0.0f, 0.0f, 0.0f, 1.0f));
            n.GetChildGeom(0).Material.SetValue(Material.SHININESS, 1.0f);
            n.GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, 0.3f);
            rootNode.AddChild(n);
            PhysicsWorld.AddObject(n, 250, Scene.Physics.PhysicsWorld.PhysicsShape.Box);*/
            //   PhysicsWorld.AddCharacter((DefaultCamera)cam, InputManager, n, 1);

            /*Rendering.NormalMapRenderer nmr;
            RenderManager.AddComponent(nmr = new Rendering.NormalMapRenderer(Environment, Camera));
            RenderManager.PostProcessor.PostFilters.Add(new Rendering.PostProcess.Filters.SSAOFilter(nmr));*/

            /*
            Geometry waterGeom = new Geometry(MeshFactory.CreateQuad());
            waterGeom.SetLocalScale(new Math.Vector3f(10));
            waterGeom.SetLocalRotation(new Math.Quaternion().SetFromAxis(Vector3f.UNIT_X, 90));
            waterGeom.SetShader(typeof(WaterShader));
            waterGeom.Material.SetValue(Material.TEXTURE_DIFFUSE, Texture.LoadTexture(AssetManager.GetAppPath() + "\\textures\\water.jpg"));
            waterGeom.Material.SetValue(Material.TEXTURE_NORMAL, Texture.LoadTexture(AssetManager.GetAppPath() + "\\textures\\water_NRM.jpg"));
            rootNode.AddChild(waterGeom);*/
            //   Console.WriteLine("\n\n" + ShaderUtil.FormatShaderProperties((string)ShaderTextLoader.GetInstance().Load(AssetManager.GetAppPath() + "\\shaders\\default.frag"), new ShaderProperties().SetProperty("NORMALS", true)));

            /*
            ServerGameComponent serv;
            this.AddComponent(serv = new ServerGameComponent(new ServerHandler((Message msg) => { })));
            serv.Connect(2222);*/

              //  Geometry quadGeom = new Geometry(MeshFactory.CreateQuad());
             //   quadGeom.AddController(new BillboardControl(cam));
             //   quadGeom.SetLocalTranslation(new Vector3f(5, 5, 5));
            //    rootNode.AddChild(quadGeom);
        }
        public override void Init()
        {
            ShadowMappingComponent smc;
            RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment));
            smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;
            axisArrows = new Geometry[3];
            Node axisNode = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\axis_arrows\\untitled.obj");
            axisArrows[0] = axisNode.GetChildGeom(0);
            axisArrows[1] = axisNode.GetChildGeom(1);
            axisArrows[2] = axisNode.GetChildGeom(2);

            foreach (Geometry g in axisArrows)
            {
                g.Material.SetValue(ApexEngine.Rendering.Material.MATERIAL_DEPTHTEST, false);
                //g.Material.SetValue(ApexEngine.Rendering.Material.MATERIAL_DEPTHMASK, false);
            }

            InputManager.AddMouseEvent(new ApexEngine.Input.MouseEvent(ApexEngine.Input.InputManager.MouseButton.Left, false, new Action(() =>
            {
                if (!holding)
                {
                    Ray ray = cam.GetCameraRay(InputManager.GetMouseX(), InputManager.GetMouseY());

                    Dictionary<Vector3f, GameObject> intersections = new Dictionary<Vector3f, GameObject>();
                    Vector3f closestIntersection = new Vector3f(float.MaxValue);
                    float minDistance = float.MaxValue;
                    List<GameObject> objectList = ApexEngine.Rendering.Util.RenderUtil.GatherObjects(rootNode);
                    foreach (GameObject g in objectList)
                    {
                        if (objectHolding == null || g != objectHolding)
                        {
                            if (g.HasController(typeof(ApexEngine.Scene.Physics.RigidBodyControl)))
                            {
                                Vector3f intersection = g.GetWorldBoundingBox().Intersect(ray);
                                if (intersection != null && !intersections.ContainsKey(intersection))
                                {
                                    intersections.Add(intersection, g);
                                }
                            }
                        }
                    }

                    if (intersections.Count == 0)
                        objectHolding = null;

                    foreach (Vector3f i in intersections.Keys)
                    {
                        float dist = i.Distance(Camera.Translation);
                        if (dist < minDistance)
                        {
                            minDistance = dist;
                            closestIntersection.Set(i);
                        }
                    }

                    GameObject hitObject = null;

                    if (intersections.TryGetValue(closestIntersection, out hitObject))
                    {
                        if (hitObject != null)
                        {
                            if (hitObject.HasController(typeof(ApexEngine.Scene.Physics.RigidBodyControl)))
                            {
                                // needs rigid body control or else the node is "locked"
                                // also we need this to test for intersection in the physics world
                                objectHolding = hitObject;
                                foreach (Geometry g in axisArrows)
                                {
                                    g.SetLocalTranslation((!centered ? objectHolding.GetLocalTranslation() : objectHolding.GetLocalTranslation().Add(objectHolding.GetLocalBoundingBox().Center.Subtract(new Vector3f(0f, objectHolding.GetLocalBoundingBox().Center.Y, 0f)))));
                                    g.UpdateTransform();
                                }
                            }
                            else
                            {
                                objectHolding = null;
                            }
                        }
                    }
                    holdTime = 0f;
                    holding = true;
                    /*

                    GameObject hitObject;
                    PhysicsWorld.Raycast(origin, direction, out hitObject);
                    objectHolding = hitObject;
                    holdTime = 0f;
                    holding = true;
                    if (hitObject != null)
                    {
                        foreach (Geometry g in axisArrows)
                        {
                            g.SetLocalTranslation((!centered ? objectHolding.GetLocalTranslation() : objectHolding.GetLocalTranslation().Add(objectHolding.GetLocalBoundingBox().Center.Subtract(new Vector3f(0f, objectHolding.GetLocalBoundingBox().Center.Y, 0f)))));
                            g.UpdateTransform();
                        }
                    }*/
                }
            })));
            InputManager.AddMouseEvent(new ApexEngine.Input.MouseEvent(ApexEngine.Input.InputManager.MouseButton.Left, true, new Action(() =>
            {
                holdTime = 0f;
                holding = false;
            })));
        }