var vShader =` uniform mat4 uProjectionMatrix; uniform mat4 uViewMatrix; uniform mat4 uModelMatrix; uniform mat4 uNormalMatrix; uniform bool uUseNormalMatrix; uniform vec3 uAmbientColor; uniform vec3 uDiffuseColor; uniform vec3 uLightDir; attribute vec3 aXYZ; attribute vec3 aColor; attribute vec3 aNormal; attribute vec4 aSphere; varying vec4 vSphere; varying vec3 vColor; varying vec3 vXYZ; void main () { mat4 mvMatrix = uViewMatrix * uModelMatrix; gl_Position = uProjectionMatrix * mvMatrix * vec4(aXYZ,1); mat4 nMatrix = uUseNormalMatrix?uNormalMatrix:mvMatrix; vColor = uAmbientColor*aColor; vec3 light = normalize(-uLightDir); vec3 normal = vec3(normalize(nMatrix*vec4(aNormal,0))); vColor += aColor*uDiffuseColor*max(dot(normal,light),0.0); vXYZ = (uModelMatrix * vec4(aXYZ,1)).xyz; vSphere = aSphere; } `; var fShader = ` precision mediump float; varying vec3 vColor; varying vec3 vXYZ; varying vec4 vSphere; uniform vec3 uEye; uniform vec3 uEyeForward; void main() { vec3 ray = uEye; vec3 step = normalize(uEyeForward); for (int i = 0; i < 100; i++) { float dist = distance(ray, vSphere.xyz) - vSphere.a; if (dist < 0.001) { if (vSphere.a == 0.0) { gl_FragColor = vec4(vColor,1.0); } else { gl_FragColor = vec4(1,0,0,1); } return; } ray += step * dist; } gl_FragColor = vec4(0,0,0,1); } `;