Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Is OSL "N" the same as C++ sg->Nf ?

Anonymous

Is OSL "N" the same as C++ sg->Nf ?

Anonymous
Not applicable

Is OSL "N" the same as C++ sg->Nf or sg->N ??

0 Likes
Reply
358 Views
4 Replies
  • OSL
Replies (4)

madsd
Advisor
Advisor

OSL N source the mesh/face normals.

0 Likes

Anonymous
Not applicable

This shader does not work because the dot product never yields a value less than zero because N is in effect a front facing normal.


shader

sidemask(

color rearColor = color(0.7, 0.7, 0),

color frontColor = color(1,0,0),

output color resultRGB = 0)

{

vector i = normalize(-I);

vector n = normalize(N);

float angle = dot(i,n); // the cosine of the angle


// When the angle becomes negative we are shading

// the rear surface.

if(angle < 0)

resultRGB = rearColor;

else

resultRGB = frontColor;

}


0 Likes

adrien.herubel
Autodesk
Autodesk

In our implementation N in OSL corresponds to `Nf` in the C++ shader globals, meaning

the face-forward shading normal.


Ng corresponds to Ngf in the C++ shader globals, meaning the face-forward geometric normal.


To detect whether the shader is being executed on a back face, you would need to use the backfacing () function.

0 Likes

Anonymous
Not applicable

Many thanks.

Malcolm


0 Likes