/// <summary> /// Inits the specified hud label text. /// </summary> /// <param name="hudLabelText">The hud label text.</param> /// <param name="objectBuilder">The object builder.</param> public void Init(string hudLabelText, MyMwcObjectBuilder_StaticAsteroid objectBuilder, Matrix matrix) { MyStaticAsteroidModels models = GetModelsFromType(objectBuilder.AsteroidType); StringBuilder hudLabelTextSb = (hudLabelText == null) ? null : new StringBuilder(hudLabelText); if (objectBuilder.Generated) { Flags &= ~EntityFlags.EditableInEditor; Flags &= ~EntityFlags.NeedsId; } else { Flags |= EntityFlags.EditableInEditor; Flags |= EntityFlags.NeedsId; } CastShadows = !objectBuilder.Generated; if (!objectBuilder.AsteroidMaterial1.HasValue && MySector.Area.HasValue) { var area = MySolarSystemConstants.Areas[MySector.Area.Value]; objectBuilder.AsteroidMaterial1 = area.SecondaryStaticAsteroidMaterial; objectBuilder.FieldDir = MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized(); } NeedsUpdate = false; Init(hudLabelTextSb, models.LOD0, models.LOD1, null, null, objectBuilder, null, models.LOD2); AsteroidType = objectBuilder.AsteroidType; SetWorldMatrix(matrix); FieldDir = objectBuilder.FieldDir; if (objectBuilder.AsteroidMaterial.HasValue) { VoxelMaterial = objectBuilder.AsteroidMaterial.Value; VoxelMaterial1 = objectBuilder.AsteroidMaterial1; m_drawTechnique = MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID; } if (objectBuilder.UseModelTechnique) { m_meshMaterial = MyVoxelMaterials.GetMaterialForMesh(VoxelMaterial); m_drawTechnique = MyMeshDrawTechnique.MESH; } InitDrawTechniques(); InitPhysics(); MyModels.OnContentLoaded += InitDrawTechniques; InitDrawTechniques(); }
static void Add(MyMwcVoxelMaterialsEnum materialEnum, string assetName, bool isIndestructible, bool useTwoTextures, float specularShininess, float specularPower, bool hasBuilderVersion) { // Check if not yet assigned MyCommonDebugUtils.AssertRelease(m_materials[(int)materialEnum] == null); //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("new MyVoxelMaterial"); // Create and add into array MyVoxelMaterial voxelMaterial = new MyVoxelMaterial(materialEnum, assetName, isIndestructible, useTwoTextures, specularShininess, specularPower, hasBuilderVersion); m_materials[(int)materialEnum] = voxelMaterial; m_meshMaterials[(int)materialEnum] = new MyMeshMaterial("Textures\\Voxels\\" + assetName + "_ForAxisXZ", assetName, voxelMaterial.GetTextures().TextureDiffuseForAxisXZ, voxelMaterial.GetTextures().TextureNormalMapForAxisXZ); }
public static void Draw() { if (!CanDrawCockpit()) { return; } MyModel model = MyModels.GetModelForDraw(MySession.PlayerShip.CockpitGlassModelEnum); RasterizerState.CullNone.Apply(); if (MyRenderConstants.RenderQualityProfile.ForwardRender) { DepthStencilState.DepthRead.Apply(); } else { MyStateObjects.DepthStencil_StencilReadOnly.Apply(); } BlendState.NonPremultiplied.Apply(); MyEffectCockpitGlass effect = (MyEffectCockpitGlass)MyRender.GetEffect(MyEffects.CockpitGlass); float glassDirtAlpha = MathHelper.Lerp(MyCockpitGlassConstants.GLASS_DIRT_MIN, MyCockpitGlassConstants.GLASS_DIRT_MAX, MySession.PlayerShip.GlassDirtLevel); effect.SetGlassDirtLevelAlpha(new Vector4(glassDirtAlpha, 0, 0, 0)); effect.SetWorldMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix); effect.SetViewMatrix(MyCamera.ViewMatrix); if (!MyRenderConstants.RenderQualityProfile.ForwardRender) { Matrix projection = MyCamera.ProjectionMatrixForNearObjects; effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewMatrixAtZero * projection); } else { effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewProjectionMatrixAtZero); } MyMeshMaterial cockpitMaterial = model.GetMeshList()[0].Materials[0]; cockpitMaterial.PreloadTexture(); effect.SetCockpitGlassTexture(cockpitMaterial.DiffuseTexture); if (!MyRenderConstants.RenderQualityProfile.ForwardRender) { Texture depthRT = MyRender.GetRenderTarget(MyRenderTargets.Depth); effect.SetDepthTexture(depthRT); effect.SetHalfPixel(MyUtils.GetHalfPixel(depthRT.GetLevelDescription(0).Width, depthRT.GetLevelDescription(0).Height)); } Vector4 sunColor = MySunWind.GetSunColor(); effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z)); effect.SetDirectionToSun(MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized()); effect.SetAmbientColor(Vector3.Zero); effect.SetReflectorPosition(MyCamera.Position - 4 * MySession.PlayerShip.WorldMatrix.Forward); if (MySession.PlayerShip.Light != null) { effect.SetNearLightColor(MySession.PlayerShip.Light.Color); effect.SetNearLightRange(MySession.PlayerShip.Light.Range); } MyRender.GetShadowRenderer().SetupShadowBaseEffect(effect); effect.SetShadowBias(0.001f); m_boundingSphereForLights.Center = MySession.PlayerShip.GetPosition(); MyLights.UpdateEffect(effect, ref m_boundingSphereForLights, true); effect.Begin(); model.Render(); effect.End(); MyCockpitGlassDecals.Draw(effect); }
static void SetupShaderForMaterialAlternative(MyEffectBase shader, MyMeshMaterial material) { switch (material.DrawTechnique) { case MyMeshDrawTechnique.MESH: case MyMeshDrawTechnique.DECAL: case MyMeshDrawTechnique.HOLO: case MyMeshDrawTechnique.ALPHA_MASKED: { if (material != null) { shader.SetTextureDiffuse(material.DiffuseTexture); shader.SetTextureNormal(material.NormalTexture); //Do we need this? Graphicians dont use this //shader.SetDiffuseColor(material.DiffuseColor); shader.SetSpecularIntensity(material.SpecularIntensity); shader.SetSpecularPower(material.SpecularPower); shader.SetDiffuseUVAnim(material.DiffuseUVAnim); shader.SetEmissivityUVAnim(material.EmissiveUVAnim); shader.SetEmissivityOffset(material.EmissivityOffset); if (material.DrawTechnique == MyMeshDrawTechnique.HOLO) { shader.SetEmissivity(material.HoloEmissivity); } // Commented due 856 - graphicians have to reexport white diffuse colors from MAX //shader.SetDiffuseColor(material.DiffuseColor); } else { shader.SetTextureDiffuse(null); shader.SetTextureNormal(null); shader.SetSpecularPower(1); shader.SetSpecularIntensity(1); //this value is set from object if not from material //shader.SetDiffuseColor(material.DiffuseColor); } if (CheckDiffuseTextures) { if (!shader.IsTextureDiffuseSet()) { LazyLoadDebugTextures(); shader.SetTextureDiffuse(m_debugTexture); shader.SetDiffuseColor(Vector3.One); shader.SetEmissivity(1); } else { if (material.DrawTechnique != MyMeshDrawTechnique.HOLO) { shader.SetEmissivity(0); } } } if (CheckNormalTextures) { if (!shader.IsTextureNormalSet()) { LazyLoadDebugTextures(); shader.SetTextureDiffuse(m_debugTexture); shader.SetEmissivity(1); } else { shader.SetTextureDiffuse(material.NormalTexture); //shader.SetTextureDiffuse(m_debugNormalTexture); shader.SetEmissivity(0); } } if (!shader.IsTextureNormalSet()) { LazyLoadDebugTextures(); shader.SetTextureNormal(m_debugTexture); } } break; case MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID: case MyMeshDrawTechnique.VOXELS_DEBRIS: break; default: { throw new MyMwcExceptionApplicationShouldNotGetHere(); } } }