Page 1 of 1
Texture channel separator node
Posted: Fri Mar 06, 2020 8:00 am
by grimm
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.
Re: Texture channel separator node
Posted: Fri Mar 06, 2020 11:56 am
by linograndiotoy
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.
We can do that already using OSL.
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;
}
Re: Texture channel separator node
Posted: Fri Mar 06, 2020 7:27 pm
by grimm
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.
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;
}
Also I wasn't able to find the rgbTexture function in the OSL documentation, is that a Octane only function?
Jason
Re: Texture channel separator node
Posted: Fri Mar 06, 2020 11:16 pm
by tcheng00
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.
Re: Texture channel separator node
Posted: Sat Mar 07, 2020 1:19 am
by grimm
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
Re: Texture channel separator node
Posted: Thu Mar 12, 2020 1:04 pm
by linograndiotoy
Yes, OSL doesn't provide acccess to Alpha yet.
Re: Texture channel separator node
Posted: Sun Mar 15, 2020 3:53 pm
by Taksha