Access an image's RGB channels independently?

Forums: Access an image's RGB channels independently?
Blender (Export script developed by yoyoz; Integrated Plugin developed by JimStar)

Access an image's RGB channels independently?

Postby pegot » Fri Aug 31, 2018 2:33 am

pegot Fri Aug 31, 2018 2:33 am
Is there any way in Octane Blender to split an image’s RGB channels? Cycles has a "Separate RGB" node that allows this and it is very useful when working with textures exported from Substance Painter for use with glTF files, which embed Metal, Roughness, and Occlusion info into separate RGB channels.
Win 10
3.7Ghz i9 10900k / 64GB
ASUS STRIX Z490-E
PSU: PowerSpec 850Wd
RTX 3090 Asus Tuff

Network rendering:
Win 10
4.2Ghz i7 7700k / 64GB
AsRock SuperCarrier
PSU: EVGA 1200w
RTX 3080 Ti EVGA Hybrid
RTX 3080 ASUS Tuff
GTX 1080ti SC Black (wc)
pegot
Licensed Customer
Licensed Customer
 
Posts: 921
Joined: Mon Nov 07, 2011 3:44 am

Re: Access an image's RGB channels independently?

Postby J.C » Fri Aug 31, 2018 11:33 am

J.C Fri Aug 31, 2018 11:33 am
It should be possible to do this in Blender's compositor.
CPU – i9 13900KF, 128GB RAM, GPU – RTX 4090
System – Windows 11
My Behance portfolio, Blender plugin FB support group
J.C
Licensed Customer
Licensed Customer
 
Posts: 1721
Joined: Thu May 13, 2010 6:35 pm
Location: Wrocław

Re: Access an image's RGB channels independently?

Postby milanm » Fri Aug 31, 2018 2:47 pm

milanm Fri Aug 31, 2018 2:47 pm
Did this in 5 min, it should do the trick. Watch out for gamma!
Gotta go now... deadlines... stress... dead GPUs... 18-hour days... I am so pale I got more nits than a BVM-X300 !

OSL code:
Code: Select all
shader mm_RGBSplit(
    color in = 0,
    float red = 0 [[float min=0, float max=1]],
    float green = 0 [[float min=0, float max=1]],
    float blue = 0 [[float min=0, float max=1]],
    output color c = 0)
{
    c = in[0]*red+in[1]*green+in[2]*blue;
}


Regards
Milan
Colorist / VFX artist / Motion Designer
macOS - Windows 7 - Cinema 4D R19.068 - GTX1070TI - GTX780
milanm
Licensed Customer
Licensed Customer
 
Posts: 261
Joined: Tue Apr 30, 2013 7:23 pm

Re: Access an image's RGB channels independently?

Postby pegot » Mon Sep 03, 2018 11:10 pm

pegot Mon Sep 03, 2018 11:10 pm
milanm wrote:Did this in 5 min, it should do the trick. Watch out for gamma!
Gotta go now... deadlines... stress... dead GPUs... 18-hour days... I am so pale I got more nits than a BVM-X300 !

OSL code:
Code: Select all
shader mm_RGBSplit(
    color in = 0,
    float red = 0 [[float min=0, float max=1]],
    float green = 0 [[float min=0, float max=1]],
    float blue = 0 [[float min=0, float max=1]],
    output color c = 0)
{
    c = in[0]*red+in[1]*green+in[2]*blue;
}


Regards
Milan

Thanks! This worked perfectly and was very easy to use. My first time trying an OSL shader. Very cool.
Win 10
3.7Ghz i9 10900k / 64GB
ASUS STRIX Z490-E
PSU: PowerSpec 850Wd
RTX 3090 Asus Tuff

Network rendering:
Win 10
4.2Ghz i7 7700k / 64GB
AsRock SuperCarrier
PSU: EVGA 1200w
RTX 3080 Ti EVGA Hybrid
RTX 3080 ASUS Tuff
GTX 1080ti SC Black (wc)
pegot
Licensed Customer
Licensed Customer
 
Posts: 921
Joined: Mon Nov 07, 2011 3:44 am

Re: Access an image's RGB channels independently?

Postby frankmci » Tue Sep 04, 2018 2:48 pm

frankmci Tue Sep 04, 2018 2:48 pm
This is super-handy and really should be a standard node for Octane, in my opinion. I thought it would be easy for me to poke around a bit and add alpha channel support for this, but of course, it's never that easy.

From what I've been able to gather in the Octane OSL docs
https://docs.otoy.com/osl/
the "color" variable only supports RGB. More poking around the net seems to show quite a bit of head scratching when it comes to calling the alpha channel data in various implementations of OSL. The best I can tell, to get the alpha data from an image you need to use the "texture" attribute, along with the "channels" attribute, although it's unclear to me whether that will just return the number of channel present in a texture, or if it will allow you to call those channels individually.

