bool LightGrid::createTLITexture() { /* Create new buffer texture */ STextureCreationFlags CreationFlags; { CreationFlags.Size = 128;//1; CreationFlags.Format = PIXELFORMAT_GRAYALPHA; CreationFlags.HWFormat = HWTEXFORMAT_INT32; CreationFlags.BufferType = IMAGEBUFFER_UBYTE;//!!!IMAGEBUFFER_INT CreationFlags.Type = TEXTURE_BUFFER; } TLITexture_ = GlbRenderSys->createTexture(CreationFlags); #if 1//!!! ImageBuffer* buf = TLITexture_->getImageBuffer(); u32* rawbuf = reinterpret_cast<u32*>(buf->getBuffer()); for (u32 i = 0; i < 50; ++i) { if (i > 25) *(rawbuf++) = 100; else *(rawbuf++) = i; *(rawbuf++) = 0; } TLITexture_->updateImageBuffer(); #endif //... return true; }
void ImageBuffer::warpPerlin(Perlin &p) { // Make a copy of the current image buffer. This is used to preserve the original texture while the current texture is warped. ImageBuffer *newBuf = new ImageBuffer(_width, _height); memcpy(newBuf->getBuffer(), buffer, _width*_height*3*sizeof(float)); for(int row=0; row<_height; row++) for(int col=0; col<_width; col++) { // Make some noise at current pixel float x = (float)col/_width; float y = (float)row/_height; //float noise = p.noise(x,y,0.0f)*0.13f; float noise = 0.0f; vector<float> *octavesNoise = p.noise(x,y,0.0f); vector<float>::iterator i = octavesNoise->begin(); while(i != octavesNoise->end()) { noise += *i; i++; } delete octavesNoise; noise *= 0.13f; // Find noisey pixel position. If noise pushes pixel position beyond image dimension, wrap around. int noiseCol = static_cast<int>(col + _width*noise); if(noiseCol > _width-1) noiseCol -= _width; else if(noiseCol < 0) noiseCol += _width; int noiseRow = static_cast<int>(row + _height*noise); if(noiseRow > _height-1) noiseRow -= _height; else if(noiseRow < 0) noiseRow += _height; // Set noisy pixel position from copied buffer to current buffer setPixel( row, col, newBuf->getPixel(_height-1-noiseRow, noiseCol) ); } delete newBuf; }