]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - shader_glsl.h
implemented gpu-skinning (vertex shader skeletal animation), can be
[xonotic/darkplaces.git] / shader_glsl.h
index dcb9c7051af13b7db51916d5e917d8d7fc52fd88..ac0dd80a48f673ab4282291b054cda1c172cff9f 100644 (file)
 "dp_attribute vec3 Attrib_TexCoord2; // tvector\n"
 "dp_attribute vec3 Attrib_TexCoord3; // normal\n"
 "dp_attribute vec4 Attrib_TexCoord4; // lightmap texcoords\n"
+"#ifdef USESKELETAL\n"
+"//uniform mat4 Skeletal_Transform[128];\n"
+"uniform vec4 Skeletal_Transform12[768];\n"
+"dp_attribute vec4 Attrib_SkeletalIndex;\n"
+"dp_attribute vec4 Attrib_SkeletalWeight;\n"
+"#endif\n"
 "#endif\n"
 "dp_varying mediump vec4 VertexColor;\n"
 "\n"
 "#ifdef VERTEX_SHADER\n"
 "void main(void)\n"
 "{\n"
+"#ifdef USESKELETAL\n"
+"      ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n"
+"      ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n"
+"      ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n"
+"      vec4 sw = Attrib_SkeletalWeight;\n"
+"      vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n"
+"      vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n"
+"      vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n"
+"      mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n"
+"      vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n"
+"#define Attrib_Position SkeletalVertex\n"
+"#endif\n"
 "      gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n"
 "#ifdef USETRIPPY\n"
 "      gl_Position = TrippyVertex(gl_Position);\n"
 "#ifdef VERTEX_SHADER\n"
 "void main(void)\n"
 "{\n"
+"#ifdef USESKELETAL\n"
+"      ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n"
+"      ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n"
+"      ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n"
+"      vec4 sw = Attrib_SkeletalWeight;\n"
+"      vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n"
+"      vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n"
+"      vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n"
+"      mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n"
+"      vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n"
+"#define Attrib_Position SkeletalVertex\n"
+"#endif\n"
 "      gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n"
 "      VertexColor = vec4(gl_Position.z, gl_Position.z, gl_Position.z, 1.0);\n"
 "#ifdef USETRIPPY\n"
 "#ifdef VERTEX_SHADER\n"
 "void main(void)\n"
 "{\n"
+"#ifdef USESKELETAL\n"
+"      ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n"
+"      ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n"
+"      ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n"
+"      vec4 sw = Attrib_SkeletalWeight;\n"
+"      vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n"
+"      vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n"
+"      vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n"
+"      mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n"
+"      vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n"
+"#define Attrib_Position SkeletalVertex\n"
+"#endif\n"
 "      VertexColor = Attrib_Color;\n"
 "#ifdef USEDIFFUSE\n"
 "      TexCoord1 = Attrib_TexCoord0.xy;\n"
 "\n"
 "void main(void)\n"
 "{\n"
+"#ifdef USESKELETAL\n"
+"      ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n"
+"      ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n"
+"      ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n"
+"      vec4 sw = Attrib_SkeletalWeight;\n"
+"      vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n"
+"      vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n"
+"      vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n"
+"      mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n"
+"      vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n"
+"#define Attrib_Position SkeletalVertex\n"
+"#endif\n"
 "#ifdef USEALPHAGENVERTEX\n"
 "      VertexColor = Attrib_Color;\n"
 "#endif\n"
 "\n"
 "void main(void)\n"
 "{\n"
+"#ifdef USESKELETAL\n"
+"      ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n"
+"      ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n"
+"      ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n"
+"      vec4 sw = Attrib_SkeletalWeight;\n"
+"      vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n"
+"      vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n"
+"      vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n"
+"      mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n"
+"      mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz));\n"
+"      vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n"
+"      vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n"
+"      vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n"
+"      vec3 SkeletalNormal  = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n"
+"#define Attrib_Position SkeletalVertex\n"
+"#define Attrib_TexCoord1 SkeletalSVector\n"
+"#define Attrib_TexCoord2 SkeletalTVector\n"
+"#define Attrib_TexCoord3 SkeletalNormal\n"
+"#endif\n"
 "#ifdef USEALPHAGENVERTEX\n"
 "      VertexColor = Attrib_Color;\n"
 "#endif\n"
 "#     ifdef USESHADOWMAPPCF\n"
 "#       define texval(off) dp_shadow2D(Texture_ShadowMap2D, vec3(off, shadowmaptc.z))  \n"
 "      vec2 offset = fract(shadowmaptc.xy - 0.5);\n"
