Texture channel separator node
It would be really nice to have a node that will allow you to extract a single (or several) channels from a image texture. One area in particular is to strip off the alpha channel to use for opacity. In most cases the alpha is embedded in the Diffuse or Albedo texture and you have to set up a Alpha Image Tex node. To have a channel separator node would be nice in the case of Blender's node groups, instead of having to setup the Alpha Image Tex node external to the group, you can just separate out the alpha channel and plug it into the Opacity pin.
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
- linograndiotoy
- Posts: 1355
- Joined: Thu Feb 01, 2018 7:10 pm
We can do that already using OSL.grimm wrote:It would be really nice to have a node that will allow you to extract a single (or several) channels from a image texture. One area in particular is to strip off the alpha channel to use for opacity. In most cases the alpha is embedded in the Diffuse or Albedo texture and you have to set up a Alpha Image Tex node. To have a channel separator node would be nice in the case of Blender's node groups, instead of having to setup the Alpha Image Tex node external to the group, you can just separate out the alpha channel and plug it into the Opacity pin.
You can download the Channel Splitter node from the LiveDB: There are many other very useful nodes there.
This is the script:
// RGB Channel Split as Grayscale
// Author: Thomas Cheng - Ambocc Studios
// www.ambocc.com - [email protected]
//
// 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;
}
Thanks Lino,
Unfortunately this does not work. I need to extract the alpha texture, which I'm assuming is the fourth channel, or in this case rgbTexture(3). I get a index out of range error, I'm thinking that it's because the rgbTexture function only allows 3 channels. I tried a rgbaTexture but there is no function.
Here is how I modified the script to try and get it to work.
Also I wasn't able to find the rgbTexture function in the OSL documentation, is that a Octane only function?
Jason
Unfortunately this does not work. I need to extract the alpha texture, which I'm assuming is the fourth channel, or in this case rgbTexture(3). I get a index out of range error, I'm thinking that it's because the rgbTexture function only allows 3 channels. I tried a rgbaTexture but there is no function.

Here is how I modified the script to try and get it to work.
Code: Select all
// RGB Channel Split as Grayscale
// Author: Thomas Cheng - Ambocc Studios
// www.ambocc.com - [email protected]
//
// 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
#define CHANNEL_A 4
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|A:4"]],
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 if (channel == CHANNEL_A)
out = rgbTexture[3];
else
out = 0;
}
Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
It can’t be done in the splitter. It’s the way the texture file is loaded before it gets to the OSL script. Maybe in the future the dev will add the feature. Most likely it was done this way because the alpha is generally ignored most of the time and therefore why not save some processing time and memory. For now, the alpha image node is your best bet.
Last edited by tcheng00 on Sat Mar 07, 2020 6:44 am, edited 1 time in total.
Thanks Thomas,
I suspected that was the case, I too hope that they will add this in. It makes building textures a little bit more difficult.
Jason
I suspected that was the case, I too hope that they will add this in. It makes building textures a little bit more difficult.
Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
- linograndiotoy
- Posts: 1355
- Joined: Thu Feb 01, 2018 7:10 pm
Yes, OSL doesn't provide acccess to Alpha yet.