Webgl glsl函数返回的值包含if语句

Webgl glsl函数返回的值包含if语句,webgl,shader,Webgl,Shader,我是webgl编程的初学者,还有很多东西要学。 我找到了一个包含此函数的现有片段着色器: float shadow(vec3 origin, vec3 ray) { float tSphere0 = intersectSphere(origin, ray, sphereCenter0, sphereRadius0); if(tSphere0 < 1.0) return 0.0; float tSphere1 = intersectSphere(origin,

我是webgl编程的初学者,还有很多东西要学。 我找到了一个包含此函数的现有片段着色器:

float shadow(vec3 origin, vec3 ray) { 
    float tSphere0 = intersectSphere(origin, ray, sphereCenter0, sphereRadius0); 
    if(tSphere0 < 1.0) return 0.0; 
    float tSphere1 = intersectSphere(origin, ray, sphereCenter1, sphereRadius1); 
    if(tSphere1 < 1.0) return 0.0; 
    float tSphere2 = intersectSphere(origin, ray, sphereCenter2, sphereRadius2); 
    if(tSphere2 < 1.0) return 0.0; 
    float tSphere3 = intersectSphere(origin, ray, sphereCenter3, sphereRadius3); 
    if(tSphere3 < 1.0) return 0.0;  
    return 1.0;
} 

你没有提供这个功能。函数
intersectSphere
不是WebGL的一部分。这是一个用户提供的函数。只是猜测一下,如果向量原点->光线与所有4个球体相交,它看起来将返回1.0,否则返回0.0。至于它意味着什么。它的意思是“如果向量原点->射线与所有4个球体相交,则返回1。否则返回0”。您可以发布
intersectSphere
的源代码吗?
float intersectSphere(vec3 origin, vec3 ray, vec3 sphereCenter, float sphereRadius) {   
    vec3 toSphere = origin - sphereCenter;   
    float a = dot(ray, ray);   
    float b = 2.0 * dot(toSphere, ray);   
    float c = dot(toSphere, toSphere) - sphereRadius*sphereRadius;   
    float discriminant = b*b - 4.0*a*c;   
    if(discriminant > 0.0) {     
        float t = (-b - sqrt(discriminant)) / (2.0 * a);     
        if(t > 0.0) return t;   }   
    return 10000.0; 
}