-"      vec4 size = vec4(offset + 1.0, 2.0 - offset), weight = (vec4(1.0, 1.0, -0.5, -0.5) + (shadowmaptc.xy - 0.5*offset).xyxy)*ShadowMap_TextureScale.xyxy;\n"
+"   vec4 size = vec4(offset + 1.0, 2.0 - offset);\n"
+"#       if USESHADOWMAPPCF > 1\n"
+"   vec2 center = (shadowmaptc.xy - offset + 0.5)*ShadowMap_TextureScale;\n"
+"   vec4 weight = (vec4(-1.5, -1.5, 2.0, 2.0) + (shadowmaptc.xy - 0.5*offset).xyxy)*ShadowMap_TextureScale.xyxy;\n"
+"      f = (1.0/25.0)*dot(size.zxzx*size.wwyy, vec4(texval(weight.xy), texval(weight.zy), texval(weight.xw), texval(weight.zw))) +\n"
+"              (2.0/25.0)*dot(size, vec4(texval(vec2(weight.z, center.y)), texval(vec2(center.x, weight.w)), texval(vec2(weight.x, center.y)), texval(vec2(center.x, weight.y)))) +\n"
+"              (4.0/25.0)*texval(center);\n"
+"#       else\n"
+"      vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (shadowmaptc.xy - 0.5*offset).xyxy)*ShadowMap_TextureScale.xyxy;\n"
 "      f = (1.0/9.0)*dot(size.zxzx*size.wwyy, vec4(texval(weight.zw), texval(weight.xw), texval(weight.zy), texval(weight.xy)));\n"
-"//#       define texval(x, y) dp_shadow2D(Texture_ShadowMap2D, vec3(center + vec2(x, y)*ShadowMap_TextureScale, shadowmaptc.z))  \n"
-"//    vec2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n"
-"//    f = dot(vec4(0.25), vec4(texval(-0.4, 1.0), texval(-1.0, -0.4), texval(0.4, -1.0), texval(1.0, 0.4)));\n"
+"#       endif        \n"
 "#     else\n"
 "      f = dp_shadow2D(Texture_ShadowMap2D, vec3(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z));\n"
 "#     endif\n"
 "uniform highp mat4 ModelViewMatrix;\n"
 "void main(void)\n"
 "{\n"
+"#ifdef USESKELETAL\n"
+"      ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n"
+"      ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n"
+"      ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n"
+"      vec4 sw = Attrib_SkeletalWeight;\n"
+"      vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n"
+"      vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n"
+"      vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n"
+"      mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n"
+"      mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz));\n"
+"      vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n"
+"      vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n"
+"      vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n"
+"      vec3 SkeletalNormal  = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n"
+"#define Attrib_Position SkeletalVertex\n"
+"#define Attrib_TexCoord1 SkeletalSVector\n"
+"#define Attrib_TexCoord2 SkeletalTVector\n"
+"#define Attrib_TexCoord3 SkeletalNormal\n"
+"#endif\n"
 "      TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, 0.0, 0.0);\n"
 "#ifdef USEVERTEXTEXTUREBLEND\n"
 "      VertexColor = Attrib_Color;\n"
 "#endif\n"
 "void main(void)\n"
 "{\n"
+"#ifdef USESKELETAL\n"
+"      ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n"
+"      ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n"
+"      ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n"
+"      vec4 sw = Attrib_SkeletalWeight;\n"
+"      vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n"
+"      vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n"
+"      vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n"
+"      mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n"
+"//    ivec4 si = ivec4(Attrib_SkeletalIndex);\n"
+"//    mat4 SkeletalMatrix = Skeletal_Transform[si.x] * Attrib_SkeletalWeight.x + Skeletal_Transform[si.y] * Attrib_SkeletalWeight.y + Skeletal_Transform[si.z] * Attrib_SkeletalWeight.z + Skeletal_Transform[si.w] * Attrib_SkeletalWeight.w;\n"
+"      mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz));\n"
+"      vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n"
+"      SkeletalVertex.w = 1.0;\n"
+"      vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n"
+"      vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n"
+"      vec3 SkeletalNormal  = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n"
+"#define Attrib_Position SkeletalVertex\n"
+"#define Attrib_TexCoord1 SkeletalSVector\n"
+"#define Attrib_TexCoord2 SkeletalTVector\n"
+"#define Attrib_TexCoord3 SkeletalNormal\n"
+"#endif\n"
+"\n"
 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n"
 "      VertexColor = Attrib_Color;\n"
 "#endif\n"