osl shader for Damas

Hello,
First of all, I’m from max/vray world, so don’t bane me right away, please.
I’m not a coder at all, and Bardo, on the vray forum, told me that I may look in blenderartists for custom made shader.
I’m looking for “Damas metal” shader and it should look photorealistic.
So, because I’m not a coder, I may be on the wrong path, so better to ask the pro for the following:

  • Can OSL be photorealistic?
  • Is blenderartists.org the right place to request such custom Shader?
  • Will this shader be compatible with vray/max or is there some difference between a blender OSL and Max/vray OSL?
  • What is the budget to write a shader? (is it compatible with small business artist like me?)

Thanks for your advice.

Hello,

That’s pretty cool. I’ve never heard of those blades

> Can OSL be photorealistic?
Yes, Sony has showed-off OSL in a few feature length movies already (e.g., MIB III, The Amazing Spider Man)

> Will this shader be compatible with vray/max or is there some difference between a blender OSL and Max/vray OSL?
It should pretty much be. That’s one of the core ideas of OSL after all.

> What is the budget to write a shader? (is it compatible with small business artist like me?)
> Is blenderartists.org the right place to request such custom Shader?
For those I will leave you in the more capable hands of others. Good luck :wink:
Tip: if you find an implementation of a Damas shader in a different language (glsl, hsl, …) it would be much easier for someone to help you.

thanks for the answer.
It sounds like there is not a lot of person able to handle this kind of shader.
Any idea about another forum where other language (glsl, hsl,…) are develop?
Thanks

