As a coder for 35+ years this really opens some doors for me. Once I realized that using blender shading nodes was just a metaphor for code, they made alot morse sense. With OSL, the gloves are off!
Million thanks to you for all your quirky and more normal tuts. You are a major influence on my interest in learning Blender as you are perhaps the best at actually demonstrating concepts and showing its potential while remaining entertaining.
I appreciate you describing what the parenthesis and brackets are for. So many coding tutorials I've watched have never done me the service of explaining such basic elements, and it immediately made me feel like I understood things 10x more once I knew.
Fyi, VS Code has an OSL extension to help with editing Open Shader scripts called "OSL Support" that helps if you want to edit outside of blender. If you want to edit inside of blender, save your file with an .osl extension to get the correct highlighting.
While I’m probably not going to learn much from this series myself, since I’ve already worked with tons of other programming languages (including shader languages like GLSL and GDSL), I do appreciate that you’re making this more accessible to everyone! Keep it up!
Ah heck yeah, as a programmer I'm insanely impressed with how good you are at explaining complex topics like this. Genuinely super excited for the rest of this series, you're making a super useful contribution to the internet!
Thanks a lot CGMatter! But please, inside those Curly Braces, pls use tab for every statement you put there; just a C-style convention and it will make code much more readable
i never clicked so hard on one of your tutorials. ever since you half-assed that OSL Fractal Shader tutorial, I've been dying for a proper OSL tutorial. So happy you are teaching this!!!
Wonderful! I remember hearing about OSL years ago. I even have a blend file that has something to do with it but I don’t remember if it was a download from somewhere or what. I knew it was something I needed because sometimes you need something more than a node group will provide. But I never saw anyone explain how to even do anything about it, and I forgot about it, so I’m glad someone is finally doing something about that, thank you! Definitely looking forward to the rest of the series!
I have used OSL to create some fractal textures. They are quite fast even on CPU (compared to a slightly optimized Numpy implementation) but the downside is that they are based on float32, which limits the zoom.
@@tiagotiagot According to the language specification, `double` is reserved as a keyword but not in use currently, and float is " guaranteed to be at least IEEE 32-bit float (the standard C float data type)". And Blender mainly use float32 for calculation (based on a post in the Blender Developer Forum)
That'a a natural evolution of geonodes; it should allow us to create less messy or tangled nodes. I guess we could have or customized nodes, am I right? Cool stuff as usual.
It's actually the opposite, kinda. Because Geonodes is rather "visual scripting", or something like this. Like you could write various scripts to generate geometry in Blender, and now you can just use nodes. OSL... Actually, it was in Blender for a long time (at least, I saw some semi-tutorials on it). But rather as "experimental" feature. It looks like, they added it to "supported" category. Interesting thing is that it's not Blender exclusive thing, but something like open standard, used by various renderers. For example, 3Delight uses it now days. Before, it used RSL (Renderman Shading Language). But I don't really know how useful it is, now days. And how hard it is. Like it (RSL) was really technical, because you was writing all the math behind shaders. Yep. Shading models, generated textures and all the other stuff. Meanwhile, considering that usually PBR are used... But on the other hand, it looks like, it can be really useful for creating various shader nodes, to be used with other ones. Which can be easier, and maybe even much more productive. (And fun?)
Oh god, I needed this so much. I'm new to blender and pulling my hair out figuring out how to do what. The zoom locks weirdly, typing x to indicate axis threatens to delete objects if my mouse was outside the area when I typed the g or r or s or whatever... and the nodes don't make any sense beyond the basic texture stuff. Coding is way easier. Can totally imagine randomising being really simple like this. Say... for instance colours. You've probably prevented my breakup with blender. Nah. i wouldn't have given up, but this makes things simpler.
This is great! Finally, someone explaining the basics of OSL shading. It's super helpful. I'd love to see the process of converting or adapting OSL shaders made for Octane/Redshift to Cycles. Understand what the difference of making OSL for different render engines if any and how to properly convert them. Thanks a lot for the series!
I am active in a couple of opensource projects, most are by and for developers. And hence code is not something dirty (in a bad way :")). Blender is differnet in the way that a very high percentage of the users cant code. By it self fine, but different
you're right, i guess it not many ppl want to give it a try. Thank u for supporting opensource projects. I dont know how to code but i see the potential in the OSL so here i go!
This is going to make things quite different for me. For me it's just easier to write code than use visual blocks. And this seems like a simple way to use same properties on multiple files when everything is just on different script files
Woah this is actually quite interesting, I can compress or make huge shader trees into just single node, and it might be more faster. I hope there is some possibility of optimizing processing time compared to normal nodes.
While ChatGPT is a great tool, this code needs work. *N* is a global variable, so normal N = normalize(N); will produce an error: "N" already declared in this scope
Thanks for this, and all Your other tutorials. Though I have a question/note regarding the "GPU compatibility" ? I'm on Linux (Pop OS 22.04), and to be able to enable GPU AND OSL I have to enable "OPTIX" in the "Edit>>Preferences >> system>>Cycles Render Devices". If I have it set at "CUDA" the "TickBox" for "Open Shading Language" disappears if I choose "Device GPU"... Is this a "Linux issue", or is it the same on other "platforms".... Or is it just "me" ??
Same thing, I have a GeForce 1070 with CUDA enabled, if I enable GPU Complete then the open shading tick box goes away, still don't have an answer even now
@@edgarhammond2252 Same card, very similar issue. No idea what's going wrong but this card is at the very bottom of the min spec. Hope it gets improvements eventually because according to NVIDIA, Optix should work on this class of card with new drivers.
I'm super excited for this, just as you say, I've never seen a comprehensive introduction to OSL or any other SL in blender -aside from a video of yours from a while back-, and that's really a shame because this is really how I prefer to interact with code, as opposed to nodes
I couldn't get OSL working with GPU in 3.5. If anyone's having this issue, I figured it out - go into edit>preferences>system and turn off your gpu for cuda, but then make sure its turned on for optix
It would be a better idea for beginners if you wrote all parameters in one line instead of separating them, so they are distinguished from the shader (or I guess function) body where we use semicolon.
#Respect for writing "abcd" instead of "asdf" :D Very cool tutorial, I've always wanted to know what is OSL in practice and what are its benefits... what are its benefits? formulating a complex set of nodes into one shader that is easy more compatible with other sofwares?
Not sure if you have ever thought of doing a follow up video on this. But this work flow works stupidly well with ChatGPT. The blender implementation is kinda bad. The play button being python instead of refreshing is confusing, having to be in the correct view or getting black renders is confusing. Not working in EEVEE is confusing. Hitting the run button and getting a python error that tells you nothing is confusing. But once you get it working it's awsome. shader FadeBetweenMasks( int HV = 0, // 0 for vertical, 1 for horizontal float FadeAmount = 0.5, color ImageA = 1, color ImageB = 0, color MaskA = 1, color MaskB = 1, output color OutColor = 0 ) { float fadeCoord;
if (HV == 0) { // Vertical fade fadeCoord = (P.y + 0.5) / FadeAmount; } else { // Horizontal fade fadeCoord = (P.x + 0.5) / FadeAmount; } float fadeFactor = smoothstep(0, 1, fadeCoord); color maskedImageA = mix(ImageA, ImageB, fadeFactor); OutColor = mix(MaskA, MaskB, fadeFactor) * maskedImageA; } I got chat GPT to spit that out with some prompts. It's not exactly what I wanted first shot but with some mucking around you can get some complicated stuff in 1 node with some simple talking with GPT. You can also use GPT to say convert GLSL scripts to OSL It's not 100% but it does give you a lot of possibilities if you say like a shadertoy example. You can bake out the textures for use with eevee or other stuff once you get something you want.
Oh neat. The last time I touched OSL was in 2.9 and saw it was CPU only so I threw that to the garbage bin. The performance hits for doing anything complex compared to the shader nodes themselves wasn't worth it.
As a coder for 35+ years this really opens some doors for me. Once I realized that using blender shading nodes was just a metaphor for code, they made alot morse sense. With OSL, the gloves are off!
Yeah, you can think of nodes like functional programming or shell pipelines.
Is it worth it being a coder? What do you do? How much do you make a month?
Million thanks to you for all your quirky and more normal tuts. You are a major influence on my interest in learning Blender as you are perhaps the best at actually demonstrating concepts and showing its potential while remaining entertaining.
I appreciate you describing what the parenthesis and brackets are for. So many coding tutorials I've watched have never done me the service of explaining such basic elements, and it immediately made me feel like I understood things 10x more once I knew.
Fyi, VS Code has an OSL extension to help with editing Open Shader scripts called "OSL Support" that helps if you want to edit outside of blender. If you want to edit inside of blender, save your file with an .osl extension to get the correct highlighting.
While I’m probably not going to learn much from this series myself, since I’ve already worked with tons of other programming languages (including shader languages like GLSL and GDSL), I do appreciate that you’re making this more accessible to everyone! Keep it up!
i think i've seen dedouze use this, but i never know what it was. thanks a lot for this
Ah heck yeah, as a programmer I'm insanely impressed with how good you are at explaining complex topics like this. Genuinely super excited for the rest of this series, you're making a super useful contribution to the internet!
Thanks a lot CGMatter! But please, inside those Curly Braces, pls use tab for every statement you put there; just a C-style convention and it will make code much more readable
i never clicked so hard on one of your tutorials. ever since you half-assed that OSL Fractal Shader tutorial, I've been dying for a proper OSL tutorial. So happy you are teaching this!!!
Wonderful! I remember hearing about OSL years ago. I even have a blend file that has something to do with it but I don’t remember if it was a download from somewhere or what. I knew it was something I needed because sometimes you need something more than a node group will provide. But I never saw anyone explain how to even do anything about it, and I forgot about it, so I’m glad someone is finally doing something about that, thank you! Definitely looking forward to the rest of the series!
I have used OSL to create some fractal textures. They are quite fast even on CPU (compared to a slightly optimized Numpy implementation) but the downside is that they are based on float32, which limits the zoom.
It doesn't support doubles?
@@tiagotiagot According to the language specification, `double` is reserved as a keyword but not in use currently, and float is " guaranteed to be at least IEEE 32-bit float (the standard C float data type)". And Blender mainly use float32 for calculation (based on a post in the Blender Developer Forum)
This is my main experience with OSL too, and also frustrated by the lack of double precision floats.
That'a a natural evolution of geonodes; it should allow us to create less messy or tangled nodes. I guess we could have or customized nodes, am I right?
Cool stuff as usual.
we can a group node, which is effectively a new node/costum node
It's actually the opposite, kinda.
Because Geonodes is rather "visual scripting", or something like this. Like you could write various scripts to generate geometry in Blender, and now you can just use nodes.
OSL... Actually, it was in Blender for a long time (at least, I saw some semi-tutorials on it). But rather as "experimental" feature. It looks like, they added it to "supported" category. Interesting thing is that it's not Blender exclusive thing, but something like open standard, used by various renderers. For example, 3Delight uses it now days. Before, it used RSL (Renderman Shading Language).
But I don't really know how useful it is, now days. And how hard it is. Like it (RSL) was really technical, because you was writing all the math behind shaders. Yep. Shading models, generated textures and all the other stuff. Meanwhile, considering that usually PBR are used...
But on the other hand, it looks like, it can be really useful for creating various shader nodes, to be used with other ones. Which can be easier, and maybe even much more productive. (And fun?)
Alright I've cleared my whole week. I'm putting on my coding glasses.
That's a quite old reference. I miss the silly fast tuts!
@@valovanonym Same
Duality of a Graphics Developer 🥸
Oh god, I needed this so much. I'm new to blender and pulling my hair out figuring out how to do what. The zoom locks weirdly, typing x to indicate axis threatens to delete objects if my mouse was outside the area when I typed the g or r or s or whatever... and the nodes don't make any sense beyond the basic texture stuff. Coding is way easier. Can totally imagine randomising being really simple like this. Say... for instance colours. You've probably prevented my breakup with blender. Nah. i wouldn't have given up, but this makes things simpler.
This is great! Finally, someone explaining the basics of OSL shading. It's super helpful. I'd love to see the process of converting or adapting OSL shaders made for Octane/Redshift to Cycles. Understand what the difference of making OSL for different render engines if any and how to properly convert them. Thanks a lot for the series!
According to the official documentation, OSL shaders made for other renderers should ostensibly work for Cycles.
Thanks this is going to be really useful, I wonder why others don’t talk about it, looks supe4 powerful.
I am active in a couple of opensource projects, most are by and for developers. And hence code is not something dirty (in a bad way :")). Blender is differnet in the way that a very high percentage of the users cant code. By it self fine, but different
you're right, i guess it not many ppl want to give it a try. Thank u for supporting opensource projects.
I dont know how to code but i see the potential in the OSL so here i go!
Really excited for this series!
Always something new with you. Thank you
Was looking forward to this one to show a friend, thank you!
Loving the addition of code to the wheel house
This is going to make things quite different for me. For me it's just easier to write code than use visual blocks. And this seems like a simple way to use same properties on multiple files when everything is just on different script files
Woah this is actually quite interesting, I can compress or make huge shader trees into just single node, and it might be more faster. I hope there is some possibility of optimizing processing time compared to normal nodes.
ChatGPT baby. shader metalSurface(
color BaseColor = color(0.9, 0.9, 0.9),
float Roughness = 0.1,
float Metalness = 0.9,
float RustLevel = 0.5,
float ScratchesLevel = 0.2,
color RustColor = color(0.8, 0.2, 0.2),
color ScratchesColor = color(0.7, 0.7, 0.7)
)
{
normal N = normalize(N);
point P = transform("shader", P);
vector V = normalize(I);
vector R = reflect(V, N);
// Calculate ambient occlusion
float ao = 1 - ambientocclusion("samples", 16, "maxdist", 1);
// Calculate diffuse color
color diffuse = mix(BaseColor, RustColor, RustLevel) * (1 - Metalness) + Metalness;
// Calculate specular reflection
color specular = mix(color(0.04, 0.04, 0.04), color(1, 1, 1), Metalness) * pow(clamp(dot(R, V), 0, 1), 1/(Roughness*Roughness));
// Calculate scratches
float scratches = noise(P * 10) * ScratchesLevel;
scratches = pow(scratches, 2);
// Combine all components
Ci = diffuse * ao + specular * ao + ScratchesColor * scratches;
}
While ChatGPT is a great tool, this code needs work.
*N* is a global variable, so
normal N = normalize(N);
will produce an error: "N" already declared in this scope
@@veecel yeah. As usual chatgpt needs a little help. It's still an infant. But it will soon be Skynet.
You are so awesome for doing this video for people. Thank you for taking your time.
this makes blender seem way more appealing as someone with a coding background
Now here's a tutorial series I can get into. Excellent!
CUDA GPU Complete does not work, the tick box goes away
Great to hear about shader programming !!!
Thanks man, great tutorial. I know too little about Blender's scripting side.
Please mind your language though, it's a bit unpleasant.
Finally :D Been waiting for this.
That's awesome! I actually wanted to use it for a long time but haven't because I didn't understand how it works
To boldly go... We're no Blender TH-camr has gone before... 🥁🎶🎷
Thanks for this, and all Your other tutorials.
Though I have a question/note regarding the "GPU compatibility" ?
I'm on Linux (Pop OS 22.04), and to be able to enable GPU AND OSL I have to enable "OPTIX" in the "Edit>>Preferences >> system>>Cycles Render Devices". If I have it set at "CUDA" the "TickBox" for "Open Shading Language" disappears if I choose "Device GPU"...
Is this a "Linux issue", or is it the same on other "platforms".... Or is it just "me" ??
Same thing, I have a GeForce 1070 with CUDA enabled, if I enable GPU Complete then the open shading tick box goes away, still don't have an answer even now
@@edgarhammond2252 Same card, very similar issue. No idea what's going wrong but this card is at the very bottom of the min spec. Hope it gets improvements eventually because according to NVIDIA, Optix should work on this class of card with new drivers.
I'm super excited for this, just as you say, I've never seen a comprehensive introduction to OSL or any other SL in blender -aside from a video of yours from a while back-, and that's really a shame because this is really how I prefer to interact with code, as opposed to nodes
What are some cool things that you can do with this?
Great, looking forward to the next video in the series
Can you please bring back the thumbnails that describe what's happening in the video so we don't have to mouse over the preview?
Thank you ! We needed tutorials about this !!
OMG, I wanted to know what was this thing, I search on the internet but I found nothing, THANK you so much
Finally! I have been waiting for this. Why does no one mention this as a major feature? I'm always confused why shader code is so unpopular.
Because until recently it has been available for CPU only. Very few are willing to deal with that limitation.
I couldn't get OSL working with GPU in 3.5. If anyone's having this issue, I figured it out - go into edit>preferences>system and turn off your gpu for cuda, but then make sure its turned on for optix
I got my hopes up thinking that eevee was getting shader language support
It would be a better idea for beginners if you wrote all parameters in one line instead of separating them, so they are distinguished from the shader (or I guess function) body where we use semicolon.
Great video! As a front-end developer, this really inspired me into learning more complex code 🙏🏼
I'm so glad blender recently made osl available for gpu!
please keep doing this series
#Respect for writing "abcd" instead of "asdf" :D
Very cool tutorial, I've always wanted to know what is OSL in practice and what are its benefits... what are its benefits?
formulating a complex set of nodes into one shader that is easy more compatible with other sofwares?
More compatible and loops
@@CGMatter Thanks! can't wait for the next one!
Not sure if you have ever thought of doing a follow up video on this. But this work flow works stupidly well with ChatGPT. The blender implementation is kinda bad. The play button being python instead of refreshing is confusing, having to be in the correct view or getting black renders is confusing. Not working in EEVEE is confusing. Hitting the run button and getting a python error that tells you nothing is confusing. But once you get it working it's awsome.
shader FadeBetweenMasks(
int HV = 0, // 0 for vertical, 1 for horizontal
float FadeAmount = 0.5,
color ImageA = 1,
color ImageB = 0,
color MaskA = 1,
color MaskB = 1,
output color OutColor = 0
) {
float fadeCoord;
if (HV == 0) { // Vertical fade
fadeCoord = (P.y + 0.5) / FadeAmount;
} else { // Horizontal fade
fadeCoord = (P.x + 0.5) / FadeAmount;
}
float fadeFactor = smoothstep(0, 1, fadeCoord);
color maskedImageA = mix(ImageA, ImageB, fadeFactor);
OutColor = mix(MaskA, MaskB, fadeFactor) * maskedImageA;
}
I got chat GPT to spit that out with some prompts. It's not exactly what I wanted first shot but with some mucking around you can get some complicated stuff in 1 node with some simple talking with GPT. You can also use GPT to say convert GLSL scripts to OSL It's not 100% but it does give you a lot of possibilities if you say like a shadertoy example. You can bake out the textures for use with eevee or other stuff once you get something you want.
Very cool! I had no idea this existed.
Is there going to be a have chat gpt make an insane node tutorial ?
you shouldn't have lost the 'tache. you look cool in that!
Honestly a god thank you so much for all you do ❤❤🎉
I always wanted to get into this! Thank you!
Whenever I check the open shading language box the viewport freezes.
Dude awesome, cannot wait for more..
Dude... so inspiring! Thanks a lot
First time I heard about Open Shading Language. So how's this compared to GLSL? And does Blender support GLSL programming?
I’ve been using a shader that’s osl only for a while. It’s cool I can lean on the GPU now. Curious about this series.
Now we are talking babe
Always wanted to learn osl, thanks!
nice bro keep us update u r futures
I'm using the blender 3.6 alpha, but I can't turn OSL on? I'm using CUDA GPU but there's no check?
This is perfect, so we can ask GPT5 for shaders
Have you already tested it with geonodes?
can you give us a tutorial on how to render with google colab?
I got jumpscared by a beardless face.
CODING TUTORIAL! Yay! It was almost inevitable after all the AI tutorials :P
P.S. CUDA support means Nvidia GPUs only
Thank you bro
Yay new CGM video
As someone who suffers everyday from studying programming, I am staying with the traditional nodes method 😅
I get this error:OSL script compilation failed, see console for errors, anybody else? Tried CPU as well same thing :( Blender 3.5 stable
what's the name of the programing lenguage u using here?
Why cant you use osl for eevee? I prefer eevee
coding...coding is it like the stuff you ask chatgpt to do? sorry im new
is open shading language like GLSL?
They're both shading languages but there are a number of differences. GLSL shaders can be converted to OSL but that requires some work and know how.
From walking to sit...king. idk man
Finally, OSL for GPUs...
damn glsl tutorials now? when are we gonna get to upbge lol
Good stuff. I'm close.
Is gpt-4 good for this? I've been trying to use it for a while, but I'm used to the nodes
Yes, Chat GPT-4 is a great coding assistant for Blender.
Try but don't let me say error in the compilation
you_know_i_am_something_of_a_programmer_myself.jpg
я пишу float a = 0 и у меня не появляется поле a в ноде. :(
Gonna use chatgpt for this too :>
Amazing!
But why not GLSL :(
This is great!
Texture paint = easy , nodes = medium , Open shading language = hard.
Oh neat. The last time I touched OSL was in 2.9 and saw it was CPU only so I threw that to the garbage bin. The performance hits for doing anything complex compared to the shader nodes themselves wasn't worth it.
Thank you Ed sheeran of blender
could you use chat gpt to generate that code ???
Yes, Chat GPT-4 is a great coding assistant for Blender.
oh thank u so much
COUNT ME INTERESTED
thanks ♥
Leeeets go
YES
OSL lesgoo
neat
No need to learn the language, now we gon use GPT to write the shader
Exactly