t values inside intersection programs

For intersection programs the current ray gets transformed to object space.
But i realized that the ray direction gets re-normalized? So t-values calculated in the intersection program can not be applied to world space rays.

I need the correct t-values in the closest hit program, what is the best way to get them since calculating the hit point, transforming the hit point and recalc the t-value for world space seems alot work…

How does rtPotentialIntersection do this to check the wrong t-values against the given range?

if you want only your intersection value, you can use rtIntersectionDistance:

rtDeclareVariable(float, intersectionDistance, rtIntersectionDistance, );

However we needed also another t values from intersection program, so we have to multiply it by this:

float3 rayDirObj = rtTransformVector(RT_WORLD_TO_OBJECT, opt_ray.direction);
float coef = 1.0f / length(rayDirObj);

Or more accurate (if ray.direction isn’t unit vector in ray generation):

float coef = length(opt_ray.direction) / length(rayDirObj);

Thank you it’s a great idea to calculate the coefficient. I did not think of this. Problem is i need the coefficient inside the intersection program. So i guess it would work like this instead?

float3 rayDirWorld = rtTransformVector(RT_OBJECT_TO_WORLD, current_ray.direction);
float coef = length(rayDirWorld);

Assuming the transform from object to world does not renormalize the vector of course.