Texture channel separator node

Sub forum for feature requests etc
Post Reply
User avatar
grimm
Licensed Customer
Posts: 1332
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

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
OctaneRender Team
Posts: 1355
Joined: Thu Feb 01, 2018 7:10 pm

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:
ChannelSplitter.PNG
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;
}
User avatar
grimm
Licensed Customer
Posts: 1332
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

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
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
tcheng00
Octane Guru
Posts: 94
Joined: Mon Jul 29, 2019 8:33 pm
Location: USA
Contact:

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.
User avatar
grimm
Licensed Customer
Posts: 1332
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

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
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
OctaneRender Team
Posts: 1355
Joined: Thu Feb 01, 2018 7:10 pm

Yes, OSL doesn't provide acccess to Alpha yet.
Taksha
Licensed Customer
Posts: 16
Joined: Sat Apr 13, 2019 12:05 pm

:roll: :roll: :shock: damn... hope it will come soon!!!!
Workstation X3: WIN7 - 2x Xeon E5 | 64 GB | 2x RTX 2080ti
______
Hackintosh: WIN7/ OS X 10.8.5/ macOS 10.13.6 running Octane :) - 1x i7 4770K | 32 GB | 1x GTX 980ti
Post Reply

Return to “User Requests”