OSL | Normal mapping shaders

Forums: OSL | Normal mapping shaders
Sub forum for help and tutorials.

Moderator: aoktar

OSL | Normal mapping shaders

Postby milanm » Thu May 23, 2019 9:00 pm

milanm Thu May 23, 2019 9:00 pm
This is going to be a topic about some (hopefully) useful OSL scripts that can help you regain control over your normal maps. I will be posting them as they are finished. I will also optimize and clean up the code over time and hopefully add some more features.

Some things you can expect to see here:

  • Height to Normal
  • Layering normal maps
  • Completely custom normal mapping method (without using normal map pin!)
  • Descriptions and examples how to use all of the above
  • Hopefully a lot more



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 | Normal mapping shaders

Postby milanm » Fri May 24, 2019 6:43 am

milanm Fri May 24, 2019 6:43 am
Ok, let's get this started. First shader is:

mm_HeightToNormal

Here is how the UI should look like by default with all of the default values and an example node graph setup.
UI.jpg


mm_HeightToNormal.zip
(1.44 KiB) Downloaded 2453 times


I’ve been working on this one for a while as I was learning more and more about normal maps in Octane. It went through a lot of changes and adjustments. I use it on a daily basis and whenever I would be annoyed by something or wish that some parameter had a different min/max value, I would change that. It solves a few limitations of the builtin bump map input and it gives you total control.

Description
This node converts a bump/height map into a tangent space normal map based on average, luminance or the intensity of each RGB channel.

Usage
Connect an image texture node with your bump map to the Input pin. Give it OSL delayed UV projection. Adjust Radius and Power to control intensity of the map, and that's it! If you find that you need to use too high or too small values, adjust Scale. Default values for quality and source should work just fine most of the time.

Parameters

- Input
Connect your ImageTexture node with a bump/height map here.

IMPORTANT: For your ImageTexture node to work, you need to connect a Texture Projection node with ‘OSL delayed UV’ projection. Don’t worry, you can still add your own projection in the Projection input of the OSL shader. :)

- Projection
You can add your Texture Projection node here. By default this input should return Mesh UV but currently, in C4D, without anything connected, projection will be box for some reason so make sure you add a Texture Projection node here.

- Source
Here you can choose how the height information is extracted from your texture. Default value is Green because that channel is the least affected by compression artifacts. If you want to mach how your displacement map looks you can choose the Red channel here.

Average – average of all three channels.
Luminance – luminance of a color according to ITU-R.
Red, Green, Blue – Individual channel intensity.

htm vs disp.png


- Quality
Here you can choose the method that does the sampling and conversion. These methods are based on standard convolution filters.

Low quality method is using 3 samples. Cheap + fast. Works great on procedural maps.
Medium - 4 samples – This the default. Almost as good as high with only 4 samples.
High (slow) - 8 samples. This is using a sobol algorithm. Great results but 2x more samples than medium.

What this means is that any node graph connected on Input will be evaluated 3,4 or 8 times in order to create a color of one sample that this shader is returning as a result. If you have a very complex network of procedural nodes or too many layered textures connected on input you will quickly realize what I meant by “(slow)” (and why SD is such a popular tool). In most cases, if you are just converting a bump map into normal map, you will not notice any performance issues but in some extreme cases you might want to use a baking texture after this shader

Quality.jpg


- Radius
Radius of the area that is sampled. You can think of this as blur. But for bump/normal maps, blur also means “more intense”. Also this is one parameter that we don’t have in the Octane default bump input. If you take a big texture and use transform node to scale it down too much you might run into the issue that you see below. In this OSL shader you can easily avoid that by adjusting Radius to a smaller value.

radius.jpg


- Power
This is blending between the resulting normal map and a neutral (0.5,0.5,1) value. Basically this changes the total intensity of your normal map but it also deforms the shape of the features in your map a bit as it gets lower. That ‘deformation’ also tends to reduce artifacts so sometimes it’s a desired effect.

- PowerMap
You can add a texture here to modulate the Power parameter. For example, you can use this to paint-out your normal map from certain areas of your model. This input does not need a OSL delayed UV.

