Skinning for animated shadows.

This commit is contained in:
Lubos Lenco 2016-04-07 00:06:57 +02:00
parent 052b2d26cd
commit c769095a1d
5 changed files with 107 additions and 74 deletions

View file

@ -62,6 +62,7 @@ void main() {
discard;
#endif
vec3 baseColor = texel.rgb;
baseColor = pow(baseColor, vec3(2.2));
#else
vec3 baseColor = matColor.rgb;
#endif

View file

@ -68,44 +68,17 @@
{
"id": "cull_mode",
"value": "counter_clockwise"
},
{
"id": "blend_source",
"value": "blend_one"
},
{
"id": "blend_destination",
"value": "blend_zero"
},
{
"id": "stencil_mode",
"value": "always"
},
{
"id": "stencil_pass",
"value": "keep"
},
{
"id": "stencil_fail",
"value": "keep"
},
{
"id": "stencil_reference_value",
"value": 0
},
{
"id": "stencil_read_mask",
"value": 255
},
{
"id": "stencil_write_mask",
"value": 255
}
],
"links": [
{
"id": "LMVP",
"link": "_lightModelViewProjectionMatrix"
},
{
"id": "skinBones",
"link": "_skinBones",
"ifdef": "_Skinning"
}
],
"vertex_shader": "shadowmap.vert.glsl",

View file

@ -29,14 +29,57 @@ in vec3 off;
#endif
uniform mat4 LMVP;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
out vec4 position;
void main() {
#ifdef _Instancing
gl_Position = LMVP * vec4(pos + off, 1.0);
#else
gl_Position = LMVP * vec4(pos, 1.0);
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
gl_Position = LMVP * sPos;
position = gl_Position;
}

View file

@ -68,44 +68,17 @@
{
"id": "cull_mode",
"value": "counter_clockwise"
},
{
"id": "blend_source",
"value": "blend_one"
},
{
"id": "blend_destination",
"value": "blend_zero"
},
{
"id": "stencil_mode",
"value": "always"
},
{
"id": "stencil_pass",
"value": "keep"
},
{
"id": "stencil_fail",
"value": "keep"
},
{
"id": "stencil_reference_value",
"value": 0
},
{
"id": "stencil_read_mask",
"value": 255
},
{
"id": "stencil_write_mask",
"value": 255
}
],
"links": [
{
"id": "LMVP",
"link": "_lightModelViewProjectionMatrix"
},
{
"id": "skinBones",
"link": "_skinBones",
"ifdef": "_Skinning"
}
],
"vertex_shader": "shadowmap.vert.glsl",

View file

@ -29,14 +29,57 @@ in vec3 off;
#endif
uniform mat4 LMVP;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
out vec4 position;
void main() {
#ifdef _Instancing
gl_Position = LMVP * vec4(pos + off, 1.0);
#else
gl_Position = LMVP * vec4(pos, 1.0);
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
gl_Position = LMVP * sPos;
position = gl_Position;
}