Browse Source

Finish legacy shader mapping

master
Skia 3 years ago
parent
commit
c049baf310
8 changed files with 43 additions and 23 deletions
  1. +1
    -3
      main.cpp
  2. +10
    -5
      mesh.cpp
  3. +13
    -3
      mesh.h
  4. +5
    -5
      scene.cpp
  5. +1
    -0
      scene.h
  6. +6
    -6
      shader_legacy.vs
  7. +5
    -0
      utils.h
  8. +2
    -1
      vertice.h

+ 1
- 3
main.cpp View File

@@ -7,13 +7,11 @@
#include <fstream>
#include <string>
#include <list>
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/gl.h>


#include <scene.h>
#include <camera.h>
#include <utils.h>

SceneHandler *scene;


+ 10
- 5
mesh.cpp View File

@@ -44,6 +44,7 @@ void Mesh::render(bool anim) {
} else {
glDisable(GL_LIGHTING);
}
// glUniformMatrix4fv(shader_bones, this->getNbBone(), GL_TRUE, boneStateList);

for (i = 0; i < this->getFaceNumber(); i++) {
Face *f = this->getFace(i);
@@ -53,19 +54,23 @@ void Mesh::render(bool anim) {
int index = f->getIndex(j);
if (anim) {
Vertice *v = this->getVertex(index);
aiMatrix4x4 t;
aiMatrix4x4 t[4];
glVertexAttribPointer(shader_Normal, 3, GL_FLOAT, GL_FALSE, 0, &this->getNormal(index)->x);
glVertexAttribPointer(shader_Weights, 3, GL_FLOAT, GL_FALSE, 0, v->getBonesWeights());
for (int k = 0; k < v->getBoneNumber(); k++) {
t = t + v->getBonesWeight(k) * boneStateList[this->getBoneIndex(v->getBonesID(k))];
t[k] = boneStateList[this->getBoneIndex(v->getBonesID(k))].Transpose();
}
glVertexAttribPointer(shader_Weights, 3, GL_FLOAT, GL_FALSE, 0, &t);
// std::cout << t << "\n";
glMultMatrixf(&t.a1);
// glMultMatrixf(&t.a1);
// FIXME: we need to send the data to the shader!!!!
}
// glPopMatrix();
if (this->getNormal(index) != NULL) {
glNormal3fv(&this->getNormal(index)->x);
glVertexAttribPointer(shader_Normal, 3, GL_FLOAT, GL_FALSE, 0, &this->getNormal(index)->x);
}
glVertex3fv(&(this->getVertex(index)->getPosition()).x);
//glVertex3fv();
glVertexAttribPointer(shader_Position, 3, GL_FLOAT, GL_FALSE, 0, &(this->getVertex(index)->getPosition()).x);
}
glEnd();
}

+ 13
- 3
mesh.h View File

@@ -3,8 +3,6 @@

#include <iostream>

#include <GL/gl.h>

#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
@@ -59,9 +57,16 @@ class Mesh
int vertNb, boneNb, faceNb, animNb, maxFaceNb;
int mesh_id;
int currentAnimation;
GLint shader_bones;
GLint shader_Position;
GLint shader_Normal;
GLint shader_BoneTransform;
GLint shader_Weights;
GLuint shaderProg;

