virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) { for (int iFrame = 0; iFrame < pVTFTexture->FrameCount(); ++iFrame ) { for (int iFace = 0; iFace < pVTFTexture->FaceCount(); ++iFace ) { int nWidth = pVTFTexture->Width(); int nHeight = pVTFTexture->Height(); int nDepth = pVTFTexture->Depth(); for (int z = 0; z < nDepth; ++z) { // Fill mip 0 with a checkerboard CPixelWriter pixelWriter; pixelWriter.SetPixelMemory( pVTFTexture->Format(), pVTFTexture->ImageData( iFrame, iFace, 0, 0, 0, z ), pVTFTexture->RowSizeInBytes( 0 ) ); for (int y = 0; y < nHeight; ++y) { pixelWriter.Seek( 0, y ); for (int x = 0; x < nWidth; ++x) { if ( ((x & m_nCheckerSize) ^ (y & m_nCheckerSize)) ^ (z & m_nCheckerSize) ) { pixelWriter.WritePixel( m_Color1.r, m_Color1.g, m_Color1.b, m_Color1.a ); } else { pixelWriter.WritePixel( m_Color2.r, m_Color2.g, m_Color2.b, m_Color2.a ); } } } } } } }
virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) { int nMipCount = pTexture->IsMipmapped() ? pVTFTexture->MipCount() : 1; for (int iFrame = 0; iFrame < pVTFTexture->FrameCount(); ++iFrame ) { for (int iFace = 0; iFace < pVTFTexture->FaceCount(); ++iFace ) { for (int iMip = 0; iMip < nMipCount; ++iMip ) { int nWidth, nHeight, nDepth; pVTFTexture->ComputeMipLevelDimensions( iMip, &nWidth, &nHeight, &nDepth ); for (int z = 0; z < nDepth; ++z) { CPixelWriter pixelWriter; pixelWriter.SetPixelMemory( pVTFTexture->Format(), pVTFTexture->ImageData( iFrame, iFace, iMip, 0, 0, z ), pVTFTexture->RowSizeInBytes( iMip ) ); for (int y = 0; y < nHeight; ++y) { pixelWriter.Seek( 0, y ); for (int x = 0; x < nWidth; ++x) { pixelWriter.WritePixel( m_Color.r, m_Color.g, m_Color.b, m_Color.a ); } } } } } } }
virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) { int nWidth = pVTFTexture->Width(); int nHeight = pVTFTexture->Height(); int nDepth = pVTFTexture->Depth(); Assert( nWidth == COLOR_CORRECTION_TEXTURE_SIZE && nHeight == COLOR_CORRECTION_TEXTURE_SIZE && nDepth == COLOR_CORRECTION_TEXTURE_SIZE ); for ( int z = 0; z < nDepth; ++z ) { CPixelWriter pixelWriter; pixelWriter.SetPixelMemory( pVTFTexture->Format(), pVTFTexture->ImageData( 0, 0, 0, 0, 0, z ), pVTFTexture->RowSizeInBytes( 0 ) ); for ( int y = 0; y < nHeight; ++y ) { pixelWriter.Seek( 0, y ); for (int x = 0; x < nWidth; ++x) { RGBX5551_t inColor; inColor.r = x; inColor.g = y; inColor.b = z; color24 col = ColorCorrectionSystem()->GetLookup( m_ColorCorrectionHandle, inColor ); pixelWriter.WritePixel( col.r, col.g, col.b, 255 ); } } } }
void CProceduralRegenerator::WriteText(CPixelWriter &pixelWriter, const char *text, unsigned char **pixels, const chr_t *chars, const int &width, const int &height, int offsetY, const Color &color, bool isKeeper) { int offsetX = isKeeper ? 600 : 350; int totalWidth = 0; int maxHeight = 0; for (int i = strlen(text) - 1; i >= 0; i--) { const chr_t &chr = chars[text[i]]; totalWidth += chr.w; maxHeight = max(maxHeight, chr.h); } int posX = offsetX - totalWidth / 2; int posY = offsetY - maxHeight / 2; for (int i = strlen(text) - 1; i >= 0; i--) { const chr_t &chr = chars[text[i]]; for(int y = 0; y < chr.h; y++) { for(int x = 0; x < chr.w; x++) { pixelWriter.Seek(posX + x, offsetY + y); int srcY = chr.y + (chr.h - 1 - y); int srcX = chr.x + (chr.w - 1 - x); pixelWriter.WritePixel(color.r(), color.g(), color.b(), color.a() * (pixels[srcY][srcX] / 255.0f)); } } posX += chr.w; } }
void CProceduralRegenerator::RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) { CPixelWriter pixelWriter; pixelWriter.SetPixelMemory( pVTFTexture->Format(), pVTFTexture->ImageData(), pVTFTexture->RowSizeInBytes( 0 ) ); // Now upload the part we've been asked for int xmax = pSubRect->x + pSubRect->width; //int xmax = pVTFTexture->Width(); int ymax = pSubRect->y + pSubRect->height; //int ymax = pVTFTexture->Height(); int x, y; //x=250-450,y=275-325 for( y = pSubRect->y; y < ymax; ++y ) { pixelWriter.Seek( pSubRect->x, y ); for( x=pSubRect->x; x < xmax; ++x ) { int r=0, g=0, b=0, a=0; //pixelWriter.ReadPixelNoAdvance( r, g, b, a ); pixelWriter.WritePixel( r, g, b, a ); } } WriteText(pixelWriter, m_szShirtName, m_pFontAtlas->m_NamePixels, m_pFontAtlas->m_NameChars, m_pFontAtlas->m_nNamePixelsWidth, m_pFontAtlas->m_nNamePixelsHeight, m_nNameOffset, m_NameColor, m_bIsKeeper); WriteText(pixelWriter, m_szShirtNumber, m_pFontAtlas->m_NumberPixels, m_pFontAtlas->m_NumberChars, m_pFontAtlas->m_nNumberPixelsWidth, m_pFontAtlas->m_nNumberPixelsHeight, m_nNumberOffset, m_NumberColor, m_bIsKeeper); }
//----------------------------------------------------------------------------- // Default implementation of regenerate texture bits //----------------------------------------------------------------------------- void CProceduralTexturePanel::RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect ) { Assert( m_pImageBuffer ); Assert( pVTFTexture->FrameCount() == 1 ); Assert( pVTFTexture->FaceCount() == 1 ); Assert( !pTexture->IsMipmapped() ); int nWidth, nHeight, nDepth; pVTFTexture->ComputeMipLevelDimensions( 0, &nWidth, &nHeight, &nDepth ); Assert( nDepth == 1 ); Assert( nWidth == m_nWidth && nHeight == m_nHeight ); CPixelWriter pixelWriter; pixelWriter.SetPixelMemory( pVTFTexture->Format(), pVTFTexture->ImageData( 0, 0, 0 ), pVTFTexture->RowSizeInBytes( 0 ) ); for ( int y = 0; y < nHeight; ++y ) { pixelWriter.Seek( 0, y ); BGRA8888_t *pTexel = &m_pImageBuffer[y * m_nWidth]; for ( int x = 0; x < nWidth; ++x, ++pTexel ) { pixelWriter.WritePixel( pTexel->r, pTexel->g, pTexel->b, pTexel->a ); } } }
void CZZTextureRegen::RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) { //m_pProxy->GenerateCamoTexture( pTexture, pVTFTexture ); CPixelWriter pixelWriter; pixelWriter.SetPixelMemory( pVTFTexture->Format(), pVTFTexture->ImageData( 0, 0, 0 ), pVTFTexture->RowSizeInBytes( 0 ) ); // Now upload the part we've been asked for int xmax = pSubRect->x + pSubRect->width; int ymax = pSubRect->y + pSubRect->height; int x, y; for( y = pSubRect->y; y < ymax; ++y ) { pixelWriter.Seek( pSubRect->x, y ); for( x=pSubRect->x; x < xmax; ++x ) { pixelWriter.WritePixel( y%256, 0, 0, 255 ); } } }
virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) { // Normalization cubemap doesn't make sense on low-end hardware // So we won't construct a spheremap out of this CPixelWriter pixelWriter; Vector direction; for (int iFace = 0; iFace < 6; ++iFace) { pixelWriter.SetPixelMemory( pVTFTexture->Format(), pVTFTexture->ImageData( 0, iFace, 0 ), pVTFTexture->RowSizeInBytes( 0 ) ); int nWidth = pVTFTexture->Width(); int nHeight = pVTFTexture->Height(); float flInvWidth = 2.0f / (float)(nWidth-1); float flInvHeight = 2.0f / (float)(nHeight-1); for (int y = 0; y < nHeight; ++y) { float v = y * flInvHeight - 1.0f; pixelWriter.Seek( 0, y ); for (int x = 0; x < nWidth; ++x) { float u = x * flInvWidth - 1.0f; float oow = 1.0f / sqrt( 1.0f + u*u + v*v ); int ix = (int)(255 * 0.5 * (u*oow + 1.0f) + 0.5f); ix = clamp( ix, 0, 255 ); int iy = (int)(255 * 0.5 * (v*oow + 1.0f) + 0.5f); iy = clamp( iy, 0, 255 ); int iz = (int)(255 * 0.5 * (oow + 1.0f) + 0.5f); iz = clamp( iz, 0, 255 ); switch (iFace) { case CUBEMAP_FACE_RIGHT: ix = 255 - ix; iy = 255 - iy; break; case CUBEMAP_FACE_LEFT: iy = 255 - iy; iz = 255 - iz; break; case CUBEMAP_FACE_BACK: break; case CUBEMAP_FACE_FRONT: iy = 255 - iy; iz = 255 - iz; break; case CUBEMAP_FACE_UP: iy = 255 - iy; break; case CUBEMAP_FACE_DOWN: ix = 255 - ix; iy = 255 - iy; iz = 255 - iz; break; default: break; } ix -= 128; iy -= 128; iz -= 128; Assert( ix >= -128 && ix <= 127 ); Assert( iy >= -128 && iy <= 127 ); Assert( iz >= -128 && iz <= 127 ); switch (iFace) { case CUBEMAP_FACE_RIGHT: // correct // pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); pixelWriter.WritePixelSigned( iz, iy, ix, 0 ); break; case CUBEMAP_FACE_LEFT: // correct // pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); pixelWriter.WritePixelSigned( iz, iy, ix, 0 ); break; case CUBEMAP_FACE_BACK: // wrong // pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); pixelWriter.WritePixelSigned( ix, iz, iy, 0 ); // pixelWriter.WritePixelSigned( -127, -127, 127, 0 ); break; case CUBEMAP_FACE_FRONT: // wrong // pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); pixelWriter.WritePixelSigned( ix, iz, iy, 0 ); break; case CUBEMAP_FACE_UP: // correct // pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); pixelWriter.WritePixelSigned( ix, iy, iz, 0 ); break; case CUBEMAP_FACE_DOWN: // correct // pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); pixelWriter.WritePixelSigned( ix, iy, iz, 0 ); break; default: break; } } } } }