shader works for all channel paletttes now

This commit is contained in:
dank074 2021-09-01 13:02:09 -05:00
parent 738ab335fe
commit 8d14854b4e

View File

@ -25,17 +25,13 @@ void main(void) {
{ {
if(channel == 0) if(channel == 0)
{ {
vec2 index = vec2(currentColor.r, 0.5); adjusted = texture2D(lut, vec2(currentColor.r, 0.5));
adjusted = texture2D(lut, index);
} else if(channel == 1) { } else if(channel == 1) {
vec2 index = vec2(currentColor.g, 0.5); adjusted = texture2D(lut, vec2(currentColor.g, 0.5));
adjusted = texture2D(lut, index);
} else if(channel == 2) { } else if(channel == 2) {
vec2 index = vec2(currentColor.b, 0.5); adjusted = texture2D(lut, vec2(currentColor.b, 0.5));
adjusted = texture2D(lut, index);
} else if(channel == 3) { } else if(channel == 3) {
vec2 index = vec2(currentColor.a, 0.5); adjusted = texture2D(lut, vec2(currentColor.a, 0.5));
adjusted = texture2D(lut, index);
} }
} }
@ -44,6 +40,11 @@ void main(void) {
export class PaletteMapFilter extends NitroFilter export class PaletteMapFilter extends NitroFilter
{ {
public static readonly CHANNEL_RED = 0;
public static readonly CHANNEL_GREEN = 1;
public static readonly CHANNEL_BLUE = 2;
public static readonly CHANNEL_ALPHA = 3;
private _lut: NitroBasetexture; private _lut: NitroBasetexture;
private _channel: number; private _channel: number;
@ -51,7 +52,24 @@ export class PaletteMapFilter extends NitroFilter
{ {
super(vertex, fragment); super(vertex, fragment);
this._channel = this.getChannelForPalette(reds, greens, blues, alphas); this._channel = this.getChannelForPalette(reds, greens, blues, alphas);
const lut = this.getLutForPalette(reds); let lut: number[] = [];
switch(this._channel)
{
case (PaletteMapFilter.CHANNEL_RED):
lut = this.getLutForPalette(reds);
break;
case (PaletteMapFilter.CHANNEL_GREEN):
lut = this.getLutForPalette(greens);
break;
case (PaletteMapFilter.CHANNEL_BLUE):
lut = this.getLutForPalette(blues);
break;
case (PaletteMapFilter.CHANNEL_ALPHA):
lut = this.getLutForPalette(alphas);
break;
}
this._lut = NitroBasetexture.fromBuffer(Uint8Array.from(lut), lut.length / 4, 1); this._lut = NitroBasetexture.fromBuffer(Uint8Array.from(lut), lut.length / 4, 1);
this.uniforms.lut = this._lut; this.uniforms.lut = this._lut;
@ -65,13 +83,13 @@ export class PaletteMapFilter extends NitroFilter
for(let i = 0; i < data.length; i++) for(let i = 0; i < data.length; i++)
{ {
// R // R
lut[(i * 4)] = ((data[i] >> 16) & 0xFF); lut[(i * 4) + PaletteMapFilter.CHANNEL_RED] = ((data[i] >> 16) & 0xFF);
// G // G
lut[(i * 4) + 1] = ((data[i] >> 8) & 0xFF); lut[(i * 4) + PaletteMapFilter.CHANNEL_GREEN] = ((data[i] >> 8) & 0xFF);
// B // B
lut[(i * 4) + 2] = (data[i] & 0xFF); lut[(i * 4) + PaletteMapFilter.CHANNEL_BLUE] = (data[i] & 0xFF);
// A // A
lut[(i * 4) + 3] = ((data[i] >> 24) & 0xFF); lut[(i * 4) + PaletteMapFilter.CHANNEL_ALPHA] = ((data[i] >> 24) & 0xFF);
} }
return lut; return lut;
@ -79,10 +97,10 @@ export class PaletteMapFilter extends NitroFilter
private getChannelForPalette(reds: number[], greens: number[], blues: number[], alphas: number[]): number private getChannelForPalette(reds: number[], greens: number[], blues: number[], alphas: number[]): number
{ {
if(reds.length === 256) return 0; if(reds.length === 256) return PaletteMapFilter.CHANNEL_RED;
if(greens.length === 256) return 1; if(greens.length === 256) return PaletteMapFilter.CHANNEL_GREEN;
if(blues.length === 256) return 2; if(blues.length === 256) return PaletteMapFilter.CHANNEL_BLUE;
if(alphas.length === 256) return 3; if(alphas.length === 256) return PaletteMapFilter.CHANNEL_ALPHA;
} }
public get lut(): NitroBasetexture public get lut(): NitroBasetexture