方法一

shader RGBSplit(

    color tex = 0,

    int red = 0 [[int min=0, int max=1]],

    int green = 0 [[int min=0, int max=1]],

    int blue = 0 [[int min=0, int max=1]],

    output color c = 0)

{

    c = tex[0]*red+tex[1]*green+tex[2]*blue;

}

方法二

// RGB Channel Split as Grayscale
// Author: Thomas Cheng - Ambocc Studios
// www.ambocc.com - info@ambocc.com
//
// Description: Connect a RGB texture and select the color channel to output as a grayscale image.

#define CHANNEL_R 1
#define CHANNEL_G 2
#define CHANNEL_B 3

shader ChannelExtractor(
color rgbTexture = 0 [[ string label = "texture"]],
int channel = 1 [[string widget = "mapper", string label = "Channel", string options = "R:1|G:2|B:3"]],
output color out = 0,
)
{
if (channel == CHANNEL_R)
out = rgbTexture[0];
else if (channel == CHANNEL_G)
out = rgbTexture[1];
else if (channel == CHANNEL_B)
out = rgbTexture[2];
else
out = 0;
}

方法三

shader get_vector_component
(
    color map = 0,
    int channel = 0 [[float min = 0,float max = 2]],
    output color c = 0,
)

{
    c = map[channel];
}