All files / src/WebGL/shaders/lib/stickimposter stickimposter.vert

100% Statements 1/1
100% Branches 0/0
100% Functions 0/0
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

118x
export default "\n\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 directionalLightColor[ 1 ];\nuniform vec3 directionalLightDirection[ 1 ];\n\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec3 color;\nattribute float radius;\n\nvarying vec3 vColor;\nvarying vec3 vLight;\nvarying vec3 cposition;\nvarying vec3 p1;\nvarying vec3 p2;\nvarying float r;\n\nvoid main() {\n\n    vColor = color; vColor.z = abs(vColor.z); //z indicates which vertex and so would vary\n    r = abs(radius);\n    vec4 to = modelViewMatrix*vec4(normal, 1.0); //normal is other point of cylinder\n    vec4 pt = modelViewMatrix*vec4(position, 1.0);\n    vec4 mvPosition = pt;\n    p1 = pt.xyz; p2 = to.xyz;\n    vec3 norm = to.xyz-pt.xyz;\n    float mult = 1.1; //slop to account for perspective of sphere\n    if(length(p1) > length(p2)) { //billboard at level of closest point\n       mvPosition = to;\n    }\n    vec3 n = normalize(mvPosition.xyz);\n//intersect with the plane defined by the camera looking at the billboard point\n    if(color.z >= 0.0) { //p1\n       if(projectionMatrix[3][3] == 0.0) { //perspective\n         vec3 pnorm = normalize(p1);\n         float t = dot(mvPosition.xyz-p1,n)/dot(pnorm,n);\n         mvPosition.xyz = p1+t*pnorm; \n       } else { //orthographic\n         mvPosition.xyz = p1;\n       }\n    } else {\n      if(projectionMatrix[3][3] == 0.0) { //perspective\n         vec3 pnorm = normalize(p2);\n         float t = dot(mvPosition.xyz-p2,n)/dot(pnorm,n);\n         mvPosition.xyz = p2+t*pnorm;\n       } else { //orthographic\n         mvPosition.xyz = p2;\n       } \n       mult *= -1.0;\n    }\n    vec3 cr = normalize(cross(mvPosition.xyz,norm))*radius;\n    vec3 doublecr = normalize(cross(mvPosition.xyz,cr))*radius;\n    mvPosition.xyz +=  mult*(cr + doublecr).xyz;\n    cposition = mvPosition.xyz;\n    gl_Position = projectionMatrix * mvPosition;\n    vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ 0 ], 0.0 );\n    vLight = normalize( lDirection.xyz )*directionalLightColor[0]; //not really sure this is right, but color is always white so..\n}\n\n";