protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { base.LoadContent(GraphicInfo, factory, contentManager); ///Create the water ///Water is just a Shader that Creates a Water like texture and binds it to a model { IModelo sm = new SimpleModel(factory, "Model\\block"); Matrix trans = Matrix.CreateTranslation(new Vector3(0, 50, 0)); Plane plano = Plane.Transform(new Plane(0, 1, 0, 0), trans); ///The water is VERRRRY big, the reflection and refraction will looks like blocked, its normal, increasy the size of the reflection/refrection buffer to correct this (bigger cost) ///We normally use the SAME transformation applyied to the plane (if not stranges affects can happen) IPhysicObject pi = new BoxObject(new Vector3(0, 50, 0), 1, 1, 1, 5, new Vector3(3000, 0.1f, 3000), trans, MaterialDescription.DefaultBepuMaterial()); pi.isMotionLess = true; ///Water shader, will refract and reflect according to the plano passed in the parameter ///Using default Parameters, there are lots of things that can be changed. See WaterCompleteShader DeferredWaterCompleteShader shader = new DeferredWaterCompleteShader(800, 600, plano, 0.1f); shader.SpecularIntensity = 0.01f; shader.SpecularPower = 50; IMaterial mat = new DeferredMaterial(shader); IObject obj4 = new IObject(mat, sm, pi); this.World.AddObject(obj4); } ExtractXmlModelLoader ext = new ExtractXmlModelLoader("Content//ModelInfos//", "Model//", "Textures//"); this.AttachCleanUpAble(ext); ModelLoaderData data = ext.Load(factory, GraphicInfo, "shadow"); WorldLoader wl = new WorldLoader(); wl.OnCreateIObject += new CreateIObject(wl_OnCreateIObject); wl.OnCreateILight += new CreateILight(wl_OnCreateILight); wl.LoadWorld(factory, GraphicInfo, World, data); #region NormalLight DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White); DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White); DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White); DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White); DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White); DirectionalLightPE ld6 = new DirectionalLightPE(Vector3.Up, Color.White); float li = 0.5f; ld1.LightIntensity = li; ld2.LightIntensity = li; ld3.LightIntensity = li; ld4.LightIntensity = li; ld5.LightIntensity = li; ld6.LightIntensity = li; this.World.AddLight(ld1); this.World.AddLight(ld2); this.World.AddLight(ld3); this.World.AddLight(ld4); this.World.AddLight(ld5); this.World.AddLight(ld6); #endregion this.World.CameraManager.AddCamera(new CameraFirstPerson(true, GraphicInfo)); SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//grassCube"); CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc); lt = new LightThrowBepu(this.World, factory,100); }
/// <summary> /// Load content for the screen. /// </summary> /// <param name="GraphicInfo"></param> /// <param name="factory"></param> /// <param name="contentManager"></param> protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, IContentManager contentManager) { ///must be called before all base.LoadContent(GraphicInfo, factory, contentManager); { IModelo sm = new SimpleModel(factory, "Model\\block"); Matrix trans = Matrix.CreateTranslation(new Vector3(100, 50, 0)); Plane plano = Plane.Transform(new Plane(0, 1, 0, 0), trans); IPhysicObject pi = new BoxObject(Vector3.Zero, 1, 1, 1, 5, new Vector3(1300, 0.1f, 1300), trans, MaterialDescription.DefaultBepuMaterial()); pi.isMotionLess = true; ///Water shader, will refract and reflect according to the plano passed in the parameter ///Using default Parameters, there are lots of things that can be changed. See WaterCompleteShader DeferredWaterCompleteShader shader = new DeferredWaterCompleteShader(800, 600, plano, 0); shader.SpecularIntensity = 0.01f; shader.SpecularPower = 50; IMaterial mat = new DeferredMaterial(shader); IObject obj4 = new IObject(mat, sm, pi); this.World.AddObject(obj4); } { ///Need to load the height, the normal texture and the difuse texture SimpleModel sm = new SimpleModel(factory, "..\\Content\\Model\\block", "..\\Content\\Textures\\color_map"); sm.SetTexture("Textures\\normal_map", TextureType.BUMP); sm.SetCubeTexture(factory.GetTextureCube("Textures//cubemap"), TextureType.ENVIRONMENT); BoxObject pi = new BoxObject(new Vector3(200, 110, 0), 1, 1, 1, 5, new Vector3(100, 100, 100), Matrix.Identity, MaterialDescription.DefaultBepuMaterial()); DeferredEnvironmentCustomShader DeferredEnvironmentCustomShader = new DeferredEnvironmentCustomShader(false, true, false); DeferredEnvironmentCustomShader.SpecularIntensity = 0.2f; DeferredEnvironmentCustomShader.SpecularPower = 30; DeferredEnvironmentCustomShader.ShaderId = ShaderUtils.CreateSpecificBitField(true); IMaterial mat = new DeferredMaterial(DeferredEnvironmentCustomShader); IObject obj3 = new IObject(mat, sm, pi); this.World.AddObject(obj3); } { List<Vector3> poss = new List<Vector3>(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { float x, y; x = i * 100; y = j * 100; poss.Add(new Vector3(x, 100, y)); } } StaticBilboardModel bm = new StaticBilboardModel(factory, "Bilbs", "..\\Content\\Textures\\tree", poss); DeferredCilindricGPUBilboardShader cb = new DeferredCilindricGPUBilboardShader(); DeferredMaterial matfor = new DeferredMaterial(cb); GhostObject go = new GhostObject(); IObject obj2 = new IObject(matfor, bm, go); this.World.AddObject(obj2); } ///Add some directional lights to completely iluminate the world #region Lights DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White); DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White); DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White); DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White); DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White); float li = 0.4f; ld1.LightIntensity = li; ld2.LightIntensity = li; ld3.LightIntensity = li; ld4.LightIntensity = li; ld5.LightIntensity = li; this.World.AddLight(ld1); this.World.AddLight(ld2); this.World.AddLight(ld3); this.World.AddLight(ld4); this.World.AddLight(ld5); #endregion ///Add a AA post effect this.RenderTechnic.AddPostEffect(new AntiAliasingPostEffect()); ///add a camera this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }
public static IObject[] CreateOBJ(IWorld world, GraphicFactory factory, GraphicInfo ginfo, ObjectInformation[] mi) { IModelo model = new CustomModel(factory, mi); MaterialDescription material; if (mi[0].staticfriction == -1 || mi[0].dinamicfriction == -1 || mi[0].ellasticity == -1) { material = MaterialDescription.DefaultBepuMaterial(); } else { material = new MaterialDescription(mi[0].staticfriction, mi[0].dinamicfriction, mi[0].ellasticity); } IPhysicObject po; bool massflag = false; if (mi[0].mass == 0) { massflag = true; mi[0].mass = 0.5f; } BatchInformation binf = model.GetBatchInformation(0)[0]; BoundingBox bb; switch (mi[0].collisionType) { case "Ghost": po = new GhostObject(mi[0].position,Matrix.CreateFromQuaternion(mi[0].rotation), mi[0].scale); break; case "Cylinder": binf.ModelLocalTransformation = Matrix.Identity; bb = ModelBuilderHelper.CreateBoundingBoxFromModel(binf); Vector3 len = bb.Max - bb.Min; po = new CylinderObject(mi[0].position, len.Y, len.X / 2,Vector3.Up ,mi[0].mass, Matrix.CreateFromQuaternion(mi[0].rotation), material); break; case "Sphere": binf.ModelLocalTransformation = Matrix.Identity; po = new SphereObject(mi[0].position, model.GetModelRadius(), mi[0].mass, mi[0].scale.X, material); po.Rotation = Matrix.CreateFromQuaternion(mi[0].rotation); break; case "Box": bb = ModelBuilderHelper.CreateBoundingBoxFromModel(binf); len = bb.Max - bb.Min; po = new BoxObject(mi[0].position, len.X, len.Y, len.Z, mi[0].mass, mi[0].scale, Matrix.CreateFromQuaternion(mi[0].rotation), material); break; case "Water": po = new GhostObject(mi[0].position, Matrix.CreateFromQuaternion(mi[0].rotation), mi[0].scale); break; case "TriangleMesh": default: po = new TriangleMeshObject(model, Vector3.Zero, Matrix.Identity, new Vector3(1), material); break; } po.isMotionLess = massflag; IShader shader = null; #if !REACH && !WINDOWS_PHONE if (mi[0].HasTexture(TextureType.ENVIRONMENT)) { shader = new DeferredEMReflectiveShader(); (shader as DeferredEMReflectiveShader).TextureCube = mi[0].textureInformation.getCubeTexture(TextureType.ENVIRONMENT); } else if (mi[0].collisionType != null && mi[0].collisionType.Contains("Water")) { Vector3 position = (Vector3)(mi[0].extra["position"]); var width = (mi[0].extra["width"]); var height = (mi[0].extra["length"]); shader = new DeferredWaterCompleteShader((int)width,(int)height, new Plane(position.X, position.Y, position.Z, 1),10.0f); } else { shader = new DeferredCustomShader(mi[0].HasTexture(TextureType.GLOW), mi[0].HasTexture(TextureType.BUMP), mi[0].HasTexture(TextureType.SPECULAR), mi[0].HasTexture(TextureType.PARALAX)); } DeferredMaterial dm = new DeferredMaterial(shader); #else shader = new ForwardXNABasicShader(); ForwardMaterial dm = new ForwardMaterial(shader); #endif IObject ob = new IObject(dm, model, po); ob.Name = mi[0].modelName; return new IObject[] { ob }; }