aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core-data/Common/ShaderLib/Skinning.glsllib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/core-data/Common/ShaderLib/Skinning.glsllib')
-rw-r--r--engine/src/core-data/Common/ShaderLib/Skinning.glsllib36
1 files changed, 36 insertions, 0 deletions
diff --git a/engine/src/core-data/Common/ShaderLib/Skinning.glsllib b/engine/src/core-data/Common/ShaderLib/Skinning.glsllib
new file mode 100644
index 0000000..f0641b6
--- /dev/null
+++ b/engine/src/core-data/Common/ShaderLib/Skinning.glsllib
@@ -0,0 +1,36 @@
+#ifdef USE_HWSKINNING
+
+#ifndef NUM_BONES
+#error A required pre-processor define "NUM_BONES" is not set!
+#endif
+
+attribute vec4 inBoneWeight;
+attribute vec4 inBoneIndices;
+uniform mat4 m_BoneMatrices[NUM_BONES];
+
+void Skinning_Compute(inout vec4 position, inout vec4 normal){
+ vec4 index = inBoneIndices;
+ vec4 weight = inBoneWeight;
+
+ vec4 newPos = vec4(0.0);
+ vec4 newNormal = vec4(0.0);
+
+ for (float i = 0.0; i < 4.0; i += 1.0){
+ mat4 skinMat = m_BoneMatrices[int(index.x)];
+ newPos += weight.x * (skinMat * position);
+ newNormal += weight.x * (skinMat * normal);
+ index = index.yzwx;
+ weight = weight.yzwx;
+ }
+
+ position = newPos;
+ normal = newNormal;
+}
+
+#else
+
+void Skinning_Compute(inout vec4 position, inout vec4 normal){
+ // skinning disabled, leave position and normal unaltered
+}
+
+#endif \ No newline at end of file