public DiffuseGlossTexture( TextureFileInfo _diffuse, TextureFileInfo _gloss ) { m_diffuseFileName = _diffuse.m_fileName; m_glossFileName = _gloss != null ? _gloss.m_fileName : null; m_diffuse = _diffuse; m_gloss = _gloss; }
public DiffuseGlossTexture(TextureFileInfo _diffuse, TextureFileInfo _gloss) { m_diffuseFileName = _diffuse.m_fileName; m_glossFileName = _gloss != null ? _gloss.m_fileName : null; m_diffuse = _diffuse; m_gloss = _gloss; }
/// <summary> /// Gives the name of the (diffuse+gloss) texture that will be generated /// </summary> /// <returns></returns> public FileInfo GetDiffuseGlossTextureFileName() { if (m_diffuse == null) { throw new Exception("Invalid source diffuse image file!"); } if (!m_diffuse.m_fileName.Exists) { throw new Exception("Source diffuse image file \"" + m_diffuse.m_fileName.FullName + "\" does not exist on disk!"); } string targetFileNameString = TextureFileInfo.GetOptimizedDiffuseGlossNameFromDiffuseName(m_diffuse.m_fileName.FullName); FileInfo targetFileName = new FileInfo(targetFileNameString); return(targetFileName); }
void TrySwapping( ref Texture _a, ref Texture _b, TextureFileInfo.USAGE _expectedUsageForA, TextureFileInfo.USAGE _expectedUsageForB, ref int _swappedSlotsCount ) { if ( _a == null || _a.m_textureFileInfo == null ) return; if ( _b == null || _b.m_textureFileInfo == null ) return; if ( _a.m_textureFileInfo.m_usage == _expectedUsageForB && _b.m_textureFileInfo.m_usage == _expectedUsageForA ) { // Switch! Texture temp = _a; _a = _b; _b = temp; _swappedSlotsCount++; } }
/// <summary> /// Generates a (diffuse+gloss) texture from 2 distinct textures /// </summary> public void GenerateDiffuseGlossTexture() { if (m_diffuse == null) { throw new Exception("Invalid source diffuse image file!"); } if (!m_diffuse.m_fileName.Exists) { throw new Exception("Source diffuse image file \"" + m_diffuse.m_fileName.FullName + "\" does not exist on disk!"); } string targetFileNameString = TextureFileInfo.GetOptimizedDiffuseGlossNameFromDiffuseName(m_diffuse.m_fileName.FullName); FileInfo targetFileName = new FileInfo(targetFileNameString); using (ImageUtility.Bitmap diffuse = new ImageUtility.Bitmap(m_diffuse.m_fileName)) { int W = diffuse.Width; int H = diffuse.Height; ImageUtility.Bitmap gloss = null; if (m_gloss != null) { gloss = new ImageUtility.Bitmap(m_gloss.m_fileName); // int gW = gloss.Width; // int gH = gloss.Height; // for ( int Y=0; Y < gH; Y++ ) // for ( int X=0; X < gW; X++ ) { // gloss.ContentXYZ[X,Y].x = ImageUtility.ColorProfile.sRGB2Linear( gloss.ContentXYZ[X,Y].x ); // } } bool needsScale = false; if (gloss != null && (gloss.Width != W || gloss.Height != H)) { needsScale = true; } if (gloss != null) { if (needsScale) { // Set gloss as alpha with re-scaling float scaleX = (float)gloss.Width / W; float scaleY = (float)gloss.Height / H; for (int Y = 0; Y < H; Y++) { float Y2 = scaleY * Y; for (int X = 0; X < W; X++) { diffuse.ContentXYZ[X, Y].w = gloss.BilinearSample(scaleX * X, Y2).x; } } } else { // Set gloss as alpha without re-scaling for (int Y = 0; Y < H; Y++) { for (int X = 0; X < W; X++) { // diffuse.ContentXYZ[X,Y].w = gloss.ContentXYZ[X,Y].x; diffuse.ContentXYZ[X, Y].w = 0.3f * gloss.ContentXYZ[X, Y].x + 0.5f * gloss.ContentXYZ[X, Y].y + 0.2f * gloss.ContentXYZ[X, Y].z; } } } } else { for (int Y = 0; Y < H; Y++) { for (int X = 0; X < W; X++) { diffuse.ContentXYZ[X, Y].w = 1.0f; } } } // Save diffuse as target diffuse.HasAlpha = gloss != null; diffuse.Save(targetFileName); } // Save optimized filename + timestamps of source files m_diffuseFileName.Refresh(); if (m_glossFileName != null) { m_glossFileName.Refresh(); } m_optimizedDiffuseGlossFileName = targetFileName; m_diffuseTimeAtGeneration = m_diffuseFileName.LastWriteTime; m_glossTimeAtGeneration = m_glossFileName != null ? m_glossFileName.LastWriteTime : DateTime.MinValue; }