如何使用纹理??
更改应用程序表面的颜色https://en.wikipedia.org/wiki/List_of_8-bit_computer_hardware_palettes
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 );
}
感谢
答案 0 :(得分:1)
这可以通过许多不同的方式来解决,但是,一种简单的方法是为当前调色板中的两种颜色和替换颜色创建制服。例如;
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)
扩展这个你可以创建一个精灵并可能为制服采样,无论如何希望这有帮助!