OSL | Raytype = Magic

Forums: OSL | Raytype = Magic
Sub forum for help and tutorials.

Moderator: aoktar

OSL | Raytype = Magic

Postby milanm » Wed Jun 13, 2018 5:39 am

milanm Wed Jun 13, 2018 5:39 am
Hi

Disclaimer: I am not a programmer. I went to art school to avoid math and did Graphic Design with gouache, ruler pens (reissfeder) and No1 sized brushes. I did have an Amiga back then (with a math coprocesor and 4Mb of ram so I could learn LightWave) but the only tech we were allowed to use was Xerox (to rip and enlarge 'fonts' from newspapers and magazines). I was one of the best in school in calligraphy and left handed! Now I suck at calligraphy. Because I'm having too much fun using C4D and Octane.

This is my first OSL script ever. It's ridiculously simple but it works and it's VERY powerful. In the C4D plugin we can't use the "popup" widget so I had to go with a bunch of if statements so the code looks complex, but trust me this is pre-school type of stuff. No math, just plain old 'if this than that'.




The section in the OSL docs about Raytype function has been haunting me for months. And finally this Sunday I took 20 minutes to figure out what happens when we use it and how the hell do we even use it. And I was blown away. And then I used it on opacity... Mind. Blown.

Usage:
This script blends between two colors/textures based on what type of ray is hitting the object. You can use it everywhere, for any parameter that has texture input. Instead of colors you can use other shaders or even other Raytype OSL shaders within other Raytype OSL shaders within oth... well... you get the idea. :)

It can be used to turn off shadows, AO, change material properties in reflections or refractions, turn off GI or use completely different material for GI on specific objects or lights and much much much much much more.

A & B: Textures/colors that are blended.

Ray: Type of ray that you want to test. Example: You apply Raytype OSL on Opacity and choose Shadow ray. When a shadow ray hits your object, only for that ray, opacity of your object can be different. So, that ray will then pass through your object and the result is -> no shadows!

Swap: Swaps the A & B inputs.

Instalation:
There is a great new manual for C4D that describes how we can use OSL shaders in C4D. The best way IMO is to drop the .osl file into your \MAXON\CINEMA 4D RXX\plugins\c4doctane\res\osl_scripts folder and then it will be available in the pull down menu along with all other scripts.

Orbx file - please check out the notes!
Raytype+InstanceID.orbx
(1.3 MiB) Downloaded 716 times


Raytype osl code / text file.
Raytype.zip
(470 Bytes) Downloaded 1091 times


BONUS: OSL 'texture' that blends textures based on InstanceID.
InstanceID.zip
(385 Bytes) Downloaded 681 times


I will be back (bearing gifs) with follow-up posts and C4D scenes to explain the best use cases and to show you what this thing can do. Stay tuned!

Remember: this is OSL, so there is an ORBX file and an .osl file that should work for users of Standalone and other DCC apps or maybe even other render engines!

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: OSL | Raytype = Magic

Postby aoktar » Wed Jun 13, 2018 6:13 am

aoktar Wed Jun 13, 2018 6:13 am
Hey,
This is cool experiment, thanks for pilotage!
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
aoktar
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 15970
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye

Re: OSL | Raytype = Magic

Postby bepeg4d » Wed Jun 13, 2018 6:15 am

bepeg4d Wed Jun 13, 2018 6:15 am
Great :D
ciao Beppe
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 9959
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: OSL | Raytype = Magic

Postby VVG » Wed Jun 13, 2018 6:24 am

VVG Wed Jun 13, 2018 6:24 am
Thanks for Sharing!
Win 10x64, AMD 1950x 16C/32T, RAM 32Gb, RTX 3060x3
Octane-for-C4D(R23.110)2021.x.x, Cycles4D, Centileo. Nvidia 472.47 STUDIO
VVG
Licensed Customer
Licensed Customer
 
Posts: 301
Joined: Sat May 07, 2016 2:34 pm

Re: OSL | Raytype = Magic

Postby milanm » Thu Jun 14, 2018 4:43 am

milanm Thu Jun 14, 2018 4:43 am
Obviously, this can be used for some cool mograph animations, cad model interior reveals etc. but I will focus here on using it as a rendering optimization tool.

In order to optimize renders in Octane--a unidirectional GPU pathtracer--we have to make sure we get the cleanest posibile result with the least amount of samples. I know many of us get distracted by Ms/s, GPU overclocking, watercooling (plumbing?) and time (how long it takes to render) but that's not the only way to measure speed of rendering in Octane. Think about it, how clean are your renders? How come some interiors take minutes to render and others take hours? We need to control what happens to samples as they travel throughout our scenes. I see this Raytype function as a tool to do exactly that.

One very interesting thing that we can do with Raytype is to separate lights to direct illumination lights (first bounce + shadows) and indirect illumination lights. In the scene below, I am using Raytype to control opacity of two lights using Diffuse rays.

Image

Orbx:
Separating Direct from Indirect Light.orbx
(393.9 KiB) Downloaded 438 times

C4D:
Important: Please use the Version 4 - XB3-R1 for testing. Or, in 3.08.1, disable 'Material Previews' and 'OpenGL previews' in the Live Viewer/Options menu.
Separating Direct from Indirect Light.zip
(165.89 KiB) Downloaded 486 times


So, it appears that there's quite a few things we can do now that we couldn't do before:

  • we can actually set a different Sample Rate for 'Indirect' lights and a different Sample Rate for 'Direct' lights.
  • We can also use different intensity and different color for each.
  • We can make the lights actually invisible in fog by using only secondary bounces (to increase illumination in fog for example) .
  • We can turn off secondary bounces (indirect illum.) to prevent multiple scattering in fog for problematic lights.
  • We can turn a wall in our interior render into a light source without changing its appearance and shading.

