Can OSL use amount of light as a factor?

(Oscalon) #1

Normally, Cycles cannot use the amount of light hitting a surface as an input within a material (whereas Blender Internal can.) With OSL, is this possible? I’d like to mix between two different textures based on the amount of light hitting a surface.

(Secrop) #2

The recurring question…

The whole purpose of Cycles is exactly this: find the amount of light hitting any point being sampled.
I don’t know if you get the irony in this… but that value will only be trully known after you render your scene with lots of samples.

Materials (shaders) are just representations of how the surface treats light rays, and they don’t know anything about those rays except, where they are comming from, and what type of ray they are. The light amount that a ray can carry it’s only known much later, after the shader has already been called.
So, no. You cannot use OSL to know that value.

You can hardcode light positions and orientations into your shader (no need for OSL here), but it will be very complicated to get the correct amount of light that hits the object. And your shader will be useless on any other scene; this is the main point for Cycles’ shaders, so that they produce an expected result no matter what are the lighting conditions of your scene (in other words, reusability).
It’s also possible to force the shader (with OSL) to throw rays in search for light sources, while the shader is being called… but this is not a good approach, and it’s better to bake illumination instead.

(IPv6) #3

Just do it in compositing, where light level can be deduced from image rendered

(shawn.kearney) #4

In Arnold you can use Lambert shader to return an RGB value at any given shading point. It’s not an absolute value, but I’ve done this here to return the dark side of an object as an emission matte:

I know that arnold can be kind of strange sometimes - and it’s not like I can just plug in standard surface into standard surface node (at least I don’t think you can) … but what exactly is doing on that allows arnold to behave this way?

Here’s another similar hack for thin glass, using a black reflective material to drive alpha:

(Secrop) #5

yes, but it’s not really a solution. you also have the diffuse_ramp and the phong_ramp closures in OSL that can do a similar effect.

(shawn.kearney) #6

definitely a hack, but it is a better solution than “it can’t be done”.