An assortment of OSL shaders for your perusal

Rens, A while back I recall you saying you were going to make a remapValue OSL. Maybe you could post it here…

For what it’s worth I did find this blendColors. Note sure it is the same tho:


shader blendColors (vector color1 = vector(1,0,0), vector color2 = vector(0,0,1), float blender = 0.0, output vector outOutput = vector(0,0,0))
{
    outOutput = color1 * blender + color2 * (1.0 - blender);
}

Is that the same as I posted here http://forums.chaosgroup.com/showthread.php?88127-How-do-I-use-a-Maya-RemapRamp-node-in-3ds-max

I’m looking to use the same technique as in Maya/VRay where you use a RemapRgbToHsv node that plugs into a V Ramp. Can an OSL do the same workflow?

Wow I just discovered this thread, fantastic stuff! :smile:

EDIT : Just tested that osl reflection stuff, it’s amazing!! I’m testing it for skin.. and reflection look WAYYYYY better now, thank’s a lot for that :smile:

Glad to hear it’s working well! : )

I had a chance to test the OSL maps in Maya, and other than a doubling of the inputs (one color, one texture) it appears to be working fine! Did anyone experience any problems in Maya?

One thing that seemed to be missing was the string widget, as in an actual text field, this was a colour input in the UI.

Yes, I have a working color correction shader with some remapping (scaling) options, like Nuke’s grade node, as well as HSV options. However I was a bit too quick with my reply, remapValue allows you to adjust the input colour using a curve or gradient, yes? I’ll write one where you can input one gradient ramp to drive another, because OSL does not allow for UI curves or keys.

Other than to match it with existing BxDFs, not much. : )

It should, if you’re looking to remap one ramp or colour range using another ramp? As I mentioned there are no UI curves or gradients in OSL, but you can drive one gradient with another one.

ArchGlass
Simulate multi-paned window glass with only a single-sided plane! And also the first OSL material (not texture) of these.
An OSL shader for creating realistic glass window panes. Window reflections are amazingly complex; you get for one pane of glass reflections from the front, back, and scattering from inbetween, light gets absorbed and passed through to the other side only to be reflected back by the next pane of glass. This shader allows you to simulate full window glass geometry with only one plane. Useful for everything but close-ups.

Links
Page:
http://www.rensheeren.com/blog/osl-archglass/
Download links:
http://www.rensheeren.com/osl/archGlass\_mat\_v002.osl
http://www.rensheeren.com/osl/rhfunctions.h
Right-click and save both in the same folder, both are needed for the shader to work. Overwrite rhfunctions.h if asked.

Features
- Specify the amount of window panes (1-3).
- Absorbtion/tint colour.
- Reflective coating layer, for example a one-way mirror or high reflectance building glass.
- Dirt layer, like a layer of dust or sand on the outside.
- IOR of glass and surrounding medium (air usually).
- Normal map inputs for creating warped reflections for each pane separately.
- Supports ray traced refraction, transparency, and black opaque for the refraction/transmission.

How to use
– Create a VRay OSL Material.
– Load in the downloaded OSL shader.
– Set how many panes are in your window. Most modern windows in temperate and cooler climates have two panes for insulation.
– Optionally set a colour for the reflective coating if your window needs one.
– Same for the dirt. The colour is usually fine, you define how much dirt there is on top of the windows with the dirt amount input.
– Set the refraction mode, 1 – ray traced refraction, 2 – transparency, 3 – no refraction, just black, for mixing with a self-illuminated interior or to just have only the glass reflection.
– Normal map inputs need a normal map with RGB 0.5 0.5 1.0 as the ‘base’, meaning that there won’t be any normal difference with that colour.
– Apply to a one-sided plane object.



NOTE: This is from the first post, which I’ll now edit to make it into an index to make things a bit clearer. : )

The Reflector!

Links
Page:

Download:
http://www.rensheeren.com/osl/reflector\_tex\_v002.osl
http://www.rensheeren.com/osl/rhfunctions.h
Save both in the same folder, both are needed for the shader to work. Overwrite rhfunctions.h if asked.

Features
- Metals and non-metals. Uses complex Fresnel for metals and switches to non-complex for non-metals for quicker rendering.
- Polarisation for both, should you want to play around with that.
- Outside medium IOR, for example for objects under water.
- Aaaand… rough Fresnel!

Rough Frensel I hear you ask? Say you have a smooth plastic ball, the reflection amount follows a Fresnel curve, where the reflection amount is lowest where it faces you or the camera, and strongest on the grazing or side angles.
Now if you roughen it up using sandpaper that angle dependant reflection strength difference is not visible anymore, when viewed as a whole. The sides would reflect roughly the same amount as the front. However in most renderers this front/side reflection curve gets applied the same independent of how rough the surface is. This leads to objects have overly bright or dark reflections on the side angles. It may look like a subtle change but objects with low glossiness / high roughness will look a lot better when the reflection curve gets smoothed out with increasing roughness.

How to use
– Create a VRay OSL Texture map.
– Load in the downloaded .osl shader.
– Create a VRayMtl and disable Fresnel reflections.
– Plug the OSL map into the reflection.
– You may want to create a VRayColor map to drive the roughness/glossiness values of both the OSL shader and the VRayMtl. Plug it into roughness_tex for the OSL shader and in Refl Gloss for the VrayMtl.

