I know I can get the ray length in OSL with the attribute path:ray_length, but can I get the ray angle (direction or source) so that I adjust the normal and reflect the ray accordingly?
Which angle do you mean? Three are multiple angles you can work with: incident angle to the geometric normal, smooth shaded normal or an arbitrary bump mapped normal. So in osl there’s no predefined variable for an angle. You need to compute it yourself using the dot product and acos.
However if you only want to reflect the direction along a given normal, you can use the reflect (I,N) function.
The incident angle gives me the direction from the viewing point to the position, but that’s not what I need. What I need is the direction from the last hit to the position in order to, for example, refract the indirect ray to a specific direction to create glass.
The way I understand this is, that the first hit point is the viewing position for the second hit point. The original viewing position is not relevant for any lighting computation further along the light path. That’s the recursive nature of ray tracing. It doesn’t make a difference whether you directly look at your second hit point from the location of the first hit point or whether the intersection originated from a recursive ray shooting.
You can also see, that the description of ‘I’ in the spec is a bit unfortunate, if you look at the description of the closure Ci. There’s no mention about viewing position anymore, but they just talk about the light leaving the surface point in the direction of ‘-I’.