I've been working on integrating OSL shaders with BRL-CAD system. I've had
some problems with refraction that seemed to be solved, but now I have a
First, when a ray hits a surface like glass, osl system may generate a
reflected ray or a refraction ray. The refraction ray direction depends on
the relative index of refraction between the medium where the ray was shot
from and the medium where it was refracted.
Second, I'm using rt_shootray to shoot rays because I'm using BRL-CAD
scenes. Consider a ray shot this way and that hits a glass material at a
point P and that osl generated a refraction ray, namely R1. The first
problem I had was that whenever I shot ray R1 with rt_shootray, the
intersection point was always P. I was then told that I should get outhit
instead of inhit in this case.
The first time I did, the rendered scene looked odd. Then, I adjusted the
index of refraction of 'struct application' to 1.5, which was the refraction
index of the glass I was using. The scene look ok and I moved on.
But now, thinking about, there's something not making sense. If the index of
refraction matters, it seems BRL-CAD is using this information to calculate
a new direction for R1. But this ray was already a refraction ray returned
by OSL, that is, it's been refracted twice. It seems to me that the right
thing to do was to pass the index of refraction as 1.0, so BRL-CAD would not
change the direction of my ray and determine the next intersection point
correctly. But as I explained, this gives a wrong result.
Maybe I did not get the definition of outhit correctly. Any clarification?