2
$\begingroup$

I'm beginner in osl I want to make simple fresnel by Open Shading Language:

my problem is I can't find view direction in osl documention

shader Fresnel
(
    output color Out = 0.0,
)
{   
    vector Fresnel = 1.-dot(N,ViewDir);
    Out = Fresnel;  
}

and this is my error

Line 11: error: 'ViewDir' was not declared in this scope

I want result like this:

enter image description here

I tried to transform but not work:

vector WorldPos = transform("camera","world",point(0,0,0));
vector CameraWorldPos = transform ("camera", "world",(1.,0.,0.));
vector viewDirection = CameraWorldPos - WorldPos;
$\endgroup$

1 Answer 1

0
$\begingroup$

The OSL global variable you're looking for is I

From the docs:

vector I

The incident ray direction, pointing from the viewing position to the shading position P.

So, what's called 'View Dir' in your illustration is -I

Note that the 'viewing position' is the origin of any ray, not just those originating at the viewpoint/camera

EDIT: however, this is the shader which works as you expected in your post:

shader naive_fresnel(

           normal Normal = N,    
    output  float  Fac = 0.0 

)
{
    Fac = 1.0 - dot(normalize(Normal),I);
}

... which means I must be pointing towards the viewpoint? (BTW, the dot-product produces a scalar value, not a vector)

Loosely speaking, to Cycles, being physically-based, everything is a light, either directly, by emission, or indirectly, by scattering or reflection.

In standard use, how rays are actually cast is down to the integrator, not the shaders. OSL provides no direct access to the direction to lamps: the notion is that this kind of 'fake' is not required, or desirable, in a physically-based renderer.

$\endgroup$
6
  • $\begingroup$ oh thanks! I didn't test -I.I have another simple question that I will appreciate if you answer me what is LightDirection? because I tried Lambert = dot(N,I) and it was black $\endgroup$ Commented Feb 4, 2019 at 21:01
  • $\begingroup$ @SeyedMortezaKamali see edit .. $\endgroup$
    – Robin Betts
    Commented Feb 5, 2019 at 9:09
  • $\begingroup$ thanks I asked this question before your editing I use 3dsmax osl do you know 3dsmax has access to light? can I access by something like this point L = transform("Lamp"); $\endgroup$ Commented Feb 5, 2019 at 9:17
  • $\begingroup$ @SeyedMortezaKamali I suspect not, in a path-tracer, for the reasons given in the edit, (although there are tricks, keeping manual track of the directions to objects in the scene, outside OSL). Let's see if a real expert comes along to give you another angle in their answer to your other question. $\endgroup$
    – Robin Betts
    Commented Feb 5, 2019 at 9:36
  • $\begingroup$ @SeyedMortezaKamali .. the point being, that Phong and Blinn are methods for faking an approximation of the response of a surface to direct lighting, whereas a renderer like Cycles simulates it, by chucking thousands of rays around. $\endgroup$
    – Robin Betts
    Commented Feb 5, 2019 at 9:43

You must log in to answer this question.

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