Skip to content

Commit

Permalink
Got morph targets working with obj sequences, started to create a GUI…
Browse files Browse the repository at this point in the history
… for modification of uniforms at run-time. Trying to make eye normals look nicer.
  • Loading branch information
nitronoid committed May 8, 2018
1 parent 84d97e8 commit 98884bd
Show file tree
Hide file tree
Showing 228 changed files with 4,112,012 additions and 63,334 deletions.
9 changes: 5 additions & 4 deletions Criminowl.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ HEADERS += \
include/CameraStates.h \
include/Material.h \
include/MaterialPBR.h \
include/Mesh.h \
include/Scene.h \
include/DemoScene.h \
include/MaterialPhong.h \
Expand All @@ -45,15 +44,16 @@ HEADERS += \
include/MaterialWireframe.h \
include/MaterialFractal.h \
include/MaterialEnvMap.h \
include/MaterialBump.h
include/MaterialBump.h \
include/TriMesh.h \
include/Edge.h

SOURCES += \
src/main.cpp \
src/MainWindow.cpp \
src/Camera.cpp \
src/TrackballCamera.cpp \
src/CameraStates.cpp \
src/Mesh.cpp \
src/Material.cpp \
src/MaterialPBR.cpp \
src/Scene.cpp \
Expand All @@ -64,7 +64,8 @@ SOURCES += \
src/MaterialWireframe.cpp \
src/MaterialFractal.cpp \
src/MaterialEnvMap.cpp \
src/MaterialBump.cpp
src/MaterialBump.cpp \
src/TriMesh.cpp

