Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // VERTEX SHADER BODY
- code += "void main(void)\n";
- code += "{\n";
- // SKINNING
- if (options.skin) {
- code += " mat4 modelMatrix = vertex_boneWeights.x * getBoneMatrix(vertex_boneIndices.x) +\n";
- code += " vertex_boneWeights.y * getBoneMatrix(vertex_boneIndices.y) +\n";
- code += " vertex_boneWeights.z * getBoneMatrix(vertex_boneIndices.z) +\n";
- code += " vertex_boneWeights.w * getBoneMatrix(vertex_boneIndices.w);\n";
- if (lighting) {
- code += " mat3 normalMatrix = mat3(modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz);\n";
- }
- } else {
- code += " mat4 modelMatrix = matrix_model;\n";
- if (lighting) {
- code += " mat3 normalMatrix = matrix_normal;\n";
- }
- }
- code += "\n";
- // TRANSFORM
- code += " vec4 positionW = modelMatrix * vec4(vertex_position, 1.0);\n";
- code += " gl_Position = matrix_viewProjection * positionW;\n\n";
- if (lighting) {
- code += " vec3 normalW = normalMatrix * vertex_normal;\n";
- code += " normalW = normalize(normalW);\n";
- if (options.normalMap && useTangents) {
- code += " vec3 tangentW = normalMatrix * vertex_tangent.xyz;\n";
- code += " tangentW = normalize(tangentW);\n";
- }
- }
- code += "\n";
- // LIGHTING
- if (lighting) {
- if (options.normalMap && useTangents) {
- // Calculate the tangent space basis vectors
- code += " vec3 binormalW = cross(normalW, tangentW) * vertex_tangent.w;\n";
- code += " mat3 tbnMatrix = mat3(tangentW.x, binormalW.x, normalW.x,\n";
- code += " tangentW.y, binormalW.y, normalW.y,\n";
- code += " tangentW.z, binormalW.z, normalW.z);\n";
- code += " vViewDirW = tbnMatrix * (view_position - positionW.xyz);\n";
- for (i = 0; i < totalLights; i++) {
- if (i < totalDirs) {
- code += " vLight" + i + "DirW = -(tbnMatrix * light" + i + "_direction);\n";
- }
- if (i >= totalDirs) {
- code += " vLight" + i + "DirW = tbnMatrix * (light" + i + "_position - positionW.xyz);\n";
- }
- if (i >= totalDirs + totalPnts) {
- code += " vLight" + i + "SpotDirW = tbnMatrix * light" + i + "_spotDirection;\n";
- }
- }
- } else {
- code += " vNormalW = normalW;\n";
- code += " vViewDirW = view_position - positionW.xyz;\n";
- for (i = 0; i < totalLights; i++) {
- if (i < totalDirs) {
- code += " vLight" + i + "DirW = -light" + i + "_direction;\n";
- }
- if (i >= totalDirs) {
- code += " vLight" + i + "DirW = light" + i + "_position - positionW.xyz;\n";
- }
- if (i >= totalDirs + totalPnts) {
- code += " vLight" + i + "SpotDirW = light" + i + "_spotDirection;\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement