How to get the view vector?

So either from the camera to the surface, or the surface to the camera. But I cannot find a way to get that vector.

I tried state::direction(), but it’s always zero in my use case.

It’s clearly used internally somewhere because it’s needed for fresnel effects.


are you familiar with the strict separation of functions and material definitions in MDL? If not, I’d recommend our introductory presentation on MDL:

Assuming yes, in MDL all directional dependencies are reserved for the renderer (to allow for efficient rendering algorithms) and encapsulated in the components we provide for the material definitions. For example, the Fresnel effect is part of the




There is no direct access to the view or light directions in the render state that you could access from the MDL functions. The state::direction is solely reserved for environment lookups.

best regards,


I was aware of the lights not being accessible, but didn’t know for the view vector.

So I’m gonna inspect those fresnel functions to try to reproduce our material as much as possible.

Thanks for the answer.

Hi, there are also custom curve and measured curve BSDF modifiers that might be more flexible for you. What kind of material are you trying to model in MDL?

In our material, we simply allow to choose different functions to have fresnel effects. And most of them are based directly on the dot product between the normal and the view vector.

But I can see why they left the view vector outside of MDL to be independent from the system.

I will also investigate custom curve and measured curve.