- Z_Power
This changes the influence of the blue/Z channel of the normal map. Reducing this can reduce some artifacts that are typical for normal maps. Also this allows you to preserve the shapes of the features in your normal map as you reduce Power. Since normal maps depend a lot on the viewing angle, sometimes you might want to increase this parameter, the option is there for you.

- Scale
This value is scaling the sensitivity of Radius and Power. Since those parameters will change a lot depending on the resolution or tiling scale of your map, I added this option to avoid dealing with too small or too big values with a lot of zeroes and having to type them in.

- Radius_x_Source and Power_x_Source
These parameters allow you to use height information from your map to scale Radius or Power. Depending on the level of sharpness of the features in your map, sometimes you might want to increase one or the other.

x-source.jpg


- Falloff
This parameter will reduce the Power of the map on the edges of your object. It is based on view direction and it’s a cheap way of faking parallax but it also helps avoid some annoying specular highlights and other artifacts.

Limitations/To do
Currently, this node doesn’t support Z from XYZtoUVW projection. It is evaluating textures only in UV space. I have an idea how to solve this.

Have fun!
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 | Normal mapping shaders

Postby Jolbertoquini » Tue May 28, 2019 8:40 am

Jolbertoquini Tue May 28, 2019 8:40 am
milanm wrote:Ok, let's get this started. First shader is:

mm_HeightToNormal

Here is how the UI should look like by default with all of the default values and an example node graph setup.
UI.jpg


mm_HeightToNormal.zip


I’ve been working on this one for a while as I was learning more and more about normal maps in Octane. It went through a lot of changes and adjustments. I use it on a daily basis and whenever I would be annoyed by something or wish that some parameter had a different min/max value, I would change that. It solves a few limitations of the builtin bump map input and it gives you total control.

Description
This node converts a bump/height map into a tangent space normal map based on average, luminance or the intensity of each RGB channel.

Usage
Connect an image texture node with your bump map to the Input pin. Give it OSL delayed UV projection. Adjust Radius and Power to control intensity of the map, and that's it! If you find that you need to use too high or too small values, adjust Scale. Default values for quality and source should work just fine most of the time.

Parameters

- Input
Connect your ImageTexture node with a bump/height map here.

IMPORTANT: For your ImageTexture node to work, you need to connect a Texture Projection node with ‘OSL delayed UV’ projection. Don’t worry, you can still add your own projection in the Projection input of the OSL shader. :)

- Projection
You can add your Texture Projection node here. By default this input should return Mesh UV but currently, in C4D, without anything connected, projection will be box for some reason so make sure you add a Texture Projection node here.

- Source
Here you can choose how the height information is extracted from your texture. Default value is Green because that channel is the least affected by compression artifacts. If you want to mach how your displacement map looks you can choose the Red channel here.

Average – average of all three channels.
Luminance – luminance of a color according to ITU-R.
Red, Green, Blue – Individual channel intensity.

htm vs disp.png


- Quality
Here you can choose the method that does the sampling and conversion. These methods are based on standard convolution filters.

Low quality method is using 3 samples. Cheap + fast. Works great on procedural maps.
Medium - 4 samples – This the default. Almost as good as high with only 4 samples.
High (slow) - 8 samples. This is using a sobol algorithm. Great results but 2x more samples than medium.

What this means is that any node graph connected on Input will be evaluated 3,4 or 8 times in order to create a color of one sample that this shader is returning as a result. If you have a very complex network of procedural nodes or too many layered textures connected on input you will quickly realize what I meant by “(slow)” (and why SD is such a popular tool). In most cases, if you are just converting a bump map into normal map, you will not notice any performance issues but in some extreme cases you might want to use a baking texture after this shader

Quality.jpg


- Radius
Radius of the area that is sampled. You can think of this as blur. But for bump/normal maps, blur also means “more intense”. Also this is one parameter that we don’t have in the Octane default bump input. If you take a big texture and use transform node to scale it down too much you might run into the issue that you see below. In this OSL shader you can easily avoid that by adjusting Radius to a smaller value.

radius.jpg


