public void CreateMaterial() { material = new MMaterial("TerrainMaterial"); MScene.MaterialRoot.Add(material); material.AddShader(TerrainShader); SetMaterial(material); }
void AddBackdrop() { Helper.CheckGLError(this, "TestPoint 3a"); MShader BackgroundShader = new MShader("BackgroundShader"); BackgroundShader.Load("default_v.glsl", "unlit_f.glsl", "Terrain\\eval.glsl", "Terrain\\control.glsl" ); BackgroundShader.Bind(); BackgroundShader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE); Helper.CheckGLError(this, "TestPoint 3b"); //SkyShader.SetInt("shadowMap", 2); MMaterial BGMat = new MMaterial("BackgroundMaterial"); BGMat.AddShader(BackgroundShader); Helper.CheckGLError(this, "TestPoint 4a"); MTexture BackgroundTexure = new MTexture("BackgroundT"); Helper.CheckGLError(this, "TestPoint 4b"); BackgroundTexure.LoadTextureData(MFileSystem.ProjectPath + "Assets\\Textures\\Planets\\8k_stars_milky_way.jpg"); BackgroundTexure.DoAssign = true; MaterialRoot.Add(BGMat); BGMat.SetDiffuseTexture(BackgroundTexure); backdrop = new MSky(); backdrop.AddMaterial(BGMat); UtilityRoot.Add(backdrop); }
void SetupMaterial() { MMaterial InstanceMat = new MMaterial("InstanceGrassMaterial"); MShader shader = new MShader("InstanceGrassShader"); //shader.LoadFromString(sVertexShader, sFragmentShader); shader.Load("instanced_v.glsl", "instanced_f.glsl", "", "" ); shader.Bind(); shader.SetFloat("Fade", 68); shader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE); shader.SetInt("material.specular", MShader.LOCATION_SPECULAR); shader.SetInt("material.multitex", MShader.LOCATION_MULTITEX); shader.SetInt("material.normalmap", MShader.LOCATION_NORMALMAP); shader.SetInt("material.shadowMap", MShader.LOCATION_SHADOWMAP); InstanceMat.AddShader(shader); MTexture GrassTex = Globals.TexturePool.GetTexture(TreeTexture); GrassTex._TextureWrapMode = TextureWrapMode.ClampToBorder; GrassTex.DoAssign = true; InstanceMat.SetDiffuseTexture(GrassTex); this.SetMaterial(InstanceMat); grass.SetMaterial(InstanceMat); MScene.MaterialRoot.Add(InstanceMat); }
public static MMaterial AddMaterial(string sName, MShader shader, MTexture tex) { MMaterial mat = new MMaterial(sName); mat.AddShader(shader); mat.SetDiffuseTexture(tex); MScene.MaterialRoot.Add(mat); return(mat); }
public void Bind(MMaterial mat, int index) { mat.shader.SetVec3("pointLights[" + index + "].position", MTransform.GetVector3(transform.Position - Globals.GlobalOffset)); mat.shader.SetVec3("pointLights[" + index + "].ambient", Ambient); mat.shader.SetVec3("pointLights[" + index + "].diffuse", Diffuse); mat.shader.SetVec3("pointLights[" + index + "].specular", Specular); mat.shader.SetFloat("pointLights[" + index + "].constant", 1.0f); mat.shader.SetFloat("pointLights[" + index + "].linear", 0.19f); mat.shader.SetFloat("pointLights[" + index + "].quadratic", 0.032f); }
public void SetupMaterial() { if (material == null) { material = new MMaterial("Material"); material.AddShader(Helper.GetGUIShader()); AddMaterial(material); material.SetDiffuseTexture(Globals.TexturePool.GetTexture("UI\\art\\grey-bg.jpg")); } }
public static MMaterial CreateMaterial(string sName) { MMaterial mat = FindMaterial(sName); if (mat != null) { Globals.Log(null, "WARNING: A material with the name " + sName + " already exists"); } mat = new MMaterial(sName); MScene.MaterialRoot.Add(mat); return(mat); }
public static MMaterial AddMaterial(MSceneObject parent, string sName) { MMaterial mat = FindMaterial(sName); if (mat == null) { Log("WARNING: Material " + sName + " not found"); return(null); } parent.AddMaterial(mat); return(mat); }
void SetupMaterial() { /* * MShader TreeShader = new MShader("TreeShader"); * TreeShader.Load("default_v.glsl", * "default_f.glsl", * "", * "" * ); * TreeShader.Bind(); * TreeShader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE); * TreeShader.SetInt("material.specular", MShader.LOCATION_SPECULAR); * TreeShader.SetInt("material.multitex", MShader.LOCATION_MULTITEX); * TreeShader.SetInt("material.normalmap", MShader.LOCATION_NORMALMAP); * TreeShader.SetInt("material.shadowMap", MShader.LOCATION_SHADOWMAP); * * MMaterial Avatar1Mat = new MMaterial("TREE01M"); * Avatar1Mat.AddShader(TreeShader); * Avatar1Mat.SetDiffuseTexture(Globals.TexturePool.GetTexture("Textures\\avatar01.jpg")); * MScene.MaterialRoot.Add(Avatar1Mat); */ MMaterial InstanceMat = new MMaterial("ForestMaterialInstanced"); MShader shader = (MShader)MScene.MaterialRoot.FindModuleByName("ForestShaderInstanced"); if (shader == null) { shader = new MShader("ForestShaderInstanced"); //shader.LoadFromString(sVertexShader, sFragmentShader); shader.Load("instanced_v.glsl", "instanced_f.glsl", "", "" ); shader.Bind(); shader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE); shader.SetInt("material.specular", MShader.LOCATION_SPECULAR); shader.SetInt("material.multitex", MShader.LOCATION_MULTITEX); shader.SetInt("material.normalmap", MShader.LOCATION_NORMALMAP); shader.SetInt("material.shadowMap", MShader.LOCATION_SHADOWMAP); } InstanceMat.AddShader(shader); InstanceMat.SetDiffuseTexture(Globals.TexturePool.GetTexture(TreeTexture)); this.SetMaterial(InstanceMat); tree.SetMaterial(InstanceMat); MScene.MaterialRoot.Add(InstanceMat); }
public static MModel GetMesh(string sFilename) { //AssimpContext importer = new AssimpContext(); //importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); if (Pool.ContainsKey(sFilename)) { return(Pool[sFilename]); } MModel model = new MModel(); MMaterial mat = (MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL); model.AddMaterial(mat); model.Load(sFilename); Pool.Add(sFilename, model); return(model); }
public override void Setup() { // MMaterial mt = new MMaterial("nullmat"); // AddMaterial(mt); Panel = MGUI.AddPanel(this, 0, 0, Width, Height, "Panel"); MMaterial m = new MMaterial("ButtonMat"); Panel.AddMaterial(m); m.AddShader(Helper.GetGUIShader()); m.SetDiffuseTexture(Globals.TexturePool.GetTexture(IconPath)); TextItem = MGUI.AddText(this, 0, 0, Width, Height, "ButtonText", "Hello"); TextItem.Text = Text; base.Setup(); this.material = null; }
void SetupMaterial() { MMaterial InstanceMat = new MMaterial("InstanceMaterial"); MShader shader = new MShader("InstanceShader"); //shader.LoadFromString(sVertexShader, sFragmentShader); shader.Load("instanced_v.glsl", "instanced_f.glsl", "", "" ); shader.Bind(); shader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE); shader.SetInt("material.specular", MShader.LOCATION_SPECULAR); shader.SetInt("material.multitex", MShader.LOCATION_MULTITEX); shader.SetInt("material.normalmap", MShader.LOCATION_NORMALMAP); shader.SetInt("material.shadowMap", MShader.LOCATION_SHADOWMAP); InstanceMat.AddShader(shader); InstanceMat.SetDiffuseTexture(Globals.TexturePool.GetTexture(MeshTexture)); this.SetMaterial(InstanceMat); material = InstanceMat; }
void CreateShaders() { MShader SkyShader = Helper.CreateShader("SkyShader"); SkyShader.Load("default_v.glsl", "sky_f.glsl", "Terrain\\eval.glsl", "Terrain\\control.glsl" ); SkyShader.Bind(); SkyShader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE); SkyShader.SetInt("material.specular", MShader.LOCATION_SPECULAR); SkyShader.SetInt("material.multitex", MShader.LOCATION_MULTITEX); SkyShader.SetInt("material.normalmap", MShader.LOCATION_NORMALMAP); SkyShader.SetInt("material.shadowMap", MShader.LOCATION_SHADOWMAP); MSkyMaterial = new MMaterial("SKY01M"); MSkyMaterial.AddShader(SkyShader); MSkyMaterial.SetDiffuseTexture(Globals.TexturePool.GetTexture(SkyTexURL)); MScene.MaterialRoot.Add(MSkyMaterial); }
public override void Setup() { material = new MMaterial("textmat"); //MMaterial uimat = (MMaterial)MScene.MaterialRoot.FindModuleByName("DefaultGUIMaterial"); AddMaterial(material); material.AddShader(Helper.GetGUIShader()); //transform.Scale = new Vector3d(10, 10, 10); //transform.Position = new Vector3d (10, 10, 10); MTexture tex = new MTexture("Texture"); material.SetDiffuseTexture(tex); TextImage = new Bitmap((int)(Width * 16), (int)(Height * 16), PixelFormat.Format32bppArgb); graphics = System.Drawing.Graphics.FromImage(TextImage);; material.DiffuseTexture.Filename = ""; SetText(Text); base.Setup(); // transform.Scale = new Vector3d(1, 1, 1); }
/** * During the Rendering phase all matrices are pre-multiplied (to bring coordinates back to local 32bit space) * and all offsets and set relative to the camera, to aid with shadow calculations - * */ public void Render() { GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); Globals.ShaderOverride = null; Globals.DrawCalls = 0; Globals.Index = 0; Globals.GlobalOffset = Camera.transform.Position; Globals.GlobalOffsetCalc = Camera.transform.Position; Matrix4d offsetmat = Matrix4d.CreateTranslation(-Globals.GlobalOffset); Matrix4d lightmatrix = light.GetLightSpaceMatrix(); Matrix4d view = Camera.GetViewMatrix(); Matrix4d projection = Camera.GetProjection(true); Matrix4d viewproj = view * projection; // GL.Viewport(0, 0, MScreen.Width, MScreen.Height); //============================ // Globals.GlobalOffset = Vector3d.Zero; // GL.CullFace(CullFaceMode.Back); // reset viewport // 2. render scene as normal using the generated depth/shadow map // -------------------------------------------------------------- for (int i = 0; i < MaterialRoot.Modules.Count; i++) { MMaterial mat = (MMaterial)MaterialRoot.Modules[i]; if (mat.IsUsed == false) { continue; } mat.shader.Bind(); mat.shader.SetMat4("view", MTransform.GetFloatMatrix(view)); mat.shader.SetMat4("projection", MTransform.GetFloatMatrix(projection)); mat.shader.SetVec4("Tweak", new Vector4(Settings.Tweak1, Settings.Tweak2, Settings.Tweak3, Settings.Tweak4)); // set light uniforms Fog.Bind(mat.shader); //TODO: use nearest lights mat.shader.SetInt("NumLights", LightRoot.Modules.Count); //TODO sort lights closest to furthest (because there is max lights =10 in shader) for (int il = 0; il < LightRoot.Modules.Count; il++) { if (il >= MAXLIGHTS) { continue; } //pointLightPositions[0] MPointLight p = (MPointLight)LightRoot.Modules[il]; p.Bind(mat, il); } mat.shader.SetVec3("viewPos", MTransform.GetVector3(Camera.transform.Position - Globals.GlobalOffset)); mat.shader.SetVec3("sunPos", MTransform.GetVector3(light.transform.Position - Globals.GlobalOffset)); mat.shader.SetInt("Closeup", Closeup); light.Bind(mat); } /////////////////////// DEPTH LIGHT FOR SHADOWS /////////////////////// GL.Viewport(0, 0, MScreen.Width, MScreen.Height); // GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); if (light.Shadows) { GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); Globals.RenderPass = Globals.eRenderPass.ShadowDepth; //============================ //render depthmap from light using depth shader light.Render(lightmatrix, offsetmat); simpleDepthShader.Bind(); Globals.ShaderOverride = simpleDepthShader; GL.DepthFunc(DepthFunction.Less); GL.Enable(EnableCap.DepthTest); //Background.Render(lightmatrix, offsetmat); //GL.Clear(ClearBufferMask.DepthBufferBit); Background2.Render(lightmatrix, offsetmat); ModelRoot.Render(lightmatrix, offsetmat); Globals.RenderPass = Globals.eRenderPass.Normal; Globals.ShaderOverride = null; } //============================ ////////////////// NORMAL RENDER //////////////////// GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); //Helper.CheckGLError(this, "Render 1"); //set FBO Renderer.Render(viewproj, offsetmat); //Helper.CheckGLError(this, "Render 1"); //load the shadow map into texture slot 4 GL.ActiveTexture(TextureUnit.Texture0 + MShader.LOCATION_SHADOWMAP); GL.BindTexture(TextureTarget.Texture2D, light.depthMap); //////////////////////////////////////////////////////// // GL.PatchParameter(PatchParameterInt.PatchVertices, 16); RenderScene(ref view, ref offsetmat, ref projection, ref viewproj); //////////// OVERLAY LAYER //////////// //============================ GL.Disable(EnableCap.DepthTest); GL.Clear(ClearBufferMask.DepthBufferBit); if (Overlay.Modules.Count > 0) { projection = Camera.GetOverlayProjection(); view = Camera.GetOverlayViewMatrix(); viewproj = view * projection; //UpdateOverlay(); Overlay.Render(viewproj, Matrix4d.Identity); } if (Stereo == true) { GL.Viewport(0, 0, MScreen.Width / 2, MScreen.Height); Vector3d original = Camera.transform.Position; Camera.transform.Position -= Camera.transform.Right(); view = Camera.GetViewMatrix(); viewproj = view * projection; GL.Viewport(MScreen.Width / 2, 0, MScreen.Width / 2, MScreen.Height); RenderScene(ref view, ref offsetmat, ref projection, ref viewproj); Camera.transform.Position = original; GL.Viewport(0, 0, MScreen.Width, MScreen.Height); } Renderer.AfterRender(); // GL.Disable(EnableCap.DepthTest); // GL.Disable(EnableCap.DepthTest); // render Depth map to quad for visual debugging // --------------------------------------------- //GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill); if (Settings.DebugDepth == true) { debugQuad.Bind(); debugQuad.material.shader.SetFloat("near_plane", light.NearPlane); debugQuad.material.shader.SetFloat("far_plane", light.FarPlane); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, light.depthMap); GL.Clear(ClearBufferMask.DepthBufferBit); debugQuad.Render(lightmatrix, Matrix4d.Identity); } ///do not reset /// Globals.GlobalOffset = Vector3d.Zero; //projection = Camera.GetProjection(true); //GUIRoot.Render(Matrix4d.Identity, Matrix4d.Identity); ErrorCode err = GL.GetError(); if (err != ErrorCode.NoError) { //Console.WriteLine("MScene Render:" + err); } }
/// <summary> /// The main setup point for the initial scene graph and tools /// </summary> public void SetupInitialObjects() { Root = new MObject(MObject.EType.Null, "Root"); //Root.Deletable = false; TemplateRoot = new MObject(MObject.EType.Null, "TemplateRoot"); Root.Add(TemplateRoot); TemplateRoot.Enabled = false; //disable updates SelectionRoot = new MObject(MObject.EType.Null, "Selection"); Root.Add(SelectionRoot); UtilityRoot = new MObject(MObject.EType.Null, "Utility"); UtilityRoot.Deletable = false; Root.Add(UtilityRoot); time = new Time(); UtilityRoot.Add(time); LightRoot = new MObject(MObject.EType.Null, "LightRoot"); Root.Add(LightRoot); Globals.ScriptHost = new MScriptHost(); UtilityRoot.Add(Globals.ScriptHost); MSystemScript sc = new MSystemScript("Massive.Main", Root); sc.SetActivator(Globals.ScriptHost.GetMainActivator()); Root.Add(sc); Globals.TexturePool = new TexturePool(); UtilityRoot.Add(Globals.TexturePool); Renderer = new MRenderer(); UtilityRoot.Add(Renderer); DefaultShader = new MShader(MShader.DEFAULT_SHADER); DefaultShader.Load("default_v.glsl", "default_f.glsl", "Terrain\\eval.glsl", "Terrain\\control.glsl"); DefaultShader.Bind(); DefaultShader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE); DefaultShader.SetInt("material.specular", MShader.LOCATION_SPECULAR); DefaultShader.SetInt("material.multitex", MShader.LOCATION_MULTITEX); DefaultShader.SetInt("material.normalmap", MShader.LOCATION_NORMALMAP); DefaultShader.SetInt("material.shadowMap", MShader.LOCATION_SHADOWMAP); //DefaultShader.Deletable = false; Helper.CheckGLError(this, "TestPoint 1"); // MShader GUIShader = new MShader("DefaultGUIShader"); // GUIShader.Load("gui_v.glsl", "gui_f.glsl"); //GUIShader.Bind(); //GUIShader.Deletable = false; MaterialRoot = new MObject(MObject.EType.Null, "MaterialRoot"); //MaterialRoot.Deletable = false; Root.Add(MaterialRoot); Helper.CheckGLError(this); if (Physics != null) { Physics.Dispose(); } Physics = new MPhysics(); Physics.Setup(); //only need to do this once //Physics.Deletable = false; UtilityRoot.Add(Physics); Helper.CheckGLError(this, "TestPoint 2"); //UtilityRoot.Add(Globals.Network); //Globals.Network.Deletable = false; DistanceClipper = new MDistanceClipper(); UtilityRoot.Add(DistanceClipper); FrustrumCuller = new MFrustrumCuller(); UtilityRoot.Add(FrustrumCuller); Globals.Avatar = new MAvatar("Player1"); UtilityRoot.Add(Globals.Avatar); Background = new MObject(MObject.EType.Null, "Background"); Root.Add(Background); Background2 = new MObject(MObject.EType.Null, "Background2"); Root.Add(Background2); ModelRoot = new MObject(MObject.EType.Null, "ModelRoot"); Root.Add(ModelRoot); ModelRoot.Deletable = false; AstroRoot = new MObject(MObject.EType.Null, "AstroRoot"); //ModelRoot.Add(AstroRoot); UtilityRoot.Add(AstroRoot); AstroRoot.Deletable = false; if (Settings.DrawPlanets == true) { MPlanetHandler mpi = new MPlanetHandler(); UtilityRoot.Add(mpi); MGrass grass = new MGrass(); Background2.Add(grass); } Priority1 = new MObject(MObject.EType.Null, "Priority1"); ModelRoot.Add(Priority1); Priority2 = new MObject(MObject.EType.Null, "Priority2"); ModelRoot.Add(Priority2); Overlay = new MObject(MObject.EType.Null, "Overlay"); //ModelRoot.Add(Overlay); //manually drawn in render if (Settings.DrawBackdrop == true) { AddBackdrop(); } Fog = new MFog(); UtilityRoot.Add(Fog); DefaultMaterial = new MMaterial(MMaterial.DEFAULT_MATERIAL); DefaultMaterial.Deletable = false; DefaultMaterial.AddShader(DefaultShader); //DefaultMaterial.SetDiffuseTexture(Globals.TexturePool.GetTexture("Textures\\default.jpg")); MaterialRoot.Add(DefaultMaterial); MTexture DefaultTexture = new MTexture(MTexture.DEFAULT_TEXTURE); DefaultTexture.LoadTextureData(MFileSystem.ProjectPath + "Assets\\Textures\\default.jpg"); DefaultTexture.DoAssign = true; DefaultMaterial.SetDiffuseTexture(DefaultTexture); MMaterial GUIMat = new MMaterial("DefaultGUIMaterial"); //GUIMat.Deletable = false; //GUIMat.AddShader(GUIShader); //GUIMat.SetDiffuseTexture(Globals.TexturePool.GetTexture("Textures\\unwrap_helper_1024.jpg")); //MaterialRoot.Add(GUIMat); MMaterial DepthMaterial = new MMaterial("Depth"); DepthMaterial.Deletable = false; simpleDepthShader = new MShader("simpleDepthShader"); simpleDepthShader.Load("shadow_mapping_depth_v.glsl", "shadow_mapping_depth_f.glsl", "", "") ; DepthMaterial.shader = simpleDepthShader; DepthMaterial.Add(simpleDepthShader); MaterialRoot.Add(DepthMaterial); Helper.CheckGLError(this, "TestPoint 5"); //UtilityRoot.Add(audioListener); //audioListener.Deletable = false; Camera = new MCamera("MainCam"); Camera.OwnerID = MObject.OWNER_SYSTEM; Camera.transform.Position = new Vector3d(9, 5, 9); UtilityRoot.Add(Camera); audioListener = new MAudioListener(); Camera.Add(audioListener); // Camera.Deletable = false; light = new MLight("DirLight"); light.OwnerID = MObject.OWNER_SYSTEM; light.transform.Position = new Vector3d(-10, 20.0f, -10.0f); UtilityRoot.Add(light); //light.Deletable = false; ScreenPick = new MScreenPick(); // ScreenPick.Setup(); UtilityRoot.Add(ScreenPick); // ScreenPick.Deletable = false; MShader debugDepthQuad = new MShader("debugDepthQuad"); debugDepthQuad.Load("debug_quad_v.glsl", "debug_quad_f.glsl", "Terrain\\eval.glsl", "Terrain\\control.glsl"); debugDepthQuad.Bind(); debugDepthQuad.SetInt("depthMap", 0); //debugDepthQuad.SetFloat("near_plane", light.NearPlane); //debugDepthQuad.SetFloat("far_plane", light.FarPlane); UtilityRoot.Add(debugDepthQuad); debugDepthQuad.Deletable = false; MMaterial debugmat = new MMaterial("DEBUG"); debugmat.shader = debugDepthQuad; //debugmat.Deletable = false; debugQuad = new DebugQuad("DEBUGQUAD"); debugQuad.material = debugmat; UtilityRoot.Add(debugQuad); debugQuad.Deletable = false; GUIRoot = new MGUI(); Root.Add(GUIRoot); Helper.CheckGLError(this, "TestPoint 6"); }
public virtual void SetMaterial(MMaterial m) { Modules.Remove(material); material = m; Add(material); }
public void AddMaterial(MMaterial m) { Add(m); material = m; }
public void InitializePlanets() { //GravityIndicator = Helper.CreateCube(MScene.AstroRoot, "GravitySphere", Vector3d.Zero); //GravityIndicator.transform.Scale = new Vector3d(0.05, 0.1, 0.1); //GravityIndicator.OwnerID = "MasterAstronomer"; //MScene.AstroRoot.Add(GravityIndicator); //GravityIndicator.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL)); CreateShaders(); for (int i = 0; i < Bodies.Count; i++) { MAstroBody m = Bodies[i]; //m.Radius = m.Radius * 0.5; if (m.IsTemplate == true) { continue; } m.ListIndex = i; Vector3d pos = m.Position + new Vector3d(-m.Radius.X, 0, 0) * (m.HasRings == true ? 3.0 : 1.1); MServerZone zone = new MServerZone("MASTER_ASTRONOMER", m.Name, "Astronomical", MassiveTools.ToVector3_Server(pos)); zone.Rotation = MassiveTools.ArrayFromQuaterniond(Quaterniond.Identity); zone.Description = m.Description + " \nRadius:" + m.Radius; MMessageBus.AddZone(this, zone); //Extensions.LookAt(m.Position + m.Radius * 2, m.Position), m.Name)); MSceneObject mo; //planet files contain uvs for mercator if (m.HasAtmosphere) { CurrentNear = m; mo = Helper.CreateModel(MScene.AstroRoot, m.Name, @"Models\planets\earth.3ds", Vector3d.Zero); //mo = Helper.CreateSphere(MScene.AstroRoot, 3, "Planet"); //mo.transform.Scale = m.Radius * 1.00055; mo.transform.Scale = m.Radius; } else { mo = Helper.CreateModel(MScene.AstroRoot, m.Name, @"Models\planets\planet_sphere2.3ds", Vector3d.Zero); mo.transform.Scale = m.Radius; } if (m.HasRings) { MModel ring = Helper.CreateModel(MScene.Priority2, m.Name + "_rings", @"Models\planets\planet_rings.3ds", Vector3d.Zero); ring.transform.Position = m.Position; ring.transform.Rotation = Quaterniond.FromEulerAngles(0, 0, 5 * Math.PI / 180); ring.transform.Scale = m.Radius; ring.InstanceID = m.Name; ring.TemplateID = m.Name; ring.DistanceThreshold = m.Radius.X * 12; ring.OwnerID = "MasterAstronomer"; MMaterial ringmat = new MMaterial(m.Name + "_mat"); ringmat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); MTexture ringtex = Globals.TexturePool.GetTexture(@"Textures\Planets\saturn_rings.png"); ringmat.SetDiffuseTexture(ringtex); ring.SetMaterial(ringmat); MPhysicsObject ringpo = new MPhysicsObject(ring, "Physics", 0, MPhysicsObject.EShape.ConcaveMesh, false, m.Radius); ringpo.SetLinearFactor(0, 0, 0); ringpo.SetRestitution(0.5); } mo.transform.Position = m.Position; //mo.transform.Scale = m.Radius * 1.9999; mo.InstanceID = m.Name; mo.TemplateID = m.Name; mo.OwnerID = "MasterAstronomer"; mo.DistanceThreshold = m.Radius.X * 110002; //distance at which it becomes visible //MModel mod = (MModel)mo.FindModuleByType(EType.Model); //mod.DistanceThreshold = mo.DistanceThreshold; //MMesh met = (MMesh)mod.FindModuleByType(EType.Mesh); //if ( met != null ) { //met.DistanceThreshold = mo.DistanceThreshold; //} mo.Tag = m; m.Tag = mo; //now that we have a 3d model, apply some progressive textures (will auto-switch with smooth transition in shader) MMaterial mat = new MMaterial(m.Name + "_mat"); mat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); MTexture tex = Globals.TexturePool.GetTexture(m.TextureName); mat.SetDiffuseTexture(tex); mo.SetMaterial(mat); MTexture tex2 = Globals.TexturePool.GetTexture("Textures\\terrain\\sand01b.jpg"); mat.SetMultiTexture(tex2); MTexture tex3 = Globals.TexturePool.GetTexture("Textures\\terrain\\water.jpg"); mat.SetNormalMap(tex3); double dia = 2.0 * Math.PI * m.Radius.X * 0.0000001; //double dia = 1; mat.Tex2CoordScale = new Vector2((float)dia, (float)dia); mo.SetMaterial(mat); MScene.MaterialRoot.Add(mat); if (m.HasAtmosphere) { if (Settings.DrawTerrains == true) { m.AddDynamicTerrain(); //adds tile based terrain (from e.g. tile service) } //MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.ConcaveMesh, //false, m.Radius); MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.Sphere, false, m.Radius); //po.SetLinearFactor(0, 0, 0); //po.SetRestitution(0.5); //MSphere moc = Helper.CreateSphere(MScene.AstroRoot, 3, m.Name+ "Clouds", Vector3d.Zero); MModel moc = Helper.CreateModel(MScene.AstroRoot, m.Name + "_clouds", @"Models\planets\clouds.3ds", Vector3d.Zero); moc.CastsShadow = false; moc.transform.Position = m.Position; moc.transform.Scale = m.Radius; moc.DistanceThreshold = m.Radius.X * 3; //moc.transform.Scale = m.Radius*2.1; moc.InstanceID = m.Name; moc.TemplateID = m.Name; moc.OwnerID = "MasterAstronomer"; moc.Tag = m; MMaterial cmat = new MMaterial("CloudMat"); cmat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); cmat.Opacity = 1; cmat.IsSky = 1; // = new MTexture("CloudTex"); MTexture ctex = Globals.TexturePool.GetTexture(CloudTexURL); ctex.Additive = false; cmat.SetDiffuseTexture(ctex); moc.SetMaterial(cmat); MScene.MaterialRoot.Add(cmat); MModel sky = Helper.CreateModel(MScene.AstroRoot, m.Name + "_sky", @"Models\sky.3ds", Vector3d.Zero); sky.CastsShadow = false; sky.transform.Position = m.Position; sky.transform.Scale = m.Radius; //moc.transform.Scale = m.Radius*2.1; sky.InstanceID = m.Name; sky.TemplateID = m.Name; sky.OwnerID = "MasterAstronomer"; sky.Tag = m; sky.SetMaterial(cmat); sky.DistanceThreshold = m.Radius.X * 4; MObjectAnimation ani = new MObjectAnimation(); ani.AngleOffset = Quaterniond.FromEulerAngles(0, 0.002, 0); ani.Speed = 1; sky.Add(ani); sky.SetMaterial(MSkyMaterial); /*MMaterial csky = new MMaterial("Skymat"); * csky.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); * csky.Opacity = 0.5; * csky.IsSky = 1; * // = new MTexture("CloudTex"); * MTexture cSkyTex = Globals.TexturePool.GetTexture(OpaqueCloudTexURL); * cSkyTex.Additive = false; * csky.SetDiffuseTexture(cSkyTex); * sky.SetMaterial(csky); * MScene.MaterialRoot.Add(csky); */ /* MSphere water = Helper.CreateSphere(MScene.ModelRoot, 5, "Water"); * water.transform.Position = m.Position; * water.transform.Scale = m.Radius * 2.00; * MMaterial waterman = new MMaterial("Watermat"); * MShader shader = new MShader("watershader"); * shader.Load("ocean_vs.glsl", "ocean_fs.glsl"); * shader.Bind(); * shader.SetInt("diffuseTexture", 0); * shader.SetInt("shadowMap", 1); * waterman.AddShader(shader); * water.SetMaterial(waterman); */ //water.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL)); } else { MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.Sphere, false, m.Radius * 0.999); po.SetLinearFactor(0, 0, 0); po.SetRestitution(0.5); } m.Setup(); //Console.WriteLine("Created:" + mo.Name + ":" + (mo.transform.Position) + " R:" + m.Radius); } }
public static MMaterial FindMaterial(string sName) { MMaterial m = (MMaterial)MScene.MaterialRoot.FindModuleByName(sName); return(m); }