This OSL script written for VRay seems to handle alphas just fine in a multi blend mode type system (which would be great in Octane), but it's far beyond my meager script cobbling abilities to untangle.

https://forums.chaosgroup.com/forum/v-r ... usal/page2
http://www.rensheeren.com/osl/merge2_tex_v001.osl

Then there's this that looks prommising
https://github.com/imageworks/OpenShadi ... a/test.osl

Anyway, what I imagined was going to be as simple as adding one float input and one more term in the c output equation has turned out to be well beyond my skill level. If anyone with a better understanding of these things wants to take a shot at it, it would be much appreciated.

I should also say that the current code with RGB only works fine in C4D, where I am now putting it to good use. Thank you!

- Frank
Technical Director - C4D, Maya, AE, - Washington DC
frankmci
Licensed Customer
Licensed Customer
 
Posts: 821
Joined: Fri May 26, 2017 2:00 pm

Re: Access an image's RGB channels independently?

Postby calus » Tue Sep 04, 2018 3:29 pm

calus Tue Sep 04, 2018 3:29 pm
frankmci wrote:This is super-handy and really should be a standard node for Octane, in my opinion.

OSL can be more handy but you can achieve the exact same result as Milanm's OSL shader with Octane math nodes:
- use "multiply" nodes by pure red, green, blue color to get the 3 color channels from greyscal textures,
- then use the "add" node to get the final RGB color.
Pascal ANDRE
calus
Licensed Customer
Licensed Customer
 
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: Access an image's RGB channels independently?

Postby frankmci » Tue Sep 04, 2018 4:41 pm

frankmci Tue Sep 04, 2018 4:41 pm
calus wrote:
frankmci wrote:This is super-handy and really should be a standard node for Octane, in my opinion.

OSL can be more handy but you can achieve the exact same result as Milanm's OSL shader with Octane math nodes:
- use "multiply" nodes by pure red, green, blue color to get the 3 color channels from greyscal textures,
- then use the "add" node to get the final RGB color.


Yes, thanks, that's close to the method I've been using, but at least in the C4D implementation of the node graph, things get messy fast in even moderately complex shader networks. To perform the same function with one node instead of four, for something I use all the time, will help keep me sane. Not to go down the "this other program does it this way..." road, but as a Maya user for 20 years, I've gotten so used to having access to individual RGBA channels by default out of every image file node, that rebuilding what seems like a very basic function every time gets awfully tedious.
Technical Director - C4D, Maya, AE, - Washington DC
frankmci
Licensed Customer
Licensed Customer
 
Posts: 821
Joined: Fri May 26, 2017 2:00 pm

Re: Access an image's RGB channels independently?

Postby AndreasResch » Wed Sep 05, 2018 6:21 am

AndreasResch Wed Sep 05, 2018 6:21 am
I also wish there were more "tool" nodes for Octane. That's what makes the Blender node system so powerful. Splitting and combining nodes is just the beginning. Randomization would be awesome and something like the "Object Info" node in Blender would be great as well. Then there are Math nodes, Vector nodes ...

OSL nodes could be a workaround, but they are still missing flexibility compared to the OSL implemetation of other shaders. I tried to use some from 3DS Max, but most of them (even simple ones) don't work at the moment.
AndreasResch
Licensed Customer
Licensed Customer
 
Posts: 78
Joined: Wed Jul 25, 2018 4:53 pm

Re: Access an image's RGB channels independently?

Postby sbstnc » Thu Nov 01, 2018 4:58 am

sbstnc Thu Nov 01, 2018 4:58 am
I had a quick look at the docs but can't work this out, can someone school me on how to apply this?
Drag in an OSL node, paste the code into it, how do you get the image input pin though? There's no pin to connect an image on the left.
Hitting compile does nothing either. What am I missing here?
sbstnc
Licensed Customer
Licensed Customer
 
Posts: 120
Joined: Mon Jul 25, 2016 1:21 am

Re: Access an image's RGB channels independently?

Postby frankmci » Thu Nov 01, 2018 5:46 pm

frankmci Thu Nov 01, 2018 5:46 pm
sbstnc wrote:I had a quick look at the docs but can't work this out, can someone school me on how to apply this?
Drag in an OSL node, paste the code into it, how do you get the image input pin though? There's no pin to connect an image on the left.
Hitting compile does nothing either. What am I missing here?


OSL nodes seem to need to be connected to shaders that are applied to geometry before they will compile. Octane doesn't "know" to compile the OSL node unless it's actually called by the render, at least the first time. They seem to stay properly compiled and saved in the scene file, even if the shader subsequently removed from all geometry.
Technical Director - C4D, Maya, AE, - Washington DC
frankmci
Licensed Customer
Licensed Customer
 
Posts: 821
Joined: Fri May 26, 2017 2:00 pm

Return to Blender


Who is online

Users browsing this forum: No registered users and 9 guests

Fri Apr 19, 2024 1:17 am [ UTC ]