Some examples:

Rough Frensel setup on the left.

Are there any shaders that anyone would like to see?

I don’t know if this is possible, I wish there was a shader that makes single sided geometry appear to have actual thickness… kinda like a shader-based Shell modifier. It doesn’t have to be so big as to change the object’s silhouette, just a one-pixel edge that catches the light.

I remember one time I saw something floating around here which emulates building interios. Imagine you have a high-rise building with thousands of offices behind glass windows. Somewhere I found some sort of shader or sth which generates perspectively correct simplified interiors/rooms behind those glass panels. I can’t find it at the moment, but do you know what I mean?

:wink:

And whats about a Curvature with 3 input Textures Flat,Concave,Convex?

You should sell your shaders, or at least add a donate button to your Page.
I’d be happy to pay a little for them:)

+1 for the blur map!

Actually I think I may want something even more important: Texture Bombing!

Just taking one or several input textures and then randomly scatter/distribute them in texture space with randomization in rotation, maybe brightnes/saturation/etc, ideally with a density setting and some controls for blending. That would be dope! WOuld pay money for it.

Can you do a decent Color Correction node via OSL? Also +1 for blur node…

No love for this one?
http://www.cuneytozdas.com/software/3dsmax/#ColorCorrect

I’m not sure I follow the reason for the rough fresnel. Couldn’t you just increase the ior and decrease the reflection amount, or is it a case of this does it in fewer clicks and/or it’s more physically accurate?

A procedural texture (or a few) that emulated the weave of various types of fabric would be useful. The clothTex is nice, but only matches a certain type of fabric weave.

True

One thing that seemed to be missing was the string widget, as in an actual text field, this was a colour input in the UI.

Yes, as far as I know that concept does not exist in Maya.

remapValue allows you to adjust the input colour using a curve or gradient, yes? I’ll write one where you can input one gradient ramp to drive another, because OSL does not allow for UI curves or keys.

FWIW, in Maya I usually end up using the blendColors node. This does more what I’m after, and has a cleaner interface than the remapValue node.

Other than to match it with existing BxDFs, not much.

Yeah, I have that much of the DisneyBRDF working in OSL currently, but I’m not sure how useful it is. I’d be happy to share it if anyone is interested.

Shark,

What is “clothTex”?

The clothTex is nice, but only matches a certain type of fabric weave.

Yes, If you increase the IOR and decrease the reflection amount you’ll get roughly the same, and yes it’s less eyeballing with the shader and you can have varying roughness as well. Plus it calculates the front reflection colour for you.
If you want to set up what I did in the shader yourself you can get a reflection map like Falloff set to Fresnel (or the reflector shader hehe) and place that into the second/white input of a Mix node. Place a VRayColor into the first/black input and set the colour to what you think the front reflection amount will be, roughly. So say RGB 0.04 for a plastic. Now have the glossiness input drive the mix amount. I tweaked the glossiness input a bit in my shader so it’s not linear, but this is roughly the same setup. In the end it’s just a colour blend and not a full per-sample calculation, but it seems to do the trick nicely so far. : )

To explain it a bit more, basically what rough Frensel does is it evens out the reflection amount (the % of light reflected) so that is is less angle dependent. So in most shaders, if you set the IOR and enable Frensel reflections you will have stronger reflections near the grazing angles or side edges of the object, like as in the edges of the sphere example I posted. The front facing reflections will be much lower.
Rough Fresnel evens this out, as when the surface is rougher, the angles get mixed and blended because of all the scratches and bumps on rough surfaces. Basically with a rougher surface you will look at a lot of front facing surfaces mixed into the side facing surfaces and the other way around, because of the micro-detail valleys and mountains (scratches). Summed up with a fully rough surface, this comes down to a close to uniform reflection amount for all angles that is close to the original front facing reflection amount, it gets evened out over all angles, side and front.

In this shader this means I have blended the Fresnel falloff curve (front low, side high) with a single colour that is close to the Fresnel front (low) reflection amount. Or to put it in numbers, when your object reflection is 4% in the front and 100% at the sides, rough Fresnel will blend this to be say 5% in the front and 5% at the sides for a fully rough surface.

That would be tricky. I had a quick look but you’re pretty limited in OSL when it comes to looking up geometry. A shader similar to the VRayEdgesTex might be able to do that.

Yes, I’ve added some features and hope to finish this version in the coming week. Here’s the WIP if you’re interested:
http://www.rensheeren.com/osl/intmaptemp.zip

And this is the thread you mentioned, I think:
http://forums.chaosgroup.com/showthread.php?81727-Interior-mapping-shader&highlight=interior+mapping

Probably not doable in OSL but I’ll have a look. I won’t be selling these shaders, but I’ll consider a donate button. : )
I started on a blur shader, but it might be very slow, let’s see!

Yes I’ve done a CC shader, I’ll upload it sometime next week hopefully.

Sounds interesting! Should be doable, yes.

That’s a tricky one but would be fun to figure out how to do that. : )

If you want to share what you have on the Disney shader I’d be interested in having a look!

Could you link said clothTex?