2018-10-03 05:52:35 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <map>
|
2018-04-02 06:05:06 +00:00
|
|
|
#include "modelshaderprogram.h"
|
|
|
|
|
2018-10-03 05:52:35 +00:00
|
|
|
const QString &ModelShaderProgram::loadShaderSource(const QString &name)
|
|
|
|
{
|
|
|
|
static std::map<QString, QString> s_shaderSources;
|
|
|
|
auto findShader = s_shaderSources.find(name);
|
|
|
|
if (findShader != s_shaderSources.end()) {
|
|
|
|
return findShader->second;
|
|
|
|
}
|
|
|
|
QFile file(name);
|
|
|
|
file.open(QFile::ReadOnly | QFile::Text);
|
|
|
|
QTextStream stream(&file);
|
|
|
|
auto insertResult = s_shaderSources.insert({name, stream.readAll()});
|
|
|
|
return insertResult.first->second;
|
|
|
|
}
|
2018-04-02 06:05:06 +00:00
|
|
|
|
2020-03-18 14:17:09 +00:00
|
|
|
bool ModelShaderProgram::isCoreProfile()
|
|
|
|
{
|
|
|
|
return m_isCoreProfile;
|
|
|
|
}
|
|
|
|
|
2020-03-20 07:41:48 +00:00
|
|
|
ModelShaderProgram::ModelShaderProgram(bool isCoreProfile)
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
2020-03-20 07:41:48 +00:00
|
|
|
if (isCoreProfile) {
|
2018-10-03 05:52:35 +00:00
|
|
|
this->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShaderSource(":/shaders/default.core.vert"));
|
|
|
|
this->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShaderSource(":/shaders/default.core.frag"));
|
2020-03-18 14:17:09 +00:00
|
|
|
m_isCoreProfile = true;
|
2018-10-03 05:52:35 +00:00
|
|
|
} else {
|
2018-10-05 07:37:01 +00:00
|
|
|
this->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShaderSource(":/shaders/default.vert"));
|
2019-12-22 12:07:42 +00:00
|
|
|
this->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShaderSource(":/shaders/default.frag"));
|
2018-10-03 05:52:35 +00:00
|
|
|
}
|
2018-04-02 06:05:06 +00:00
|
|
|
this->bindAttributeLocation("vertex", 0);
|
|
|
|
this->bindAttributeLocation("normal", 1);
|
|
|
|
this->bindAttributeLocation("color", 2);
|
2018-05-10 09:16:22 +00:00
|
|
|
this->bindAttributeLocation("texCoord", 3);
|
2018-10-04 12:51:01 +00:00
|
|
|
this->bindAttributeLocation("metalness", 4);
|
|
|
|
this->bindAttributeLocation("roughness", 5);
|
2018-10-09 02:19:12 +00:00
|
|
|
this->bindAttributeLocation("tangent", 6);
|
2019-11-02 02:43:23 +00:00
|
|
|
this->bindAttributeLocation("alpha", 7);
|
2018-04-02 06:05:06 +00:00
|
|
|
this->link();
|
|
|
|
|
|
|
|
this->bind();
|
2018-10-05 07:37:01 +00:00
|
|
|
m_projectionMatrixLoc = this->uniformLocation("projectionMatrix");
|
|
|
|
m_modelMatrixLoc = this->uniformLocation("modelMatrix");
|
2018-10-09 02:19:12 +00:00
|
|
|
m_normalMatrixLoc = this->uniformLocation("normalMatrix");
|
2018-10-05 07:37:01 +00:00
|
|
|
m_viewMatrixLoc = this->uniformLocation("viewMatrix");
|
2018-04-02 06:05:06 +00:00
|
|
|
m_lightPosLoc = this->uniformLocation("lightPos");
|
2018-05-10 09:16:22 +00:00
|
|
|
m_textureIdLoc = this->uniformLocation("textureId");
|
|
|
|
m_textureEnabledLoc = this->uniformLocation("textureEnabled");
|
2018-10-09 02:19:12 +00:00
|
|
|
m_normalMapIdLoc = this->uniformLocation("normalMapId");
|
|
|
|
m_normalMapEnabledLoc = this->uniformLocation("normalMapEnabled");
|
|
|
|
m_metalnessMapEnabledLoc = this->uniformLocation("metalnessMapEnabled");
|
|
|
|
m_roughnessMapEnabledLoc = this->uniformLocation("roughnessMapEnabled");
|
|
|
|
m_ambientOcclusionMapEnabledLoc = this->uniformLocation("ambientOcclusionMapEnabled");
|
|
|
|
m_metalnessRoughnessAmbientOcclusionMapIdLoc = this->uniformLocation("metalnessRoughnessAmbientOcclusionMapId");
|
2019-08-08 11:24:33 +00:00
|
|
|
m_mousePickEnabledLoc = this->uniformLocation("mousePickEnabled");
|
|
|
|
m_mousePickTargetPositionLoc = this->uniformLocation("mousePickTargetPosition");
|
2019-08-17 10:13:11 +00:00
|
|
|
m_mousePickRadiusLoc = this->uniformLocation("mousePickRadius");
|
2020-04-02 10:39:57 +00:00
|
|
|
m_toonShadingEnabledLoc = this->uniformLocation("toonShadingEnabled");
|
|
|
|
m_renderPurposeLoc = this->uniformLocation("renderPurpose");
|
|
|
|
m_toonEdgeEnabledLoc = this->uniformLocation("toonEdgeEnabled");
|
|
|
|
m_screenWidthLoc = this->uniformLocation("screenWidth");
|
|
|
|
m_screenHeightLoc = this->uniformLocation("screenHeight");
|
|
|
|
m_toonNormalMapIdLoc = this->uniformLocation("toonNormalMapId");
|
|
|
|
m_toonDepthMapIdLoc = this->uniformLocation("toonDepthMapId");
|
2020-03-18 14:17:09 +00:00
|
|
|
if (m_isCoreProfile) {
|
|
|
|
m_environmentIrradianceMapIdLoc = this->uniformLocation("environmentIrradianceMapId");
|
|
|
|
m_environmentIrradianceMapEnabledLoc = this->uniformLocation("environmentIrradianceMapEnabled");
|
|
|
|
m_environmentSpecularMapIdLoc = this->uniformLocation("environmentSpecularMapId");
|
|
|
|
m_environmentSpecularMapEnabledLoc = this->uniformLocation("environmentSpecularMapEnabled");
|
|
|
|
}
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 07:37:01 +00:00
|
|
|
int ModelShaderProgram::projectionMatrixLoc()
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
2018-10-05 07:37:01 +00:00
|
|
|
return m_projectionMatrixLoc;
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 07:37:01 +00:00
|
|
|
int ModelShaderProgram::modelMatrixLoc()
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
2018-10-05 07:37:01 +00:00
|
|
|
return m_modelMatrixLoc;
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 02:19:12 +00:00
|
|
|
int ModelShaderProgram::normalMatrixLoc()
|
|
|
|
{
|
|
|
|
return m_normalMatrixLoc;
|
|
|
|
}
|
|
|
|
|
2018-10-05 07:37:01 +00:00
|
|
|
int ModelShaderProgram::viewMatrixLoc()
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
2018-10-05 07:37:01 +00:00
|
|
|
return m_viewMatrixLoc;
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::lightPosLoc()
|
|
|
|
{
|
|
|
|
return m_lightPosLoc;
|
|
|
|
}
|
2018-05-10 09:16:22 +00:00
|
|
|
|
|
|
|
int ModelShaderProgram::textureEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_textureEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::textureIdLoc()
|
|
|
|
{
|
|
|
|
return m_textureIdLoc;
|
|
|
|
}
|
2018-10-09 02:19:12 +00:00
|
|
|
|
|
|
|
int ModelShaderProgram::normalMapEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_normalMapEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::normalMapIdLoc()
|
|
|
|
{
|
|
|
|
return m_normalMapIdLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::metalnessMapEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_metalnessMapEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::roughnessMapEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_roughnessMapEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::ambientOcclusionMapEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_ambientOcclusionMapEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::metalnessRoughnessAmbientOcclusionMapIdLoc()
|
|
|
|
{
|
|
|
|
return m_metalnessRoughnessAmbientOcclusionMapIdLoc;
|
|
|
|
}
|
|
|
|
|
2019-08-08 11:24:33 +00:00
|
|
|
int ModelShaderProgram::mousePickEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_mousePickEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::mousePickTargetPositionLoc()
|
|
|
|
{
|
|
|
|
return m_mousePickTargetPositionLoc;
|
|
|
|
}
|
2019-08-17 10:13:11 +00:00
|
|
|
|
|
|
|
int ModelShaderProgram::mousePickRadiusLoc()
|
|
|
|
{
|
|
|
|
return m_mousePickRadiusLoc;
|
|
|
|
}
|
2020-03-18 14:17:09 +00:00
|
|
|
|
|
|
|
int ModelShaderProgram::environmentIrradianceMapIdLoc()
|
|
|
|
{
|
|
|
|
return m_environmentIrradianceMapIdLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::environmentIrradianceMapEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_environmentIrradianceMapEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::environmentSpecularMapIdLoc()
|
|
|
|
{
|
|
|
|
return m_environmentSpecularMapIdLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::environmentSpecularMapEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_environmentSpecularMapEnabledLoc;
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:39:57 +00:00
|
|
|
int ModelShaderProgram::toonShadingEnabledLoc()
|
2020-03-29 10:06:45 +00:00
|
|
|
{
|
2020-04-02 10:39:57 +00:00
|
|
|
return m_toonShadingEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::renderPurposeLoc()
|
|
|
|
{
|
|
|
|
return m_renderPurposeLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::toonEdgeEnabledLoc()
|
|
|
|
{
|
|
|
|
return m_toonEdgeEnabledLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::screenWidthLoc()
|
|
|
|
{
|
|
|
|
return m_screenWidthLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::screenHeightLoc()
|
|
|
|
{
|
|
|
|
return m_screenHeightLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::toonNormalMapIdLoc()
|
|
|
|
{
|
|
|
|
return m_toonNormalMapIdLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModelShaderProgram::toonDepthMapIdLoc()
|
|
|
|
{
|
|
|
|
return m_toonDepthMapIdLoc;
|
|
|
|
}
|