1
Fork 0

Speed up rendering (not by much) using Shape2D and a RGB8 LUT.

This commit is contained in:
Marisa the Magician 2023-10-09 12:57:25 +02:00
commit e2e9b75d31
2 changed files with 45 additions and 4 deletions

BIN
RGB8LUT.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View file

@ -81,6 +81,10 @@ class FireTexture
private Array<FireSpark> sparks;// all the active sparks
private bool bhasstars; // true if any sparks with type SPARK_Stars exist
private Shape2D blitter; // the shape used to map pixels to palette indices
private TextureID blittertx; // the texture used for mapping to the palette
private Vector2 blitterlut[256]; // for fast color uv matching
// parses a fire texture from a file
static FireTexture Load( string path )
{
@ -207,9 +211,46 @@ class FireTexture
void Render()
{
// blit to canvas, one pixel at a time (oof)
for ( uint y=0; y<height; y++ )
for ( uint x=0; x<width; x++ )
cv.Clear(x,y,x+1,y+1,GetPixelRGB(x,y));
// create the blitter if it doesn't exist
if ( !blitter )
{
blittertx = TexMan.CheckForTexture("RGB8LUT");
blitter = new("Shape2D");
// one quad at a time
int baseidx = 0;
for ( uint y=0; y<height; y++ ) for ( uint x=0; x<width; x++ )
{
blitter.PushVertex((x,y));
blitter.PushVertex((x+1,y));
blitter.PushVertex((x,y+1));
blitter.PushVertex((x+1,y+1));
// CCW triangles with origin at top left
blitter.PushTriangle(baseidx,baseidx+3,baseidx+1);
blitter.PushTriangle(baseidx,baseidx+2,baseidx+3);
baseidx += 4;
}
// prepare the lut
for ( int i=0; i<256; i++ )
{
double x = pal[i].r+((pal[i].g/16)*256)%4096;
double y = (pal[i].g/16)+(pal[i].b*16);
blitterlut[i] = (x,y)/4096.+(1.,1.)/8192.;
}
}
// remap Shape2D UVs
uint pxcnt = width*height;
Vector2 c;
blitter.Clear(Shape2D.C_Coords);
for ( uint i=0; i<pxcnt; i++ )
{
// centered on the grid
c = blitterlut[pixels[i]];
blitter.PushCoord(c);
blitter.PushCoord(c);
blitter.PushCoord(c);
blitter.PushCoord(c);
}
// blit Shape2D
cv.DrawShape(blittertx,false,blitter);
}
}