mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-18 22:36:27 +01:00
pls help bill
This commit is contained in:
parent
270d785d27
commit
fac319a6dd
@ -1,4 +1,4 @@
|
|||||||
import { NitroFilter } from './proxy';
|
import { NitroFilter, NitroTexture } from './proxy';
|
||||||
|
|
||||||
const vertex = `
|
const vertex = `
|
||||||
attribute vec2 aVertexPosition;
|
attribute vec2 aVertexPosition;
|
||||||
@ -14,52 +14,81 @@ void main(void)
|
|||||||
const fragment = `
|
const fragment = `
|
||||||
varying vec2 vTextureCoord;
|
varying vec2 vTextureCoord;
|
||||||
uniform sampler2D uSampler;
|
uniform sampler2D uSampler;
|
||||||
uint8_t reds[256];
|
uniform sampler2D lut;
|
||||||
uint8_t greens[256];
|
uniform int channel;
|
||||||
uint8_t blues[256];
|
|
||||||
uint8_t alphas[256];
|
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
vec4 currentColor = texture2D(uSampler, vTextureCoord);
|
vec4 currentColor = texture2D(uSampler, vTextureCoord);
|
||||||
vec4 newColor =
|
if(channel == 0)
|
||||||
|
{
|
||||||
|
vec2 index = vec2(int(currentColor.r * 255.0), 0.5);
|
||||||
|
vec4 newColor = texture2D(lut, index);
|
||||||
|
gl_FragColor = vec4(newColor.r, newColor.g, newColor.b, currentColor.a);
|
||||||
|
} else if(channel == 1) {
|
||||||
|
vec2 index = vec2(int(currentColor.g * 255.0), 0.5);
|
||||||
|
vec4 newColor = texture2D(lut, index);
|
||||||
|
gl_FragColor = vec4(newColor.r, newColor.g, newColor.b, currentColor.a);
|
||||||
|
} else if(channel == 2) {
|
||||||
|
vec2 index = vec2(int(currentColor.b * 255.0), 0.5);
|
||||||
|
vec4 newColor = texture2D(lut, index);
|
||||||
|
gl_FragColor = vec4(newColor.r, newColor.g, newColor.b, currentColor.a);
|
||||||
|
} else if(channel == 3) {
|
||||||
|
vec2 index = vec2(int(currentColor.a * 255.0), 0.5);
|
||||||
|
vec4 newColor = texture2D(lut, index);
|
||||||
|
gl_FragColor = vec4(newColor.r, newColor.g, newColor.b, currentColor.a);
|
||||||
|
}
|
||||||
|
|
||||||
gl_FragColor = vec4(newColor.r, newColor.g, newColor.b, newColor.a);
|
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
export class PaletteMapFilter extends NitroFilter
|
export class PaletteMapFilter extends NitroFilter
|
||||||
{
|
{
|
||||||
private _reds: number[];
|
private _lut: NitroTexture;
|
||||||
private _greens: number[];
|
private _channel: number;
|
||||||
private _blues: number[];
|
|
||||||
private _alphas: number[];
|
|
||||||
|
|
||||||
constructor(reds: number[], greens: number[], blues: number[], alphas: number[])
|
constructor(reds: number[], greens: number[], blues: number[], alphas: number[])
|
||||||
{
|
{
|
||||||
super(vertex, fragment);
|
super(vertex, fragment);
|
||||||
|
this._channel = this.getChannelForPalette(reds, greens, blues, alphas);
|
||||||
this._reds = reds;
|
const lut = this.getLutForPalette(reds);
|
||||||
this._greens = greens;
|
this._lut = NitroTexture.fromBuffer(Uint8Array.from(lut), lut.length / 4, 1);
|
||||||
this._blues = blues;
|
this.uniforms.lut = this._lut;
|
||||||
this._alphas = alphas;
|
this.uniforms.channel = this._channel;
|
||||||
|
this.uniforms.lut.baseTexture.mipmap = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get reds(): number[]
|
private getLutForPalette(data: number[]): number[]
|
||||||
{
|
{
|
||||||
return this._reds;
|
const lut = [];
|
||||||
|
for(let i = 0; i < data.length; i++)
|
||||||
|
{
|
||||||
|
// R
|
||||||
|
lut[(i * 4)] = ((data[i] >> 16) & 0xFF) / 0xff;
|
||||||
|
// G
|
||||||
|
lut[(i * 4) + 1] = ((data[i] >> 8) & 0xFF) / 0xff;
|
||||||
|
// B
|
||||||
|
lut[(i * 4) + 2] = (data[i] & 0xFF) / 0xff;
|
||||||
|
// A
|
||||||
|
lut[(i * 4) + 3] = ((data[i] >> 24) & 0xFF) / 0xff;
|
||||||
|
}
|
||||||
|
console.log(lut);
|
||||||
|
return lut;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get blues(): number[]
|
private getChannelForPalette(reds: number[], greens: number[], blues: number[], alphas: number[]): number
|
||||||
{
|
{
|
||||||
return this._blues;
|
if(reds.length === 256) return 0;
|
||||||
|
if(greens.length === 256) return 1;
|
||||||
|
if(blues.length === 256) return 2;
|
||||||
|
if(alphas.length === 256) return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get greens(): number[]
|
public get lut(): NitroTexture
|
||||||
{
|
{
|
||||||
return this._greens;
|
return this._lut;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get alphas(): number[]
|
public get channel(): number
|
||||||
{
|
{
|
||||||
return this._alphas;
|
return this._channel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user