Find a cylinder normal based on hit vector from camera


I am working on a raytracing shader that tests for hits from cameraRays to a cylinder of radius R and center C, using cameraPosition as RayOrigin.

The cylinder raytracing works fine, but I am struggling to find the Normal of the hit position.

I thought about projecting the cameraToHitPoint (point is the hit point on cylinder) vector on the cylinder axis, normalizing it, but it doesn’t seem to work. Any idea?

Thank you.


If I understand you correctly, don’t use the cameraToHitPoint vector, use the hit point itself.

Something like normalize(hitPoint - projectOnto(hitPoint, cylinderAxis)) should work. But, without seeing your code, I can’t be 100% certain