Need help ray casting through objects in correlation with coefficients assigend to each object

Is there any way this can be achieved. I am a beginner.