1
$\begingroup$

I'm beginner in osl my problem is I couldn't find Light direction in osl documention to make lambert lighting model

shader Lambert(
output color Result = 0.    
)
{
Result = dot(N,LightDir);   
}

and this is my error:

Line 5: error: 'LightDir' was not declared in this scope

I need result like this:

enter image description here

$\endgroup$
1
  • $\begingroup$ @RichSedman can you explain more? I just need Light Direction $\endgroup$ Commented Feb 5, 2019 at 13:31

1 Answer 1

1
$\begingroup$

You can't actually access the Lamp location directly within OSL (see Getting a light vector in OSL for Blender) but you can feed a Vector representing the lamp location into the shader to use in the calculation. The Vector can be captured directly from the Lamp location by using Drivers so that moving the lamp automatically affects the shading.

OSL lamp location

Here the Combine XYZ node has been setup with Drivers (right-click and Add Driver and then set up the driver to set each value to Lamp X Location, Y Location, Z Location). The Subtract Vector Maths node creates a vector by subtracting the Position of the point on the surface and the Normalize ensures it's of length 1. The result is passed into the OSL node to represent the direction of the Lamp.

Since the lamp location is captured using Drivers, moving the lamp automatically updates the Combine XYZ node to represent the new lamp location.

For multiple lamps you would need to add multiple Combine XYZ nodes, each driver by the respective lamp, and each passed into the OSL node on a new input to include in your calculation.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .