UNPKG

@tolokoban/tgd

Version:

ToloGameDev library for WebGL2

2 lines 1.67 kB
export declare const VERT = "#version 300 es\n\nprecision highp float;\n\nuniform mat4 uniModelViewMatrix;\nuniform mat4 uniProjectionMatrix;\nuniform float uniMinRadius;\n\n//===================\n// Vertex attributes\n//-------------------\n\n// Position of the vertex, relative to\n// the current center and assuming a\n// radius of 1.\nin vec3 POSITION;\n// What tip is your center: 0 (base) or 1 (tip).\nin float attTip;\n// Normals of the tube that represents the segment.\nin vec3 NORMAL;\n\n//=====================\n// Instance attributes\n//---------------------\n\n// Coords and radius of base.\nin vec4 attXYZR0;\n// Coords and radius of tip.\nin vec4 attXYZR1;\n// The color is taken from a texture.\nin vec2 attUV0;\nin vec2 attUV1;\n\nvoid main() {\n vec3 pos = POSITION;\n vec4 xyzr = mix(attXYZR0, attXYZR1, attTip);\n vec3 center = xyzr.xyz;\n float radius = max(\n xyzr.w,\n uniMinRadius * (uniProjectionMatrix * uniModelViewMatrix * vec4(center, 1)).w\n );\n vec3 dir = attXYZR1.xyz - attXYZR0.xyz;\n float len = length(dir);\n if (len == 0.0) {\n // Just a sphere\n pos *= radius;\n pos += center.xyz;\n varNormal = NORMAL;\n } else {\n // Full capsule\n vec3 Z = dir / len;\n vec3 v = abs(Z.z) > 0.7 ? vec3(1,0,0) : vec3(0,0,1);\n vec3 Y = cross(v, Z);\n vec3 X = cross(Y, Z);\n mat3 mat = mat3(X, Y, Z);\n pos *= radius;\n pos = mat * pos + center.xyz;\n varNormal = mat * NORMAL;\n }\n gl_Position = uniProjectionMatrix * uniModelViewMatrix * vec4(pos, 1);\n}"; //# sourceMappingURL=segments.vert.d.ts.map