Brief OSL capabilities?

I’ve been thinking of adapting a certain shader/rendering algorithm in Cycles, but as I never used OSL before, I don’t have an idea of what it can do and what it can’t as most of the shaders I’ve seen here are procedural textures, etc.
Briefly, what I need to do is Modify the camera ray origin and direction at a given pixel coordinate in the rendered image.
Is that something OSL can do? If so, can I have examples/links to similar shaders so I can get an initial push?
Thanks in advance!

That is something OSL is not supposed to do. You can check here its capabilities. Interferring with rays is not completly allowed.

It’s possible, however to use refraction and glossy to change a ray direction using normals, but not its origin as it’s the object surface that will throw the new ray. Also, if you want to control each pixel individually, you need to set the width in the Film panel to 1.0 and have the object of the size of the pixel (or use the ‘Window’ vector multiplied by the render resolution to have the pixel position data on the object).

A better solution would be to do it in composition.

Thanks for the reply!
Is there a solid, non hack’ish way to do it? Does the rendering kernel have a python api for instance?

well… I never tried it, and hope it’s working ok for cycles, but you can check the RenderEngine api:

this however doesn’t let you change the rays, unless you render the pixels you want with another camera, and then mix the final renders.

No, that would be way too slow to use. If it’s a data pass you’re after, OSL can do raytracing in the shader, but AFAIR you can’t get the final color that way, at best you can sample the normal, distance, etc. (you should check that, my memory is not all that reliable)

If it’s really important to you, modifying the Cycles kernel is probably your only option.

you should check that, my memory is not all that reliable

unfortunatelly no… just because you can only do it at the surface, where you can use normals. Inside a volume, there are no normals, and that’s not much you can do. :frowning:

Hmm I guess so :frowning:

Perhaps we’ll get a scattering angle enhancement to the volume scatter anisotropic function at some point :wink: