【问题标题】:game maker - how to swap the color palette using shaders and texture [duplicate]游戏制作者-如何使用着色器和纹理交换调色板[重复]
【发布时间】:2016-09-26 14:24:14
【问题描述】:

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

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

https://en.wikipedia.org/wiki/List_of_8-bit_computer_hardware_palettes#/media/File: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 );
}

谢谢

【问题讨论】:

    标签: glsl shader fragment-shader game-maker gml


    【解决方案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)
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-12
      • 2018-09-10
      • 2013-09-17
      • 1970-01-01
      • 2020-04-16
      • 2019-01-12
      • 1970-01-01
      • 2014-11-25
      相关资源
      最近更新 更多