UNPKG

mdx-m3-viewer

Version:

A browser WebGL model viewer. Mainly focused on models of the games Warcraft 3 and Starcraft 2.

3 lines (2 loc) 1.92 kB
declare const shader = "\n#ifdef SKIN\nattribute vec4 a_bones;\nattribute vec4 a_weights;\n\nvoid transformSkin(inout vec3 position, inout vec3 normal, inout vec3 tangent, inout vec3 binormal) {\n mat4 bone;\n\n bone += fetchMatrix(a_bones[0], 0.0) * a_weights[0];\n bone += fetchMatrix(a_bones[1], 0.0) * a_weights[1];\n bone += fetchMatrix(a_bones[2], 0.0) * a_weights[2];\n bone += fetchMatrix(a_bones[3], 0.0) * a_weights[3];\n\n mat3 rotation = mat3(bone);\n\n position = vec3(bone * vec4(position, 1.0));\n normal = rotation * normal;\n tangent = rotation * tangent;\n binormal = rotation * binormal;\n}\n#else\nattribute vec4 a_bones;\n#ifdef EXTENDED_BONES\nattribute vec4 a_extendedBones;\n#endif\nattribute float a_boneNumber;\n\nmat4 getVertexGroupMatrix() {\n mat4 bone;\n\n // For the broken models out there, since the game supports this.\n if (a_boneNumber > 0.0) {\n for (int i = 0; i < 4; i++) {\n if (a_bones[i] > 0.0) {\n bone += fetchMatrix(a_bones[i] - 1.0, 0.0);\n }\n }\n\n #ifdef EXTENDED_BONES\n for (int i = 0; i < 4; i++) {\n if (a_extendedBones[i] > 0.0) {\n bone += fetchMatrix(a_extendedBones[i] - 1.0, 0.0);\n }\n }\n #endif\n }\n\n return bone / a_boneNumber;\n}\n\nvoid transformVertexGroups(inout vec3 position, inout vec3 normal) {\n mat4 bone = getVertexGroupMatrix();\n mat3 rotation = mat3(bone);\n\n position = vec3(bone * vec4(position, 1.0));\n normal = normalize(rotation * normal);\n}\n\nvoid transformVertexGroupsHD(inout vec3 position, inout vec3 normal, inout vec3 tangent, inout vec3 binormal) {\n mat4 bone = getVertexGroupMatrix();\n mat3 rotation = mat3(bone);\n\n position = vec3(bone * vec4(position, 1.0));\n normal = normalize(rotation * normal);\n tangent = normalize(rotation * tangent);\n binormal = normalize(rotation * binormal);\n}\n#endif\n"; export default shader;