游戏制造者-如何使用着色器和纹理交换调色板



如何改变应用表面的颜色,使用纹理??

https://en.wikipedia.org/wiki/List_of_8-bit_computer_hardware_palettes

https://en.wikipedia.org/wiki/List_of_8-bit_computer_hardware_palettes/媒体/文件:CGA_palette_color_test_chart.png

https://upload.wikimedia.org/wikipedia/commons/c/c5/CGA_palette_color_test_chart.png

我的片段着色器是这样开始的:

varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
    gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
}

谢谢

这可以通过许多不同的方式实现,然而,一个简单的方法是为当前调色板中的颜色和替代颜色创建制服。例如,

uniform vec3 rep1;
uniform vec3 rep2;
uniform vec3 rep3;
uniform vec3 new1;
uniform vec3 new2;
uniform vec3 new3;

然后你可以检查采样像素是否是你要替换的颜色之一,如果是,则传递新颜色;

//Sample the original pixel
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
//Make it easier to compare (out of 255 instead of 1)
vec3 test = vec3(
    gl_FragColor.r * 255.0,
    gl_FragColor.g * 255.0, 
    gl_FragColor.b * 255.0
);
//Check if it needs to be replaced
if (test == rep1) {test = new1;}
if (test == rep2) {test = new2;}
if (test == rep3) {test = new3;}
//return the result in the original format
gl_FragColor = vec4(
    test.r / 255.0,
    test.g / 255.0,
    test.b / 255.0,
    gl_FragColor.a
);

然后在你的房间创建代码(或其他初始化代码)中,你可以设置着色器并定义要替换的调色板和要替换的内容,例如:

// -- Set Pallete --
shader_set(sPalleter)
//Red
shader_set_uniform_f(shader_get_uniform(sPalleter, "rep1"), 255, 0, 0)
shader_set_uniform_f(shader_get_uniform(sPalleter, "new1"), 155, 188, 15)
//White
shader_set_uniform_f(shader_get_uniform(sPalleter, "rep2"), 255, 255, 255)
shader_set_uniform_f(shader_get_uniform(sPalleter, "new2"), 48, 98, 48)
//Black
shader_set_uniform_f(shader_get_uniform(sPalleter, "rep3"), 0, 0, 0)
shader_set_uniform_f(shader_get_uniform(sPalleter, "new3"), 15, 56, 15)

扩展这一点,你可以创建一个精灵,并可能为制服取样,无论如何希望这有助于!

最新更新