u probably are not getting it..!!
I am using 0 OR 1 only to check that if there is an intersection or not...
int id = checkIntersection(t1,camera, rayDirection);
in above code this 0 OR 1 is getting stored in "id" AND distance along that vector is getting stored in variable "t1" which i am using to travel along reflected vector.
anyways thank you for help !! i found solution to my problem the problem was in sphere intersection code.
correct code is..
int sphereIntersect(vec3 rayDir, vec3 rayOrigin, out float t1, in vec3 sCenter, in float sRadius)
rayDir = normalize(rayDir);
float B = 2.0 *( ( rayDir.x * (rayOrigin.x - sCenter.x ) )+ ( rayDir.y * (rayOrigin.y - sCenter.y )) + ( rayDir.z * (rayOrigin.z - sCenter.z ) ));
float C = pow((rayOrigin.x - sCenter.x),2.0) + pow((rayOrigin.y - sCenter.y),2.0) + pow((rayOrigin.z - sCenter.z),2.0) - pow(sRadius,2.0);
float D = B*B - 4.0*C ;
t1= (-B - pow(D, .5)) / 2.0;
if (t1 > 0.0)
return 0; //since determinant of quadratic equation <0 so no solution and hence no intersection
previously i was using both roots of quadratic equation which was wrong..!!
Thank you once again..