public:
Mesh(int id, int vertSize, int boneSize, int faceSize){
Mesh(int id, int vertSize, int boneSize, int faceSize, GLuint prog){
shaderProg = prog;
vertNb = vertSize;
boneNb = boneSize;
faceNb = 0;
@@ -74,6 +79,11 @@ class Mesh
boneStateList = (aiMatrix4x4*) malloc(boneNb * sizeof(aiMatrix4x4));
faceList = (Face**)malloc(faceSize * sizeof(Face*));
currentAnimation = 0;
shader_bones = glGetUniformLocation(shaderProg, "gBones");
shader_Position = glGetAttribLocation(shaderProg, "Position");
shader_Normal = glGetAttribLocation(shaderProg, "Normal");
shader_BoneTransform = glGetAttribLocation(shaderProg, "BoneTransform");
shader_Weights = glGetAttribLocation(shaderProg, "Weights");
};

void setCurrentAnim(int n) {

+ 5
- 5
scene.cpp View File

@@ -6,15 +6,14 @@
#include <iostream>
#include <time.h>

#include <GL/glew.h>
#include <GL/gl.h>


#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>

#include <scene.h>
#include <utils.h>

using namespace std;

const aiNode *getNode(const aiScene *scene, aiString name) {
@@ -48,6 +47,8 @@ SceneHandler::SceneHandler(char *fName, GLuint prog) {
if (!scene) {
std::cerr << "Error importing file" << std::endl;
} else {
shaderProg = prog;

get_bounding_box();
scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
@@ -68,7 +69,6 @@ SceneHandler::SceneHandler(char *fName, GLuint prog) {
// Shader variable
m_WVPLocation = glGetUniformLocation(prog, "gWVP");
m_WorldMatrixLocation = glGetUniformLocation(prog, "gWorld");

}
}

@@ -78,7 +78,7 @@ void SceneHandler::initMeshList(const aiNode* nd){
meshList = (Mesh**) realloc(meshList, (nd->mNumMeshes + meshNumber) * sizeof(Mesh*));
for (i = 0; i < nd->mNumMeshes; ++i) {
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[i]];
Mesh *newMesh = new Mesh(i, mesh->mNumVertices, mesh->mNumBones, mesh->mNumFaces);
Mesh *newMesh = new Mesh(i, mesh->mNumVertices, mesh->mNumBones, mesh->mNumFaces, shaderProg);
for(j = 0; j < mesh->mNumVertices; j++){
Vertice *newVert = new Vertice(j, mesh->mVertices[j]);
if (mesh->mNormals != NULL) {

+ 1
- 0
scene.h View File

@@ -33,6 +33,7 @@ class SceneHandler
clock_t m_startTime;
GLuint m_WVPLocation;
GLuint m_WorldMatrixLocation;
GLuint shaderProg;

public:
SceneHandler(char *fName, GLuint prog);

+ 6
- 6
shader_legacy.vs View File

@@ -4,8 +4,8 @@

attribute vec3 Position;
attribute vec3 Normal;
attribute ivec4 BoneIDs;
attribute vec4 Weights;
attribute mat4 BoneTransform[4];
attribute float Weights[4];

varying vec2 TexCoord0;
varying vec3 Normal0;
@@ -19,10 +19,10 @@ uniform mat4 gBones[MAX_BONES];

void main()
{
mat4 BoneTransform = gBones[BoneIDs[0]] * Weights[0];
BoneTransform += gBones[BoneIDs[1]] * Weights[1];
BoneTransform += gBones[BoneIDs[2]] * Weights[2];
BoneTransform += gBones[BoneIDs[3]] * Weights[3];
mat4 BoneTransform = BoneTransform[0] * Weights[0];
BoneTransform += BoneTransform[1] * Weights[1];
BoneTransform += BoneTransform[2] * Weights[2];
BoneTransform += BoneTransform[3] * Weights[3];

vec4 PosL = BoneTransform * vec4(Position, 1.0);
gl_Position = gWVP * PosL;

+ 5
- 0
utils.h View File

@@ -3,10 +3,15 @@

#include <iostream>

#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/gl.h>

#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>


const aiNodeAnim *findNodeAnim(const aiAnimation *anim, aiString name);

aiVector3D operator*( float num, aiVector3D v );

+ 2
- 1
vertice.h View File

@@ -3,13 +3,13 @@

#include <iostream>

#include <GL/gl.h>

#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>

#include <vectors.h>
#include <utils.h>

#define MAX_BONES 4

@@ -55,6 +55,7 @@ class Vertice {
int getBoneNumber() { return numBone; };

float getBonesWeight(int i){return bonesWeight[i]; };
float *getBonesWeights(){ return bonesWeight; };




Loading…
Cancel
Save