normals react to skeletal animation

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 882cd65e51
commit 45ab442396
4 changed files with 57 additions and 21 deletions
+3 -1
View File
@@ -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};
+23 -11
View File
@@ -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<glad.h>
#include<glfw3.h>
#include<ext.hpp>
#include<iostream>
#include "model.h"
#include "light.h"
#include "node.h"
#include "root.h"
#include "shader.h"
#include "material.h"
#include "mesh.h"
#include <glad.h>
#include <glfw3.h>
#include <ext.hpp>
#include <iostream>
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.";
+7 -4
View File
@@ -1,9 +1,11 @@
#ifndef LIGHT_H
#define LIGHT_H
#include"vector.h"
#include<vector>
#include<glm.hpp>
#include "vector.h"
#include "animatable.h"
#include <vector>
#include <glm.hpp>
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<Node*>, glm::mat4&, glm::mat4&);
void updateShader(std::vector<Material*>, int, glm::mat4&, glm::mat4&);
+24 -5
View File
@@ -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;
}