OTHER_FILES += \
$$files(shaders/*, true) \
Expand Down
30 changes: 25 additions & 5 deletions include/DemoScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,30 @@ class DemoScene : public Scene

public slots:
//-----------------------------------------------------------------------------------------------------
/// @brief Used to link a Qt button to the scene, to allow rotation of the model to be toggled.
/// @param [in] _rotating tells the scene whether it should rotate the model or not.
/// @brief Used to link a Qt button to the scene, to change the metallic value of the shader.
/// @param [in] _metallic is the new value for the shader.
//-----------------------------------------------------------------------------------------------------
void rotating(const bool _rotating);
void metallicUpdate(const double _metallic);
//-----------------------------------------------------------------------------------------------------
/// @brief Used to link a Qt button to the scene, to change the roughness value of the shader.
/// @param [in] _roughness is the new value for the shader.
//-----------------------------------------------------------------------------------------------------
void roughnessUpdate(const double _roughness);
//-----------------------------------------------------------------------------------------------------
/// @brief Used to link a Qt button to the scene, to change the base specular value of the shader.
/// @param [in] _baseSpec is the new value for the shader.
//-----------------------------------------------------------------------------------------------------
void baseSpecUpdate(const double _baseSpec);
//-----------------------------------------------------------------------------------------------------
/// @brief Used to link a Qt button to the scene, to change the normal strength value of the shader.
/// @param [in] _normalStrength is the new value for the shader.
//-----------------------------------------------------------------------------------------------------
void normalStrengthUpdate(const double _normalStrength);
//-----------------------------------------------------------------------------------------------------
/// @brief Used to link a Qt button to the scene, to pause and unpause the morph targets.
/// @param [in] _paused is the new value for the shader.
//-----------------------------------------------------------------------------------------------------
void setPaused(const bool _paused);
//-----------------------------------------------------------------------------------------------------
/// @brief Used to link a Qt button to the scene, to allow switching between meshes in the scene, this
/// calls loadMesh.
Expand All @@ -94,7 +114,7 @@ public slots:
//-----------------------------------------------------------------------------------------------------
/// @brief Holds our test meshes.
//-----------------------------------------------------------------------------------------------------
Mesh m_owlMesh;
TriMesh m_owlMesh;
//-----------------------------------------------------------------------------------------------------
/// @brief Wraps up our OpenGL buffers and VAO.
//-----------------------------------------------------------------------------------------------------
Expand All @@ -113,7 +133,7 @@ public slots:
//-----------------------------------------------------------------------------------------------------
/// @brief The materials used in this scene.
//-----------------------------------------------------------------------------------------------------
std::unique_ptr<Material> m_material;
std::unique_ptr<MaterialPBR> m_material;
//-----------------------------------------------------------------------------------------------------
/// @brief Is the mesh rotating.
//-----------------------------------------------------------------------------------------------------
Expand Down
69 changes: 69 additions & 0 deletions include/Edge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef EDGE_H
#define EDGE_H

#include <QOpenGLFunctions>

struct Edge
{
//-----------------------------------------------------------------------------------------------------
/// @brief Default constructor.
//-----------------------------------------------------------------------------------------------------
Edge() = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default copy constructor.
//-----------------------------------------------------------------------------------------------------
Edge(const Edge&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default copy assignment operator.
//-----------------------------------------------------------------------------------------------------
Edge& operator=(const Edge&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default move constructor.
//-----------------------------------------------------------------------------------------------------
Edge(Edge&&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default move assignment operator.
//-----------------------------------------------------------------------------------------------------
Edge& operator=(Edge&&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default destructor.
//-----------------------------------------------------------------------------------------------------
~Edge() = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Constructor that takes two vertex indices.
/// @param _a is a vertex index representing one of the vertices that contributes to this edge.
/// @param _b is a vertex index representing one of the vertices that contributes to this edge.
//-----------------------------------------------------------------------------------------------------
Edge(const GLushort _a, const GLushort _b) :
p(std::min(_a, _b), std::max(_a, _b))
{}
//-----------------------------------------------------------------------------------------------------
/// @brief Used for hashing.
//-----------------------------------------------------------------------------------------------------
friend bool operator==(const Edge &_a, const Edge &_b)
{
return _a.p == _b.p;
}
//-----------------------------------------------------------------------------------------------------
/// @brief Internally stores a pair, which is sorted on construction.
//-----------------------------------------------------------------------------------------------------
std::pair<GLushort, GLushort> p;
};


//-----------------------------------------------------------------------------------------------------
/// @brief Define the hash struct for this Edge so we can create unordered_set's using it.
//-----------------------------------------------------------------------------------------------------
namespace std
{
template <>
struct hash<Edge>
{
size_t operator()(const Edge &_key) const
{
return std::hash<size_t>()(std::hash<GLushort>()(_key.p.first)) ^ std::hash<GLushort>()(_key.p.second);
}
};
}

#endif // EDGE_H
53 changes: 39 additions & 14 deletions include/MaterialPBR.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Material.h"
#include "vec3.hpp"
#include <QOpenGLTexture>
#include "Mesh.h"
#include "TriMesh.h"
#include "MeshVBO.h"

class MaterialPBR : public Material
Expand All @@ -15,17 +15,19 @@ class MaterialPBR : public Material
const std::shared_ptr<ShaderLib> &io_shaderLib,
std::array<glm::mat4, 3>* io_matrices,
QOpenGLContext* io_context,
const glm::vec3 &_albedo,
const float _ao,
const float _roughness,
const float _metallic
const float _metallic,
const float _baseSpec,
const float _normalStrength
) :
Material(io_camera, io_shaderLib, io_matrices),
m_albedo(_albedo),
m_context(io_context),
m_ao(_ao),
m_roughness(_roughness),
m_metallic(_metallic)
m_metallic(_metallic),
m_baseSpec(_baseSpec),
m_normalStrength(_normalStrength)
{}
MaterialPBR(const MaterialPBR&) = default;
MaterialPBR& operator=(const MaterialPBR&) = default;
Expand All @@ -39,26 +41,41 @@ class MaterialPBR : public Material

virtual const char* shaderFileName() const override;

void setMetallic(const float _metallic) noexcept;
float getMetallic() const noexcept;

void setRoughness(const float _roughness) noexcept;
float getRoughness() const noexcept;

void setBaseSpec(const float _baseSpec) noexcept;
float getBaseSpec() const noexcept;

void setNormalStrength(const float _normalStrength) noexcept;
float getNormalStrength() const noexcept;

void setPaused(const bool _paused) noexcept;
bool getPaused() const noexcept;

private:
void initTargets();
void initCaptureMatrices();
void initSphereMap();
void initCubeMap(const Mesh &_cube, const MeshVBO &_vbo);
void initIrradianceMap(const Mesh &_cube, const MeshVBO &_vbo);
void initPrefilteredMap(const Mesh &_cube, const MeshVBO &_vbo);
void initBrdfLUTMap(const Mesh &_plane, const MeshVBO &_vbo);
void initCubeMap(const TriMesh &_cube, const MeshVBO &_vbo);
void initIrradianceMap(const TriMesh &_cube, const MeshVBO &_vbo);
void initPrefilteredMap(const TriMesh &_cube, const MeshVBO &_vbo);
void initBrdfLUTMap(const TriMesh &_plane, const MeshVBO &_vbo);

void generateCubeMap(const Mesh &_cube,
void generateCubeMap(const TriMesh &_cube,
const MeshVBO &_vbo,
std::unique_ptr<QOpenGLTexture> &_texture,
const int _dim,
const std::string &_matPath,
const std::function<void (QOpenGLShaderProgram* io_prog)> &_prerender = [](QOpenGLShaderProgram*){}
);

void generate3DTexture(
const Mesh &_plane,
void generate3DTexture(const TriMesh &_plane,
const MeshVBO &_vbo,
std::unique_ptr<QOpenGLTexture> &_texture,
std::unique_ptr<QOpenGLTexture> &_texture, const int _dim,
const std::string &_matPath,
const std::function<void (QOpenGLShaderProgram* io_prog)> &_prerender = [](QOpenGLShaderProgram*){}
);
Expand All @@ -74,11 +91,19 @@ class MaterialPBR : public Material
std::unique_ptr<QOpenGLTexture> m_albedoMap;
std::unique_ptr<QOpenGLTexture> m_normalMap;

glm::vec3 m_albedo;
QOpenGLContext* m_context;
float m_ao;
float m_roughness;
float m_metallic;
float m_baseSpec;
float m_normalStrength;

QOpenGLBuffer m_morphTargetBuffer;

GLuint m_morphTargetSSBO = 0;
std::chrono::high_resolution_clock::time_point m_last;
float m_time = 0.0f;
bool m_paused = true;

};

Expand Down
100 changes: 0 additions & 100 deletions include/Mesh.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/Scene.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SCENE_H_
#define SCENE_H_

#include "Mesh.h"
#include "TriMesh.h"
#include <gtc/matrix_transform.hpp>
#include <ext.hpp>
#include <glm.hpp>
Expand Down
Loading

0 comments on commit 98884bd

Please sign in to comment.