# An assortment of OSL shaders for your perusal

**URL:** <https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619>\
**Category:** General\
**Tags:** fresnel, osl\
**Created:** [May 23, 2016, 5:14pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619 "2016-05-23T17:14:40Z")\
**Posts on this page:** 20\
**Page:** 6

<div class="post-metadata">

**Author:** ![Morbid\_Angel](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/morbid_angel/32/21272_2.png) [@Morbid\_Angel](https://forums.chaos.com/u/Morbid_Angel)\
**Post date:** [July 17, 2016, 4:25am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/101 "2016-07-17T04:25:30Z")

</div>

Rens your shaders are pretty impressive!

How about a single sheet scattering material, which simulates scattering of light with single sided geometry (like leaves) I feel that the current 2sided mtl can be better with support of sss, I mean it works fine but at ilm we had to do all kinds of tricks with real sss ontop of it to make it look good and its a pain in the ass a bit, and also 2sided mtl does not have a render element..

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [July 17, 2016, 2:07pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/102 "2016-07-17T14:07:31Z")

</div>

OSL doesn’t allow the creation of custom BSDFs so this can’t be achieved with it.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![snivlem](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@snivlem](https://forums.chaos.com/u/snivlem)\
**Post date:** [August 10, 2016, 12:45am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/103 "2016-08-10T00:45:23Z")

</div>

The archglass looks really cool but I’m struggling to understand a key concept

> This shader allows you to simulate full window glass geometry with only one plane

Can this shader be used on a pane of glass that actually has a thickness? Would I be correct in assuming this would be achieved by setting both “VRay IOR Out and VRay IOR Glass” to 1.550.

Currently VRay IOR Out set to 1 which I think is why it is supposed to be used on a plane without a thickness?

---

<div class="post-metadata">

**Author:** ![snivlem](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@snivlem](https://forums.chaos.com/u/snivlem)\
**Post date:** [August 11, 2016, 11:53pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/104 "2016-08-11T23:53:27Z")

</div>

Sorry for the double post, but Vlado, is there a difference between how Max and Maya interpret OSL shaders? It seems no normal map works with this particular glass OSL shader in Maya. I’m assuming it’s to do with the code itself, in that Max is Z up and Maya is Y up?

If anyone else could give me a pointer on where to start editing to fix this, I’d be happy experimenting with the code to get this working in Maya - it’s an awesome glass shader!

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [August 12, 2016, 8:32am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/105 "2016-08-12T08:32:51Z")

</div>

I’ll get one of our OSL guys to look into it.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![Rens](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/rens/32/16004_2.png) [@Rens](https://forums.chaos.com/u/Rens)\
**Post date:** [August 12, 2016, 9:41am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/106 "2016-08-12T09:41:27Z")

</div>

Sorry for the lack of updates, busy busy. 🙂

> [@composite layers](https://forums.chaos.com/t/composite-layers/51925/4):
>
> Can this shader be used on a pane of glass that actually has a thickness? Would I be correct in assuming this would be achieved by setting both “VRay IOR Out and VRay IOR Glass” to 1.550.
> 
> Currently VRay IOR Out set to 1 which I think is why it is supposed to be used on a plane without a thickness?

No, I’ve measured the values from 1, 2 and 3 panes of glass and fitted reflection and refraction curves to match them. When using more than one face/side of geo the calculations won’t work anymore and you’d get unexpected results. : )  
The reason for this is that it’s pretty hard to get values right if you’re using only a plane as your geo for speed. Raytracing two or three actual panes of glass would be much slower.

IOR out would be the IOR of air usually (outside of the glass). You could for example simulate window glass under water (IOR 1.333) as well if you’d ever want to… probably not though hehe. Setting both to 1.55 would effectively cancel out any reflection.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Alex\_M](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Alex\_M](https://forums.chaos.com/u/Alex_M)\
**Post date:** [August 12, 2016, 2:02pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/107 "2016-08-12T14:02:38Z")

</div>

Thanks for the shaders, Rens. I wanted to try the Arch Glass OSL shader but I get errors when I load it. ☹ Please see below. I’m using Max 2016 SP3 with Vray 3.40.02

```auto

[B][COLOR="#FF0000"]error: Input file "D:\Downloads\OSL shaders\OSL – ArchGlass\archGlass_mat_v002.osl" not found
Could not compile shader D:\Downloads\OSL shaders\OSL – ArchGlass\archGlass_mat_v002.osl (OSL to OSO)[/COLOR][/B]

```

---

<div class="post-metadata">

**Author:** ![Ihno](https://avatars.discourse-cdn.com/v4/letter/i/c0e974/32.png) [@Ihno](https://forums.chaos.com/u/Ihno)\
**Post date:** [August 12, 2016, 2:27pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/108 "2016-08-12T14:27:04Z")

</div>

Is the “rhfunctions.h” from rens page in the same folder? They wont work otherwise.

---

<div class="post-metadata">

**Author:** ![Alex\_M](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Alex\_M](https://forums.chaos.com/u/Alex_M)\
**Post date:** [August 12, 2016, 3:11pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/109 "2016-08-12T15:11:25Z")

</div>

Yes, it is. 😕

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [August 12, 2016, 4:26pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/110 "2016-08-12T16:26:48Z")

</div>

> [@Merry Christmas!](https://forums.chaos.com/t/merry-christmas/51976/4):
>
> Thanks for the shaders, Rens. I wanted to try the Arch Glass OSL shader but I get errors when I load it. ☹ Please see below. I’m using Max 2016 SP3 with Vray 3.40.02
> 
> ```auto
> 
> [B][COLOR="#FF0000"]error: Input file "D:\Downloads\OSL shaders\OSL – ArchGlass\archGlass_mat_v002.osl" not found
> Could not compile shader D:\Downloads\OSL shaders\OSL – ArchGlass\archGlass_mat_v002.osl (OSL to OSO)[/COLOR][/B]
> 
> ```

Can you try putting the shader in a folder that doesn’t contain spaces? I can’t think of anything else that might be throwing it off right now.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![Alex\_M](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Alex\_M](https://forums.chaos.com/u/Alex_M)\
**Post date:** [August 12, 2016, 5:36pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/111 "2016-08-12T17:36:37Z")

</div>

That worked! Why would that be a problem though? I tried another OSL shader from Rens called Mix Normal Maps and it works fine in a folder with spaces. 😵‍💫

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [August 12, 2016, 6:32pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/112 "2016-08-12T18:32:40Z")

</div>

> [@Maya Vray distributed rendering doesn't work](https://forums.chaos.com/t/maya-vray-distributed-rendering-doesnt-work/51966/2):
>
> That worked! Why would that be a problem though? I tried another OSL shader from Rens called Mix Normal Maps and it works fine in a folder with spaces. 😵‍💫

It might not be the spaces as such, but some other character like the dash character ‘-’ which is maybe is a Unicode character and not plain ASCII… or something like that.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![Rens](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/rens/32/16004_2.png) [@Rens](https://forums.chaos.com/u/Rens)\
**Post date:** [August 13, 2016, 6:31am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/113 "2016-08-13T06:31:31Z")

</div>

Yeah someone else had the same problem, also a folder with spaces and characters like dashes. : )

---

<div class="post-metadata">

**Author:** ![snivlem](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@snivlem](https://forums.chaos.com/u/snivlem)\
**Post date:** [August 15, 2016, 1:12am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/114 "2016-08-15T01:12:27Z")

</div>

THanks for the shader and explanation rens. This is incredibly useful on projects where the architects give us sketchup models that have glass that is not thick! Massive timesaver!

---

<div class="post-metadata">

**Author:** ![Pixelcon](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/pixelcon/32/22319_2.png) [@Pixelcon](https://forums.chaos.com/u/Pixelcon)\
**Post date:** [August 22, 2016, 8:54am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/115 "2016-08-22T08:54:59Z")

</div>

I’m also having issues with the Arch glass osl ☹

Using 3.40.02 & Max 2015 sp3

If I try rendering with RT I get an error - “Error during V-Ray RT initialization in stage 2!”  
and if I render with production I get a finished render except max hangs after the render is completed ☹  
No error readout in the VrayOSLMtl node…

I have double checked that i have rhfunctions.h in the same folder and the path contains no spaces…

---

<div class="post-metadata">

**Author:** ![sharktacos](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sharktacos](https://forums.chaos.com/u/sharktacos)\
**Post date:** [August 30, 2016, 6:24am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/116 "2016-08-30T06:24:16Z")

</div>

Hey Rens,  
I have a request for ya. You have several Fresnel implementations, each based I believe on viewing angle. It would be great if you could write an OSL Fresnel calculated per microfacet, rather than viewing angle, as described [here](https://www.solidangle.com/research/physically_based_shader_design_in_arnold.pdf) (page 10-12). As you can see in the images, this is important for avoiding over-bright highlights as well as dark areas at glancing angles.

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [August 30, 2016, 7:29am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/117 "2016-08-30T07:29:01Z")

</div>

> [@Car Flakes as map](https://forums.chaos.com/t/car-flakes-as-map/52292/4):
>
> I have a request for ya. You have several Fresnel implementations, each based I believe on viewing angle. It would be great if you could write an OSL Fresnel calculated per microfacet, rather than viewing angle, as described here

This is not possible in OSL; it must be supported in the BRDFs provided by the renderer. This will be implemented in the next SP of V-Ray, but in the meantime you can use the alSurface material here:  
[https://github.com/ChaosGroup/vray\_al\_surface/releases](https://github.com/ChaosGroup/vray%5C_al%5C_surface/releases)

There is also a conceptual problem with OSL regarding this. Glossy Fresnel not only determines how a BRDF reacts to light, but its “transparency” as well (how it is combined with other BRDFs below it). OSL has no way for closures to return this transparency so it must be computed in another way, potentially duplicating the work done by the BRDF.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![sharktacos](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sharktacos](https://forums.chaos.com/u/sharktacos)\
**Post date:** [August 30, 2016, 2:42pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/118 "2016-08-30T14:42:18Z")

</div>

> [@Vray 3 Maya Proxy Subdivision Problem](https://forums.chaos.com/t/vray-3-maya-proxy-subdivision-problem/52286/6):
>
> This is not possible in OSL; it must be supported in the BRDFs provided by the renderer. This will be implemented in the next SP of V-Ray  
> Vlado

Thanks for the explanation. Some followup questions:

1) The only OSL brdf that has Fresnel currently is the microfacet\_ggx (the eta parameter). Is it correct that this currently is not using per microfacet Fresnel, but will in the next SP?

2) Will a Fresnel term that uses per microfacet be added to the other brdf closures (for example to the vray\_blinn) closure too?

3) In an energy conserving shader the diffuse transmission would be attenuated by the fresnel transmission of the specular/reflection. So in psuedo code:  
`diffuseColor *= (1.0 - specColor)`

This works if the specColor is multiplied with the Fresnel, but if the Fresnel is built into the brdf, how would one keep the shader energy conserving when combining closures?

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [August 30, 2016, 2:50pm UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/119 "2016-08-30T14:50:07Z")

</div>

> [@Motion Blur Sets](https://forums.chaos.com/t/motion-blur-sets/52325/3):
>
> 1) The only OSL brdf that has Fresnel currently is the microfacet\_ggx (the eta parameter). Is it correct that this currently is not using per microfacet Fresnel, but will in the next SP?

This is correct, yes.

> 2) Will a Fresnel term that uses per microfacet be added to the other brdf closures (for example to the vray\_blinn) closure too?Yes.

> 3) In an energy conserving shader the diffuse transmission would be attenuated by the fresnel transmission of the specular/reflection. So in psuedo code:  
> `diffuseColor *= (1.0 - specColor)`
> 
> This works if the specColor is multiplied with the Fresnel, but if the Fresnel is built into the brdf, how would one keep the shader energy conserving when combining closures?I have no idea. Like I said above, this is an oversight in OSL. You can ask on the OSL Google group and see if there is a recommended approach.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![Ivan\_Mavrov](https://avatars.discourse-cdn.com/v4/letter/i/aeb1de/32.png) [@Ivan\_Mavrov](https://forums.chaos.com/u/Ivan_Mavrov)\
**Post date:** [August 31, 2016, 9:59am UTC](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619/120 "2016-08-31T09:59:21Z")

</div>

> [@Vray 3 Maya Proxy Subdivision Problem](https://forums.chaos.com/t/vray-3-maya-proxy-subdivision-problem/52286/6):
>
> OSL has no way for closures to return this transparency so it must be computed in another way, potentially duplicating the work done by the BRDF.

You could do the energy preservation but you’ll have to duplicate the Fresnel work done inside the closure as Vlado warned earlier.  
You do the Fresnel term math (hopefully matching that of the microfacet\_ggx) and figure out the reflection weight.  
Then apply it only to the diffuse/refractive closure below:

`diffuseColor *= (1.0 - specularColor * fresnelReflectionWeight);`

Best regards,  
Ivan M.

[Previous page](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619.md?page=5)

[Next page](https://forums.chaos.com/t/an-assortment-of-osl-shaders-for-your-perusal/58619.md?page=7)
