View Full Version : Lambert shading and soft shadows from scratch in nodal

Dan_Ritchie

09-12-2014, 12:42 PM

There are times when it can be advantagous to create a shader from scratch in Nodal.

The Lambert shader is one of the most used and typical shading models in 3D. Here's how to make one from scratch.

https://www.youtube.com/watch?v=FRL5uFXh8C8

Soft shadows are easy to create using the raytrace node.

https://www.youtube.com/watch?v=ZDivyV3Mvmc

And one more on sub-surface scattering with a different aproach.

https://www.youtube.com/watch?v=SZn5TMFskdg

OnlineRender

09-12-2014, 01:54 PM

knocking it out the PARK.............................................. .. cheers!

Dan_Ritchie

09-12-2014, 05:46 PM

The nodes

http://www.squirreldome.com/download/nodes.zip

Sensei

09-12-2014, 06:40 PM

Unfortunately it's not entirely correct way.

When you reverse normal vector by multiplying by -1,-1,-1 (you can actually use math > vector > scale -100%)

and then dot will return value result is in range -1 .... +1

so if you would save it in format that's storing floating point values (like EXR or so),

info about -1 will be still there in image and might cause further issues during post-processing.

You should make sure that value is properly clamped.

After dot product there should be math > scalar > max with 0 as 2nd input.

After that we can be sure result is in range 0...+1

Clamping can be done in Effects window, Processing tab "Limit Dynamic Range",

but IMHO better do it in nodes..

Dan_Ritchie

09-13-2014, 11:41 AM

Unfortunately it's not entirely correct way.

When you reverse normal vector by multiplying by -1,-1,-1 (you can actually use math > vector > scale -100%)

and then dot will return value result is in range -1 .... +1

Yes, but dot product can produce a negative number regardless of if we multiply by -1 or not, because normals can always have a negative direction.

We can prove that there is a negative value by adding an ABS to the output from dot product.

124228

It's easy to solve using a logic node. Id rather use logic than a clamp because clamp required you to set an upper limit, which is non kosure for HDR, although I suppose you could pass the original value through, but I was trying to keep it programmy.

The logic reads something like "if input<0 then output=0 else use original input"

124229

Sensei

09-13-2014, 12:14 PM

Math > Scalar > Max

1st input - dot result

2nd input - 0.0

after that if dot result > 0.0, dot result is used

if it was <0.0, 0.0 is used.

Quick and simple.

Powered by vBulletin® Version 4.2.3 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.