- Power
This is blending between the resulting normal map and a neutral (0.5,0.5,1) value. Basically this changes the total intensity of your normal map but it also deforms the shape of the features in your map a bit as it gets lower. That ‘deformation’ also tends to reduce artifacts so sometimes it’s a desired effect.

- PowerMap
You can add a texture here to modulate the Power parameter. For example, you can use this to paint-out your normal map from certain areas of your model. This input does not need a OSL delayed UV.

- Z_Power
This changes the influence of the blue/Z channel of the normal map. Reducing this can reduce some artifacts that are typical for normal maps. Also this allows you to preserve the shapes of the features in your normal map as you reduce Power. Since normal maps depend a lot on the viewing angle, sometimes you might want to increase this parameter, the option is there for you.

- Scale
This value is scaling the sensitivity of Radius and Power. Since those parameters will change a lot depending on the resolution or tiling scale of your map, I added this option to avoid dealing with too small or too big values with a lot of zeroes and having to type them in.

- Radius_x_Source and Power_x_Source
These parameters allow you to use height information from your map to scale Radius or Power. Depending on the level of sharpness of the features in your map, sometimes you might want to increase one or the other.

x-source.jpg


- Falloff
This parameter will reduce the Power of the map on the edges of your object. It is based on view direction and it’s a cheap way of faking parallax but it also helps avoid some annoying specular highlights and other artifacts.

Limitations/To do
Currently, this node doesn’t support Z from XYZtoUVW projection. It is evaluating textures only in UV space. I have an idea how to solve this.

Have fun!
Milan


Thanks a lot Milan Great Job! I was wondering if we could have a option of blur I guess add the osl blur texture before the imager?

best,
JO
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
User avatar
Jolbertoquini
Licensed Customer
Licensed Customer
 
Posts: 1067
Joined: Sun Aug 31, 2014 7:08 am
Location: London

Re: OSL | Normal mapping shaders

Postby Terryvfx » Thu May 30, 2019 3:21 am

Terryvfx Thu May 30, 2019 3:21 am
This is insane, thank you very much for putting this out! :shock:
I'm waiting for the rest of the nodes, specially the one for mixing normal maps.
User avatar
Terryvfx
Licensed Customer
Licensed Customer
 
Posts: 358
Joined: Tue Dec 30, 2014 12:43 am

Re: OSL | Normal mapping shaders

Postby LOVEXMEDIA » Thu Jan 30, 2020 4:06 pm

LOVEXMEDIA Thu Jan 30, 2020 4:06 pm
Is this still something that will be coming to Octane at some point?
LoveyDov3
https://www.instagram.com/lvydov3/
i9-10940x [Custom Loop] • 96GB RAM • 2× NVLinkRTX 3090 FE
User avatar
LOVEXMEDIA
Licensed Customer
Licensed Customer
 
Posts: 36
Joined: Wed Jun 07, 2017 1:19 am

Re: OSL | Normal mapping shaders

Postby itsallgoode9 » Fri May 01, 2020 4:25 pm

itsallgoode9 Fri May 01, 2020 4:25 pm
LOVEXMEDIA wrote:Is this still something that will be coming to Octane at some point?


Oh yes, a height to normal node built in would be amazing!
Intel i7-3930K, 64gb RAM, Asus X79 Deluxe mobo, 2x EVGA 780 6gb (for rendering), 1x PNY quaddro k4000 (for display)
Windows 8.1 x64, Maya 2014, Octane Render v2
itsallgoode9
Licensed Customer
Licensed Customer
 
Posts: 885
Joined: Thu Apr 03, 2014 9:04 am
Location: New York City

Re: OSL | Normal mapping shaders

Postby jordi » Tue Apr 20, 2021 11:51 am

jordi Tue Apr 20, 2021 11:51 am
Any idea how to implemented on Houdini with a noise node as bump source?
Thanks a lot.
jordi
Licensed Customer
Licensed Customer
 
Posts: 4
Joined: Sun Sep 13, 2015 7:10 pm

Return to Help / Tutorials


Who is online

Users browsing this forum: No registered users and 4 guests

Thu Apr 18, 2024 7:10 am [ UTC ]