From 45ab4423964bd844eaf076a15e8a466661190743 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 7 Mar 2021 19:57:13 +0200 Subject: [PATCH] normals react to skeletal animation --- keyframeChannel.h | 4 +++- light.cpp | 34 +++++++++++++++++++++++----------- light.h | 11 +++++++---- texture.vert | 29 ++++++++++++++++++++++++----- 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/keyframeChannel.h b/keyframeChannel.h index 1909287..1634952 100644 --- a/keyframeChannel.h +++ b/keyframeChannel.h @@ -21,7 +21,9 @@ namespace vb01{ SCALE_Z, SHAPE_KEY_MIN, SHAPE_KEY_VALUE, - SHAPE_KEY_MAX + SHAPE_KEY_MAX, + SPOTLIGHT_INNER_ANGLE, + SPOTLIGHT_OUTER_ANGLE }; struct Keyframe{ enum Interpolation{CONSTANT, LINEAR, BEZIER}; diff --git a/light.cpp b/light.cpp index 435a06f..b0b0451 100755 --- a/light.cpp +++ b/light.cpp @@ -1,14 +1,15 @@ -#include"model.h" -#include"light.h" -#include"node.h" -#include"root.h" -#include"shader.h" -#include"material.h" -#include"mesh.h" -#include -#include -#include -#include +#include "model.h" +#include "light.h" +#include "node.h" +#include "root.h" +#include "shader.h" +#include "material.h" +#include "mesh.h" + +#include +#include +#include +#include using namespace glm; using namespace std; @@ -29,6 +30,17 @@ namespace vb01{ delete depthMapShader; } + void Light::animate(float value, KeyframeChannel keyframeChannel){ + switch(keyframeChannel.type){ + case KeyframeChannel::SPOTLIGHT_INNER_ANGLE: + innerAngle = value; + break; + case KeyframeChannel::SPOTLIGHT_OUTER_ANGLE: + outerAngle = value; + break; + } + } + void Light::initDepthMap(){ string basePath = "../../vb01/depthMap."; diff --git a/light.h b/light.h index 6407f31..d3c44b7 100755 --- a/light.h +++ b/light.h @@ -1,9 +1,11 @@ #ifndef LIGHT_H #define LIGHT_H -#include"vector.h" -#include -#include +#include "vector.h" +#include "animatable.h" + +#include +#include namespace vb01{ class Node; @@ -12,7 +14,7 @@ namespace vb01{ class Material; - class Light{ + class Light : public Animatable{ public: enum Type{POINT, DIRECTIONAL, SPOT, AMBIENT}; @@ -40,6 +42,7 @@ namespace vb01{ inline float getShadowFarPlane(){return farPlane;} inline Node* getNode(){return node;} private: + void animate(float, KeyframeChannel); void initDepthMap(); void renderShadow(std::vector, glm::mat4&, glm::mat4&); void updateShader(std::vector, int, glm::mat4&, glm::mat4&); diff --git a/texture.vert b/texture.vert index 2bfcc49..b272397 100755 --- a/texture.vert +++ b/texture.vert @@ -81,6 +81,12 @@ float getWeight(Bone bone){ void main(){ vec4 vertPos = vec4(aPos, 1); bool anyWeights = false; + + mat3 normalMat = mat3(transpose(inverse(model))); + norm = (normalMat * aNorm); + tan = (normalMat * aTan); + biTan = (normalMat * aBiTan); + for(int i = 0; i < numMaxInfluences; i++) if(aWeight[i] > 0) anyWeights = true; @@ -104,21 +110,34 @@ void main(){ poseTransform[i] = poseTransform[bones[i].parent] * localTransform; } - vec3 v0 = vec3(0); + vec3 v0 = vec3(0), n0 = vec3(0), t0 = vec3(0), b0 = vec3(0); for(int i = 0; i < numBones; i++){ float weight = getWeight(bones[i]); - vec4 boneLocalVert = inverse(transform[i]) * vertPos; + mat4 inverseTransform = inverse(transform[i]); + vec4 boneLocalVert = inverseTransform * vertPos; + vec4 boneLocalNorm = inverseTransform * vec4(aNorm, 0); + vec4 boneLocalTan = inverseTransform * vec4(aTan, 0); + vec4 boneLocalBiTan = inverseTransform * vec4(aBiTan, 0); + v0 += (weight * poseTransform[i] * boneLocalVert).xyz; + mat4 normalPoseTrans = transpose(inverse(poseTransform[i])); + n0 += (weight * normalPoseTrans * boneLocalNorm).xyz; + t0 += (weight * normalPoseTrans * boneLocalTan).xyz; + b0 += (weight * normalPoseTrans * boneLocalBiTan).xyz; } vertPos.xyz = v0; + norm = n0; + tan = t0; + biTan = b0; } + norm = normalize(normalMat * norm); + tan = normalize(normalMat * tan); + biTan = normalize(normalMat * biTan); + gl_Position = proj * view * model * vertPos; fragPos = vec3(model * vertPos); - norm = mat3(transpose(inverse(model))) * aNorm; - tan = mat3(transpose(inverse(model))) * aTan; - biTan = mat3(transpose(inverse(model))) * aBiTan; texCoords = aTexCoords; }