If I see it correctly it is mainly the patterning that is distinctive (the general diffusion and gloss look a lot like regular (stainless) steel. The patterning looks like it could be implemented with banded perlin noise, although your picture has quite a different scale of banding than the images in the wikipedia article. Such banding could then drive the normal and/or additional glossiness or roughness.

Sounds like an interesting challenge. I can’t promiss anything but I will see if I can come up with a practical example the coming days to show you what I mean.

my first attempt (I know lighting is not my forte :wink:


The idea is to have some continuous noise values, check if they are within a certain range and if so use the value to drive a rapidly oscillating function. This a little bit like I did for my fingerprint shader, although that one used different noise. The node setup used for the image above looks like this (and as you can see I have experimented with different sources of noise):



The code for the shader is short (and could have been done in nodes only)


#include "stdosl.h"


shader bands(
  float Value=0,
  
  float Low=0,
  float High=1,
  
  float Frequency=1,
  
  output float Fac=0
){
  if( Value >= Low && Value <= High){
    Fac = (sin(Frequency*Value)+1)/2;
  }  
}



There are of course still a lot of issues here: the pattern on the original photo looks a bit more angular and the edges of the thin bands look much ‘tighter’ , probably because the blade is polished, leaving just the boundaries between the different steel compositions visible as hairlines while my shader creates bumps that are sinuses which are quite smooth in comparison. the latter can be solved by clamping the sinus or replacing it by another periodical function alltogether but the first is more of a challenge because it entails finding a noise function that fits the blade pattern better. A candidate might be marble noise (bands perturbed with perlin). And of course the shader as a whole should be better because now it looks more like aluminium coated plastic :slight_smile:

The osl is portable to vray, the nodes probably are not but the whole node setup could be coded as a self contained osl script without much work (every Cycles node can be implemented in osl with the exception of the actual material output node)

Thanks,
it really look like chinese all this code!
Let me try to render it and I will then psot the result.

Thanks,
I would like to give a try in Vray but reading your comments, I’m not so sure how to handle it:

  • Do I load only the OSL?
  • Do I need to couple it with a shader?
    As per the reflection, by using regular shader, the IOR must be different from line type A (white) than the one type B (dark). You are right about the polish, I believe that the metal have an orientation and the line catch the light differently according to orientation (like normal in CG word)
    I can see some a vector function on your shader. I’ve never seen it in Vray. I Need to find out if such function exist.
    Thanks

test answer

I know next to nothing about Vray so it is a bit guesswork for me :slight_smile:
The OSL shader just transforms a value to another value, in this case some noise to a value that is used to mix two different diffuse shaders, drive a bump node (that converts a height value to a normal) and finally it also drives the roughness of an anisotropic shader.
So in short: yes you do need to couple it to a shader :slight_smile: I guess it is possible in Vray to create two slightly different metal shaders and mix between them based on the output of an OSL shader?

[Edit: to make experimenting easier for you I have uploaded the .blend

(it does not contain the HDRi map from my example image but for the rest it is the same)

Because all those extra nodes might be distracting I also uploaded a slimmed down version that simply uses the value as a diffuse color so yo can see the effects of the parameters.

]

thanks for your time.
I tried but failed.
I copy past the code into the bloc note and then save it with .osl extension.
I load the file in the vray oso slot and it return nothing, neither an error message.

The mix of several shader is not a problem in vray, using the vrayblendmaterial, but I need to find out how what the .osl file needs to be interpreted in vray & 3Dsmax.


Looking at your screenshot, I wonder where is your .osl link in your node?
Thanks the .blend, I haven’t open blender since 15 years, sounds like I will have to sniff it a bit again.

just guessing here but because you refer to the ‘OSO’ slot, could it be that Vray needs a compiled shader? The .oso extension is used for files containing a compiled version of the .osl file. Blender takes care of this automatically but maybe Vray bundles the OSL compiler as a seperate tool? If so, that tool is probably called ‘oslc’ and should be run from the command line.

I want to help you but this is going to be strictly technical about OSL in V-Ray for Max and I apologize for this non-Blender targeted post.

Yes V-Ray is bundled with the OSL compiler (oslc), but it also takes care of OSL to OSO compilation automatically, so no problem there.
The thing is that OSL integration in 3ds Max is somewhat limited by the material editor which is not as powerful as Blender’s graph editor.

3ds Max expects textures to have color and (optionally) alpha output.
Every OSL output color parameter is considered as possible color output and
every OSL output float parameter is considered as possible alpha output.
As you can see in the screenshot you provided “Fac” is considered as alpha output because it’s a float.
Just change the type of the “Fac” parameter from output float to output color.

But that’s not all.
You need to feed some noise into your OSL shader node in 3ds Max.
3ds Max textures can be connected to other textures only via texture interfaces.
In other words in order for the “Value” input parameter to become “attachable” to other nodes it has to be a texture
and all OSL string parameters are by default considered textures in 3ds Max.
Again you need to change the type of “Value” to string and do a texture look up to get a float value.

Yeah … I know …

Best regards,
Ivan Mavrov

P.S. I am new to this forum. I’ll try and post a code sample as soon as I figure out how.

@iMavrov: thank you! It seems that there are quite some ‘interesting’ differences between the OSL integrations in Blender and Vray. :slight_smile:

I get your point about output socket and it would indeed be trivial to change Fac to a color, but do I understand it correctly that an OSL shader in Vray can only have textures (== strings) as inputs? That would it make very hard to parameterize shaders (as is done here with the High and Low parameters) …

Anyway, you need to post at least 10 messages or so before you are allowed attachments but you can include code snippets between
code brackets, like so (replace () by []):

(code)
… lines of code …
(/code)

@@varkenvarken: Thank you for the code tag hint.

OSL shaders in V-Ray can have input parameters of various types. The problem arises when you want an input connection socket to appear, so that you can connect the output of another node to your input parameter. In the 3ds Max material editor this is possible only for texture parameters so your input type should be changed to “string” and instead of working with your input parameter you do a texture look up to get the value you need. Here is the example:


// Modified bands shader.
// Original shader by varkenvarken.


#include "stdosl.h"


shader bands(
  string Value="some_noise_texture",
  
  float Low=0,
  float High=1,
  
  float Frequency=1,
  
  output color Fac=0
){
  float valueSample = texture(Value, u, v);
  
  if( valueSample >= Low && valueSample <= High){
    Fac = (sin(Frequency*valueSample)+1)/2;
  }  
}