Let's see how we can use that to speed up rendering of lights in volume mediums.

There were multiple requests on the forum for some kind of solution for simple, even fake, 'visible' spotlights or fog effects. Right now we can either change the settings to AO or render volumetrics separately. But what if the rest of the scene needs Pathtracing and we only need one (god?)ray of light coming through the window? Can we just reduce multiple scattering in the volume but still keep our shadows somehow? Well, now we can do that.

Here's a light source inside a volume rendered using Pathtracing kernel, Max. samples 128, No GI clamp. We get a ton of fireflies everywhere.
fog1.jpg


If we make sure our lights are only emitting direct light we get some improvement. Notice how fireflies are only focused around our lights and the rest of the scene is clean. That means adaptive sampling will be able to do a better job detecting noise.
fog2.jpg


If we go a step further, using the Camera ray option, we can make direct light only visible in the camera. We loose our reflections, but we get a super clean render. This is great for stage lights, spaceship thrusters, spot lights and all those cases where lights are too small to have a significant effect on the overall lighting in our scenes but it's just enough to cause a lot of noise everywhere.
fog3.jpg


Orbx:
Fog.orbx
(278.34 KiB) Downloaded 391 times

C4D:
Important: Please use the Version 4 - XB3-R1 for testing. Or, in 3.08.1, disable 'Material Previews' and 'OpenGL previews' in the Live Viewer/Options menu.
Fog.zip
(87.14 KiB) Downloaded 429 times


Regards
Milan
Last edited by milanm on Fri Jun 15, 2018 4:22 pm, edited 2 times in total.
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: OSL | Raytype = Magic

Postby Studio21 » Thu Jun 14, 2018 8:54 am

Studio21 Thu Jun 14, 2018 8:54 am
very cool! thx!
Studio21
Licensed Customer
Licensed Customer
 
Posts: 212
Joined: Wed Nov 16, 2016 11:14 am

Re: OSL | Raytype = Magic

Postby Studio21 » Thu Jun 14, 2018 9:51 am

Studio21 Thu Jun 14, 2018 9:51 am
however I do get a lot of render failures messing around with it in C4D


Best,

Guy
Studio21
Licensed Customer
Licensed Customer
 
Posts: 212
Joined: Wed Nov 16, 2016 11:14 am

Re: OSL | Raytype = Magic

Postby milanm » Thu Jun 14, 2018 10:45 am

milanm Thu Jun 14, 2018 10:45 am
OSL has been rock solid in OctaneRender, however there's definitely some more work needed to make it work with the way C4D plugin is detecting updates. There is the compilation process that can happen either automatically or manually depending on your choice and besides that during the updating process, the plugin needs to create all those new UI elements.

So to be on the safe side for now these are my tips:

- I find that it's best to stop the rendering before adding the OSL Texture to a new texture input.
- It's a good idea to disable the 'Auto' compilation option after that too.
- Using the 'Copy Shader' option seems to be more stable than adding a new OSL Texture.

So we just have to take it easy for now I guess.

I had a lot of crashes as I was changing the code live and something in the scene would trigger an update and it would compile while the code is unfinished but that is to be expected, obviously, and I guess that's what the 'auto' option is for.

Also I'm avoiding the node editor for now because of that issue when it changes the kernel sometimes to Infochannel. It's hard to pinpoint when or why this happens but trust me as soon as I get to the bottom of that I'm coming back to bother Ahmet about it on the forum.

With all of that said, once you set it up everything works just fine and you can save your scenes and use those materials as normal. It's only during 'experimental' stages that we have to be a bit cautious. Right now I'm using it everywhere and anywhere and with those tips above everything works great.

Oh there's one more safety measure. Make sure you finish all of the important jobs before playing with this because it's highly contagious, it tends to make time run faster and hair grow faster so I'm not responsible for any missed deadlines or bad hairstyles if someone was having way too much fun. ;)

Cheers
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: OSL | Raytype = Magic

Postby Studio21 » Thu Jun 14, 2018 12:12 pm

Studio21 Thu Jun 14, 2018 12:12 pm
Yeah I agree @millan. OSL need some more work on stability in C4D, standalone is rock solid. thx for the tips :)


Best,

Guy
Studio21
Licensed Customer
Licensed Customer
 
Posts: 212
Joined: Wed Nov 16, 2016 11:14 am

Re: OSL | Raytype = Magic

Postby frankmci » Thu Jun 14, 2018 1:02 pm

frankmci Thu Jun 14, 2018 1:02 pm
milanm wrote:OSL has been rock solid in OctaneRender, however there's definitely some more work needed to make it work with the way C4D plugin is detecting updates. There is the compilation process that can happen either automatically or manually depending on your choice and besides that during the updating process, the plugin needs to create all those new UI elements.


This is wonderful stuff, Milan! Unfortunately, as you say, OSL is terribly unstable in C4D at the moment. I can't even look past frame 5 of your demo scene without the dreaded "CUDA 700 illegal memory access" error requiring I quit and restart C4D. It works great in Stand Alone, though.

I've been trying to dig into OSL in C4D over the last week or two (3.08.1-R1), but have found it so unstable as to not be worth my time, regardless of Web and CUDA driver versions, and it does not fail gracefully; one typo in the code and it completely kills the app. Any info on that, @aoktar?

In my case, this is on Mac OS 10.12.6, C4D R19.053, GTX1080 TI, and various web/CUDA versions.

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

Return to Help / Tutorials


Who is online

Users browsing this forum: No registered users and 16 guests

Sat Apr 27, 2024 12:00 pm [ UTC ]