I am new, but this is what I see:
You can find
camera_distance(kg, sd->P) in
kernel_passes.h at line 263.
sd is passed into the function at line 173:
ccl_device_inline void kernel_write_data_passes(KernelGlobals *kg,
ccl_global float *buffer,
ccl_addr_space PathState *state,
ShaderData is defined in
kernel_types.h (line 932). It’s long, so I won’t post here, but some data includes:
/* position */
/* smooth normal for shading */
/* true geometric normal */
/* view/incoming direction */
Again, I am not an expert. I hope someone more knowledgeable corrects me if I’m mistaken or missing anything. I would like to learn Cycles so I hope this helps. If you’d like help with your project, I’d be interested in exploring some of the things you’re asking about.