internal static void Add(ref MyRenderVoxelMaterialData materialData) { // Check if not yet assigned MyDebug.AssertRelease(!m_materials.ContainsKey(materialData.Index)); // Create and add into array MyRenderVoxelMaterial voxelMaterial = new MyRenderVoxelMaterial(materialData); m_materials[materialData.Index] = voxelMaterial; }
// Parameter 'useTwoTexturesPerMaterial' tells us if we use two textures per material. One texture for axis XZ and second for axis Y. // Use it for rock/stone materials. Don't use it for gold/silver, because there you don't need to make difference between side and bottom materials. // Using this we save texture memory, but pixel shader still used differenced textures (two samplers looking to same texture) public MyRenderVoxelMaterial(MyRenderVoxelMaterialData data) { // SpecularPower must be > 0, because pow() makes NaN results if called with zero MyDebug.AssertRelease(data.SpecularPower > 0); m_diffuseXZ = data.DiffuseXZ; m_diffuseY = data.DiffuseY; m_normalXZ = data.NormalXZ; m_normalY = data.NormalY; SpecularIntensity = data.SpecularShininess; SpecularPower = data.SpecularPower; m_materialIndex = data.Index; }
public MyObjectsPoolSimple(int capacity) { // Pool should contain at least one preallocated item! MyDebug.AssertRelease(capacity > 0); ClearAllAllocated(); // Preallocate items m_items = new T[capacity]; for (int i = 0; i < m_items.Length; i++) { m_items[i] = new T(); } }
// This method initializes voxel map (size, position, etc) but doesn't load voxels // It only presets all materials to values specified in 'defaultMaterial' - so it will become material everywhere. private void InitVoxelMap(Vector3 positionLeftBottom) { MySandboxGame.Log.WriteLine("MyVoxelMap.InitVoxelMap() - Start"); MySandboxGame.Log.IncreaseIndent(); var defaultMaterial = MyDefinitionManager.Static.GetDefaultVoxelMaterialDefinition(); VoxelMapId = MySession.Static.VoxelMaps.AllocateId(); var size = Storage.Size; MySandboxGame.Log.WriteLine("File: " + Storage.Name, LoggingOptions.VOXEL_MAPS); MySandboxGame.Log.WriteLine("ID: " + VoxelMapId, LoggingOptions.VOXEL_MAPS); MySandboxGame.Log.WriteLine("Size: " + size, LoggingOptions.VOXEL_MAPS); // If you need more voxel maps, enlarge this constant. MyDebug.AssertRelease(VoxelMapId <= MyVoxelConstants.MAX_VOXEL_MAP_ID); SizeInMetres = size * MyVoxelConstants.VOXEL_SIZE_IN_METRES; SizeInMetresHalf = SizeInMetres / 2.0f; LocalAABB = new BoundingBox(-SizeInMetresHalf, SizeInMetresHalf); PositionLeftBottomCorner = positionLeftBottom; if (MyFakes.ENABLE_DEPRECATED_HALF_VOXEL_OFFSET) { // for backward compatibility only PositionLeftBottomCorner += MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF; } SetWorldMatrix(Matrix.CreateTranslation(PositionLeftBottomCorner + SizeInMetresHalf)); // If you need larged voxel maps, enlarge this constant. MyDebug.AssertRelease(Size.X <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS); MyDebug.AssertRelease(Size.Y <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS); MyDebug.AssertRelease(Size.Z <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS); // Voxel map size must be multiple of a voxel data cell size. MyDebug.AssertRelease((Size.X & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); MyDebug.AssertRelease((Size.Y & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); MyDebug.AssertRelease((Size.Z & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); // Voxel map size must be multiple of a voxel data cell size. MyDebug.AssertRelease((Size.X % MyVoxelConstants.RENDER_CELL_SIZE_IN_VOXELS) == 0); MyDebug.AssertRelease((Size.Y % MyVoxelConstants.RENDER_CELL_SIZE_IN_VOXELS) == 0); MyDebug.AssertRelease((Size.Z % MyVoxelConstants.RENDER_CELL_SIZE_IN_VOXELS) == 0); RenderCellsCount = Size / MyVoxelConstants.RENDER_CELL_SIZE_IN_VOXELS; Geometry.Init(this); CastShadows = true; MySandboxGame.Log.DecreaseIndent(); MySandboxGame.Log.WriteLine("MyVoxelMap.InitVoxelMap() - End"); }
public override void LoadContent() { MyRender.Log.WriteLine("MyDecals.LoadContent() - START"); MyRender.Log.IncreaseIndent(); MyRender.GetRenderProfiler().StartProfilingBlock("MyDecals::LoadContent"); // Reason is that if count of neighbour triangles is more then decal triangles buffer, we won't be able to add any triangleVertexes to the buffer. MyDebug.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER > MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES); MyDebug.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_LARGE <= MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER); MyDebug.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_SMALL <= MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER); // Reason is that if count of neighbour triangles is more then decal triangles buffer, we won't be able to add any triangleVertexes to the buffer. MyDebug.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER > MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES); // Reason is that if count of neighbour triangles is more then this fade limit, we won't be able to add decals that lay on more triangles, because buffer will be never released to us. MyDebug.AssertRelease(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES < (MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.TEXTURE_LARGE_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT)); // Reason is that if count of neighbour triangles is more then this fade limit, we won't be able to add decals that lay on more triangles, because buffer will be never released to us. MyDebug.AssertRelease(MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES < (MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.TEXTURE_SMALL_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT)); // Large must be bigger than small MyDebug.AssertRelease(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES > MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES); m_vertices = new MyVertexFormatDecal[MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.VERTEXES_PER_DECAL]; // m_neighbourTriangles = new List<MyTriangle_Vertex_Normals>(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES); m_decalsForModels = new MyDecalsForRenderObjects(MyDecalsConstants.DECAL_BUFFERS_COUNT); m_decalsForVoxels = new MyDecalsForVoxels(MyDecalsConstants.DECAL_BUFFERS_COUNT); // Decal textures int texturesCount = MyEnumsToStrings.Decals.Length; m_texturesDiffuse = new MyTexture2D[texturesCount]; m_texturesNormalMap = new MyTexture2D[texturesCount]; for (int i = 0; i < texturesCount; i++) { //MyRender.Log.WriteLine("textureManager " + i.ToString() + "Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_Diffuse", SysUtils.LoggingOptions.MISC_RENDER_ASSETS); m_texturesDiffuse[i] = MyTextureManager.GetTexture <MyTexture2D>("Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_Diffuse.dds", "", null, LoadingMode.Immediate); //MyRender.Log.WriteLine("textureManager " + i.ToString() + "Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_NormalMap", SysUtils.LoggingOptions.MISC_RENDER_ASSETS); m_texturesNormalMap[i] = MyTextureManager.GetTexture <MyTexture2D>("Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_NormalMap.dds", "", CheckTexture, LoadingMode.Immediate); MyUtilsRender9.AssertTexture(m_texturesNormalMap[i]); } MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.Log.DecreaseIndent(); MyRender.Log.WriteLine("MyDecals.LoadContent() - END"); }
public MyRenderCustomMaterial(MyRenderCustomMaterialData data) { m_materialIndex = data.Index; Mass = data.Mass; Strength = data.Strength; // SpecularPower must be > 0, because pow() makes NaN results if called with zero MyDebug.AssertRelease(data.SpecularPower > 0); SpecularIntensity = data.SpecularShininess; SpecularPower = data.SpecularPower; m_diffuse = data.Diffuse; m_normal = data.Normal; }
private void InitCues(MyObjectBuilder_CueDefinitions cues) { foreach (var cue in cues.Cues) { bool found = false; foreach (MySoundCuesEnum soundCue in Enum.GetValues(typeof(MySoundCuesEnum))) { if (cue.Name == soundCue.ToString()) { m_cues[(int)soundCue] = cue; found = true; break; } } MyDebug.AssertRelease(found, string.Format("Cue {0} not in enum", cue.Name)); } }
// Parameter 'useTwoTexturesPerMaterial' tells us if we use two textures per material. One texture for axis XZ and second for axis Y. // Use it for rock/stone materials. Don't use it for gold/silver, because there you don't need to make difference between side and bottom materials. // Using this we save texture memory, but pixel shader still used differenced textures (two samplers looking to same texture) public MyRenderVoxelMaterial(MyRenderVoxelMaterialData data) { // SpecularPower must be > 0, because pow() makes NaN results if called with zero MyDebug.AssertRelease(data.SpecularPower > 0); m_diffuseXZ = data.DiffuseXZ; m_diffuseY = data.DiffuseY; m_normalXZ = data.NormalXZ; m_normalY = data.NormalY; SpecularIntensity = data.SpecularShininess; SpecularPower = data.SpecularPower; m_materialIndex = data.Index; DistancesAndScale = data.DistanceAndScale; DistancesAndScaleFar = data.DistanceAndScaleFar; ExtensionDetailScale = data.ExtensionDetailScale; DistancesAndScaleFar3 = data.DistanceAndScaleFar3; Far3Color = data.Far3Color; }
static void Validate <T>(Type type, T list) where T : IList <string> { Array values = Enum.GetValues(type); Type underlyingType = Enum.GetUnderlyingType(type); if (underlyingType == typeof(System.Byte)) { foreach (byte value in values) { MyDebug.AssertRelease(list[value] != null); } } else if (underlyingType == typeof(System.Int16)) { foreach (short value in values) { MyDebug.AssertRelease(list[value] != null); } } else if (underlyingType == typeof(System.UInt16)) { foreach (ushort value in values) { MyDebug.AssertRelease(list[value] != null); } } else if (underlyingType == typeof(System.Int32)) { foreach (int value in values) { MyDebug.AssertRelease(list[value] != null); } } else { // Unhandled underlying type - probably "long" throw new InvalidBranchException(); } }
private static void Validate <T>(Type type, T list) where T : IList <string> { Array values = Enum.GetValues(type); Type underlyingType = Enum.GetUnderlyingType(type); if (underlyingType == typeof(byte)) { foreach (byte num in values) { MyDebug.AssertRelease(list[num] != null); } } else if (underlyingType == typeof(short)) { foreach (short num2 in values) { MyDebug.AssertRelease(list[num2] != null); } } else if (underlyingType == typeof(ushort)) { foreach (ushort num3 in values) { MyDebug.AssertRelease(list[num3] != null); } } else if (!(underlyingType == typeof(int))) { throw new InvalidBranchException(); } else { foreach (int num4 in values) { MyDebug.AssertRelease(list[num4] != null); } } }
// Calculate texture size, based on width * resolution, texture format (number of bytes per one pixel) and number of mip-map levels // Result is in mega bytes (not bytes) // IMPORTANT: I am not sure if I am doing this correctly for non-uniform mip maps (e.g. 512x128) because each dimension should // have different mipmap level count, but there's only one. In forst case, result will be wrong just by few bytes. public static double CalculateTextureSizeInMb(Format inputFormat, int inputWidth, int inputHeight, int inputLevelCount) { int sizeInBytes = 0; int width = inputWidth; int height = inputHeight; for (int level = 0; level < inputLevelCount; level++) { int sizeOfOneLevel; MyDebug.AssertRelease(width >= 1); MyDebug.AssertRelease(height >= 1); switch (inputFormat) { case Format.A8: case Format.L8: sizeOfOneLevel = width * height; break; case Format.A8R8G8B8: case Format.A8B8G8R8: case Format.D24S8: case Format.A2R10G10B10: case Format.Q8W8V8U8: sizeOfOneLevel = width * height * 4; break; case Format.Dxt1: sizeOfOneLevel = (width * height * 3) / 8; break; case Format.Dxt3: case Format.Dxt5: sizeOfOneLevel = (width * height * 4) / 4; break; case Format.R32F: sizeOfOneLevel = (width * height * 4); break; case Format.A16B16G16R16: case Format.A16B16G16R16F: sizeOfOneLevel = (width * height * 4) * 2; break; default: throw new Exception("You are trying to calculate 'texture size in Mb' on a texture whose format is not yet supported by this method. You should extend this method!"); } sizeInBytes += sizeOfOneLevel; if (width > 1) { width /= 2; } if (height > 1) { height /= 2; } } return(sizeInBytes / 1024.0 / 1024.0); }
static void AssertTextureDxtCompress(MyTexture2D texture) { MyDebug.AssertRelease(IsTextureDxtCompressed(texture)); }