Splatmapping now working.
Rendering pipleline now support 3 different types of Material: Basic: a material with a single color on every property (diffuse, specular, ect). SingleTextures: a material with a single texture in all or any property. Have a single color on the rest. SplatMapping: has a SplatMap and 0 to 5 different textures to every property. Properties with o texture uses a single color insted. All materials with a texture has a UVRepeat, telling how many time to till in U and in V. modelJobs now uses ShadeID, ModelID and TextureID for the Hash insted of only Texture MayaExported exports 3 differnt types of material, the same as the piplen now supports.
This commit is contained in:
@@ -77,8 +77,8 @@ void DrawBloomPass::Draw(GLuint texture)
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
|
||||
//Iterate some times to make it more gaussian.
|
||||
for (int i = 1; i < m_iterations; i++) {
|
||||
@@ -90,8 +90,8 @@ void DrawBloomPass::Draw(GLuint texture)
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
|
||||
//horizontal pass
|
||||
|
||||
@@ -102,8 +102,8 @@ void DrawBloomPass::Draw(GLuint texture)
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
}
|
||||
|
||||
//final vertical gaussian after the iterations are done
|
||||
@@ -115,8 +115,8 @@ void DrawBloomPass::Draw(GLuint texture)
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
|
||||
GLERROR("DrawBloomPass::Draw: END");
|
||||
}
|
||||
|
||||
@@ -38,6 +38,6 @@ void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture, GLf
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
}
|
||||
|
||||
@@ -55,6 +55,15 @@ void DrawFinalPass::InitializeShaderPrograms()
|
||||
m_ExplosionEffectProgram->BindFragDataLocation(1, "bloomColor");
|
||||
m_ExplosionEffectProgram->Link();
|
||||
GLERROR("Creating explosion program");
|
||||
|
||||
m_ForwardPlusSplatMapProgram = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapProgram");
|
||||
m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlus.vert.glsl")));
|
||||
m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMap.frag.glsl")));
|
||||
m_ForwardPlusSplatMapProgram->Compile();
|
||||
m_ForwardPlusSplatMapProgram->BindFragDataLocation(0, "sceneColor");
|
||||
m_ForwardPlusSplatMapProgram->BindFragDataLocation(1, "bloomColor");
|
||||
m_ForwardPlusSplatMapProgram->Link();
|
||||
GLERROR("Creating SplatMap program");
|
||||
}
|
||||
|
||||
void DrawFinalPass::Draw(RenderScene& scene)
|
||||
@@ -114,8 +123,9 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
{
|
||||
GLuint forwardHandle = m_ForwardPlusProgram->GetHandle();
|
||||
GLERROR("forwardHandle");
|
||||
GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle();
|
||||
GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle();
|
||||
GLERROR("explosionHandle");
|
||||
GLuint forwardSplatHandle = m_ForwardPlusSplatMapProgram->GetHandle();
|
||||
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
|
||||
@@ -171,14 +181,32 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
if (modelJob) {
|
||||
//bind forward program
|
||||
m_ForwardPlusProgram->Bind();
|
||||
glUniform2f(glGetUniformLocation(forwardHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
//TODO: JOHAN/TOBIAS: Bind shader based on ModelJob->ShaderID;
|
||||
switch (modelJob->Type) {
|
||||
case RawModel::MaterialType::Basic:
|
||||
case RawModel::MaterialType::SingleTextures:
|
||||
{
|
||||
m_ForwardPlusProgram->Bind();
|
||||
GLERROR("Bind Forward program");
|
||||
//bind uniforms
|
||||
BindModelUniforms(forwardHandle, modelJob, scene);
|
||||
break;
|
||||
}
|
||||
case RawModel::MaterialType::SplatMapping:
|
||||
{
|
||||
m_ForwardPlusSplatMapProgram->Bind();
|
||||
GLERROR("Bind SplatMap program");
|
||||
//bind uniforms
|
||||
BindModelUniforms(forwardSplatHandle, modelJob, scene);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//bind textures
|
||||
BindModelTextures(modelJob);
|
||||
GLERROR("asdasd");
|
||||
|
||||
//bind uniforms
|
||||
BindModelUniforms(forwardHandle, modelJob, scene);
|
||||
|
||||
//bind textures
|
||||
BindModelTextures(modelJob);
|
||||
|
||||
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
||||
|
||||
@@ -230,48 +258,65 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<E
|
||||
|
||||
void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene)
|
||||
{
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
GLERROR("Bind 1 uniform");
|
||||
GLint Location_M = glGetUniformLocation(shaderHandle, "M");
|
||||
glUniformMatrix4fv(Location_M, 1, GL_FALSE, glm::value_ptr(job->Matrix));
|
||||
GLERROR("Bind 2 uniform");
|
||||
GLint Location_V = glGetUniformLocation(shaderHandle, "V");
|
||||
glUniformMatrix4fv(Location_V, 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||
GLERROR("Bind 3 uniform");
|
||||
GLint Location_P = glGetUniformLocation(shaderHandle, "P");
|
||||
glUniformMatrix4fv(Location_P, 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
GLERROR("Bind 4 uniform");
|
||||
|
||||
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
|
||||
GLint Location_ScreenDimensions = glGetUniformLocation(shaderHandle, "ScreenDimensions");
|
||||
glUniform2f(Location_ScreenDimensions, m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
|
||||
GLERROR("Bind 5 uniform");
|
||||
|
||||
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(job->Color));
|
||||
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(job->DiffuseColor));
|
||||
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(job->FillColor));
|
||||
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), job->FillPercentage);
|
||||
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
|
||||
GLint Location_FillPercentage = glGetUniformLocation(shaderHandle, "FillPercentage");
|
||||
glUniform1f(Location_FillPercentage, job->FillPercentage);
|
||||
GLERROR("Bind 6 uniform");
|
||||
GLint Location_DiffuseColor = glGetUniformLocation(shaderHandle, "DiffuseColor");
|
||||
glUniform4fv(Location_DiffuseColor, 1, glm::value_ptr(job->DiffuseColor));
|
||||
GLERROR("Bind 7 uniform");
|
||||
GLint Location_FillColor = glGetUniformLocation(shaderHandle, "FillColor");
|
||||
glUniform4fv(Location_FillColor, 1, glm::value_ptr(job->FillColor));
|
||||
GLERROR("Bind 8 uniform");
|
||||
GLint Location_Color = glGetUniformLocation(shaderHandle, "Color");
|
||||
glUniform4fv(Location_Color, 1, glm::value_ptr(job->Color));
|
||||
GLERROR("Bind 9 uniform");
|
||||
GLint Location_AmbientColor = glGetUniformLocation(shaderHandle, "AmbientColor");
|
||||
glUniform4fv(Location_AmbientColor, 1, glm::value_ptr(scene.AmbientColor));
|
||||
|
||||
GLERROR("END");
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
|
||||
void DrawFinalPass::BindExplosionTextures(std::shared_ptr<ExplosionEffectJob>& job)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
if (job->DiffuseTexture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture->m_Texture);
|
||||
if (job->DiffuseTexture.size() > 0 && job->DiffuseTexture[0] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture[0]->m_Texture); //JOHAN TODO: support multiple diffuse Textures
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
if (job->NormalTexture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->NormalTexture->m_Texture);
|
||||
if (job->NormalTexture.size() > 0 && job->NormalTexture[0] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->NormalTexture[0]->m_Texture); //JOHAN TODO: support multiple diffuse Textures
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
if (job->SpecularTexture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture->m_Texture);
|
||||
if (job->SpecularTexture.size() > 0 && job->SpecularTexture[0] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture[0]->m_Texture); //JOHAN TODO: support multiple diffuse Textures
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
if (job->IncandescenceTexture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture->m_Texture);
|
||||
if (job->IncandescenceTexture.size() > 0 && job->IncandescenceTexture[0] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture[0]->m_Texture); //JOHAN TODO: support multiple diffuse Textures
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
|
||||
}
|
||||
@@ -279,32 +324,95 @@ void DrawFinalPass::BindExplosionTextures(std::shared_ptr<ExplosionEffectJob>& j
|
||||
|
||||
void DrawFinalPass::BindModelTextures(std::shared_ptr<ModelJob>& job)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
if (job->DiffuseTexture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture->m_Texture);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
}
|
||||
switch (job->Type) {
|
||||
case RawModel::MaterialType::SingleTextures:
|
||||
case RawModel::MaterialType::Basic:
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
if (job->DiffuseTexture.size() > 0 && job->DiffuseTexture[0] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture[0]->m_Texture);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
if (job->NormalTexture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->NormalTexture->m_Texture);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
if (job->NormalTexture.size() > 0 && job->NormalTexture[0] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->NormalTexture[0]->m_Texture);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
if (job->SpecularTexture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture->m_Texture);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
if (job->SpecularTexture.size() > 0 && job->SpecularTexture[0] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture[0]->m_Texture);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
if (job->IncandescenceTexture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture->m_Texture);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
if (job->IncandescenceTexture.size() > 0 && job->IncandescenceTexture[0] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture[0]->m_Texture);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RawModel::MaterialType::SplatMapping:
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, job->SplatMap->m_Texture);
|
||||
|
||||
int texturePosition = GL_TEXTURE1;
|
||||
//Bind 5 diffuse textures
|
||||
for (unsigned int i = 0; i < 5; i++) {
|
||||
glActiveTexture(texturePosition);
|
||||
if (job->DiffuseTexture.size() > i && job->DiffuseTexture[i] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture[i]->m_Texture);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
}
|
||||
texturePosition++;
|
||||
}
|
||||
//Bind 5 Normal textures
|
||||
for (unsigned int i = 0; i < 5; i++) {
|
||||
glActiveTexture(texturePosition);
|
||||
if (job->NormalTexture.size() > i && job->NormalTexture[i] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->NormalTexture[i]->m_Texture);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
|
||||
}
|
||||
texturePosition++;
|
||||
}
|
||||
//Bind 5 Specular textures
|
||||
for (unsigned int i = 0; i < 5; i++) {
|
||||
glActiveTexture(texturePosition);
|
||||
if (job->SpecularTexture.size() > i && job->SpecularTexture[i] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture[i]->m_Texture);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
|
||||
}
|
||||
texturePosition++;
|
||||
}
|
||||
//Bind 5 Incandescence textures
|
||||
for (unsigned int i = 0; i < 5; i++) {
|
||||
glActiveTexture(texturePosition);
|
||||
if (job->IncandescenceTexture.size() > i && job->IncandescenceTexture[i] != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture[i]->m_Texture);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
|
||||
}
|
||||
texturePosition++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,6 @@ void DrawScreenQuadPass::Draw(GLuint texture)
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
}
|
||||
|
||||
@@ -5,19 +5,69 @@ Model::Model(std::string fileName)
|
||||
//Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller.
|
||||
m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
|
||||
|
||||
for (auto& group : m_RawModel->MaterialGroups) {
|
||||
if (!group.TexturePath.empty()) {
|
||||
group.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.TexturePath));
|
||||
}
|
||||
if (!group.NormalMapPath.empty()) {
|
||||
group.NormalMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.NormalMapPath));
|
||||
}
|
||||
if (!group.SpecularMapPath.empty()) {
|
||||
group.SpecularMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.SpecularMapPath));
|
||||
}
|
||||
if (!group.IncandescenceMapPath.empty()) {
|
||||
group.IncandescenceMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.IncandescenceMapPath));
|
||||
}
|
||||
for (auto& materialProperty : m_RawModel->m_Materials) {
|
||||
switch (materialProperty.type) {
|
||||
case RawModel::MaterialType::SingleTextures:
|
||||
{
|
||||
RawModel::MaterialSingleTextures* materialSingleTexture = static_cast<RawModel::MaterialSingleTextures*>(materialProperty.material);
|
||||
if (!materialSingleTexture->ColorMap.TexturePath.empty()) {
|
||||
materialSingleTexture->ColorMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSingleTexture->ColorMap.TexturePath));
|
||||
}
|
||||
if (!materialSingleTexture->NormalMap.TexturePath.empty()) {
|
||||
materialSingleTexture->NormalMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSingleTexture->NormalMap.TexturePath));
|
||||
}
|
||||
if (!materialSingleTexture->SpecularMap.TexturePath.empty()) {
|
||||
materialSingleTexture->SpecularMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSingleTexture->SpecularMap.TexturePath));
|
||||
}
|
||||
if (!materialSingleTexture->IncandescenceMap.TexturePath.empty()) {
|
||||
materialSingleTexture->IncandescenceMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSingleTexture->IncandescenceMap.TexturePath));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RawModel::MaterialType::SplatMapping:
|
||||
{
|
||||
RawModel::MaterialSplatMapping* materialSplatMapping = static_cast<RawModel::MaterialSplatMapping*>(materialProperty.material);
|
||||
if (!materialSplatMapping->SplatMap.TexturePath.empty()) {
|
||||
materialSplatMapping->SplatMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSplatMapping->SplatMap.TexturePath));
|
||||
}
|
||||
for (auto& texture : materialSplatMapping->ColorMaps)
|
||||
{
|
||||
if (!texture.TexturePath.empty()) {
|
||||
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
|
||||
}
|
||||
else {
|
||||
texture.Texture = nullptr;
|
||||
}
|
||||
}
|
||||
for (auto& texture : materialSplatMapping->NormalMaps)
|
||||
{
|
||||
if (!texture.TexturePath.empty()) {
|
||||
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
|
||||
} else {
|
||||
texture.Texture = nullptr;
|
||||
}
|
||||
}
|
||||
for (auto& texture : materialSplatMapping->SpecularMaps)
|
||||
{
|
||||
if (!texture.TexturePath.empty()) {
|
||||
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
|
||||
}
|
||||
else {
|
||||
texture.Texture = nullptr;
|
||||
}
|
||||
}
|
||||
for (auto& texture : materialSplatMapping->IncandescenceMaps)
|
||||
{
|
||||
if (!texture.TexturePath.empty()) {
|
||||
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
|
||||
}
|
||||
else {
|
||||
texture.Texture = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate GL buffers
|
||||
|
||||
@@ -34,7 +34,7 @@ void RawModelCustom::ReadMeshFile(std::string filePath)
|
||||
ReadMeshFileHeader(offset, fileData);
|
||||
ReadMesh(offset, fileData, fileByteSize);
|
||||
}
|
||||
delete fileData;
|
||||
delete[] fileData;
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadMeshFileHeader(std::size_t& offset, char* fileData)
|
||||
@@ -116,7 +116,7 @@ void RawModelCustom::ReadMaterialFile(std::string filePath)
|
||||
if (fileByteSize > 0) {
|
||||
ReadMaterials(offset, fileData, fileByteSize);
|
||||
}
|
||||
delete fileData;
|
||||
delete[] fileData;
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadMaterials(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
|
||||
@@ -169,15 +169,8 @@ void RawModelCustom::ReadMaterialSingle(std::size_t& offset, char* fileData, con
|
||||
m_Materials.push_back(newMaterialProperty);
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadMaterialBasic(RawModelCustom::MaterialBasic* newMaterial, unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
||||
void RawModelCustom::ReadMaterialBasic(RawModelCustom::MaterialBasic* newMaterial, std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
|
||||
{
|
||||
if (offset + sizeof(unsigned int) * 4 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading Material texture names length failed");
|
||||
}
|
||||
|
||||
unsigned int* nameLengths = (unsigned int*)(fileData + offset);
|
||||
offset += sizeof(unsigned int) * 4;
|
||||
|
||||
if (offset + sizeof(float) * 11 + sizeof(unsigned int) * 2 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading Material specular, reflection, color and start and end index values failed");
|
||||
}
|
||||
@@ -200,42 +193,49 @@ void RawModelCustom::ReadMaterialBasic(RawModelCustom::MaterialBasic* newMateria
|
||||
offset += sizeof(unsigned int);
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadMaterialSingleTexture(RawModelCustom::MaterialSingleTextures* newMaterial, unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
||||
{
|
||||
unsigned char numberOfMaps[4];
|
||||
void RawModelCustom::ReadMaterialSingleTexture(RawModelCustom::MaterialSingleTextures* newMaterial, std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
|
||||
{
|
||||
ReadMaterialBasic(newMaterial, offset, fileData, fileByteSize);
|
||||
if (offset + sizeof(unsigned char) * 4 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading Material NumOfMaps failed");
|
||||
}
|
||||
unsigned char numberOfMaps[4];
|
||||
memcpy(numberOfMaps, fileData + offset, sizeof(unsigned char) * 4);
|
||||
offset += sizeof(unsigned char) * 4;
|
||||
|
||||
if (numberOfMaps[0] > 0)
|
||||
{
|
||||
ReadMaterialTextureProperties(newMaterial->ColorMaps, offset, fileData, fileByteSize);
|
||||
ReadMaterialTextureProperties(newMaterial->ColorMap, offset, fileData, fileByteSize);
|
||||
}
|
||||
|
||||
if (numberOfMaps[1] > 0)
|
||||
{
|
||||
ReadMaterialTextureProperties(newMaterial->SpecularMaps, offset, fileData, fileByteSize);
|
||||
ReadMaterialTextureProperties(newMaterial->SpecularMap, offset, fileData, fileByteSize);
|
||||
}
|
||||
|
||||
if (numberOfMaps[2] > 0)
|
||||
{
|
||||
ReadMaterialTextureProperties(newMaterial->NormalMaps, offset, fileData, fileByteSize);
|
||||
ReadMaterialTextureProperties(newMaterial->NormalMap, offset, fileData, fileByteSize);
|
||||
}
|
||||
|
||||
if (numberOfMaps[3] > 0)
|
||||
{
|
||||
ReadMaterialTextureProperties(newMaterial->IncandescenceMaps, offset, fileData, fileByteSize);
|
||||
ReadMaterialTextureProperties(newMaterial->IncandescenceMap, offset, fileData, fileByteSize);
|
||||
}
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadMaterialSplatMapping(RawModelCustom::MaterialSplatMapping* newMaterial, unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
||||
void RawModelCustom::ReadMaterialSplatMapping(RawModelCustom::MaterialSplatMapping* newMaterial, std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
|
||||
{
|
||||
ReadMaterialBasic(newMaterial, offset, fileData, fileByteSize);
|
||||
ReadMaterialTextureProperties(newMaterial->SplatMap, offset, fileData, fileByteSize);
|
||||
unsigned char numberOfMaps[4];
|
||||
if (offset + sizeof(unsigned char) * 4 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading Material NumOfMaps failed");
|
||||
}
|
||||
|
||||
unsigned char numberOfMaps[4];
|
||||
memcpy(numberOfMaps, fileData + offset, sizeof(unsigned char) * 4);
|
||||
offset += sizeof(unsigned char) * 4;
|
||||
|
||||
newMaterial->ColorMaps.resize(numberOfMaps[0]);
|
||||
for (unsigned char i = 0; i < numberOfMaps[0]; i++)
|
||||
{
|
||||
@@ -261,8 +261,10 @@ void RawModelCustom::ReadMaterialSplatMapping(RawModelCustom::MaterialSplatMappi
|
||||
}
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadMaterialTextureProperties(RawModelCustom::TextureProperties& texture, unsigned int &offset, char* fileData, unsigned int& fileByteSize) {
|
||||
void RawModelCustom::ReadMaterialTextureProperties(RawModelCustom::TextureProperties& texture, std::size_t& offset, char* fileData, const unsigned int& fileByteSize) {
|
||||
unsigned int nameLength = *(unsigned int*)(fileData + offset);
|
||||
offset += sizeof(unsigned int);
|
||||
|
||||
if (nameLength > 0) {
|
||||
if (offset + nameLength > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading Material texture path failed");
|
||||
@@ -312,7 +314,7 @@ void RawModelCustom::ReadAnimationFile(std::string filePath)
|
||||
ReadAnimationBindPoses(offset, fileData, fileByteSize);
|
||||
ReadAnimationClips(offset, fileData, fileByteSize, numAnimations);
|
||||
}
|
||||
delete fileData;
|
||||
delete[] fileData;
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadAnimationBindPoses(std::size_t& offset, char* fileData, const unsigned int& fileByteSize)
|
||||
@@ -432,7 +434,7 @@ void RawModelCustom::ReadAnimationClipSingle(std::size_t& offset, char* fileData
|
||||
#endif
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadAnimationKeyFrame(std::size_t& &offset, char* fileData, const unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation)
|
||||
void RawModelCustom::ReadAnimationKeyFrame(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation)
|
||||
{
|
||||
Skeleton::Animation::Keyframe newKeyFrame;
|
||||
|
||||
@@ -475,6 +477,9 @@ RawModelCustom::~RawModelCustom()
|
||||
if (m_Skeleton != nullptr) {
|
||||
delete m_Skeleton;
|
||||
}
|
||||
for (auto material : m_Materials) {
|
||||
delete material.material;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -113,6 +113,7 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
|
||||
if (cModel["Transparent"]) {
|
||||
transparentJobs.push_back(explosionEffectJob);
|
||||
} else {
|
||||
explosionEffectJob->CalculateHash();
|
||||
opaqueJobs.push_back(explosionEffectJob);
|
||||
}
|
||||
} else {
|
||||
@@ -132,6 +133,7 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
|
||||
if (cModel["Transparent"]) {
|
||||
transparentJobs.push_back(modelJob);
|
||||
} else {
|
||||
modelJob->CalculateHash();
|
||||
opaqueJobs.push_back(modelJob);
|
||||
}
|
||||
}
|
||||
@@ -196,7 +198,7 @@ void RenderSystem::fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World*
|
||||
if (texts == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (auto& textComponent : *texts) {
|
||||
bool visible = textComponent["Visible"];
|
||||
if (!visible) {
|
||||
@@ -252,6 +254,7 @@ void RenderSystem::Update(double dt)
|
||||
}
|
||||
|
||||
fillModels(scene.OpaqueObjects, scene.TransparentObjects);
|
||||
scene.OpaqueObjects.sort();
|
||||
fillPointLights(scene.PointLightJobs, m_World);
|
||||
fillDirectionalLights(scene.DirectionalLightJobs, m_World);
|
||||
fillText(scene.TextJobs, m_World);
|
||||
|
||||
@@ -48,16 +48,16 @@ std::vector<glm::mat4> Skeleton::GetFrameBones(const Animation& animation, doubl
|
||||
while (time > animation.Duration) {
|
||||
time -= animation.Duration;
|
||||
}
|
||||
|
||||
//JOHAN TODO: Ask Viktor about stuff
|
||||
//int currentKeyframeIndex = GetKeyframe(animation, time);
|
||||
|
||||
//const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex];
|
||||
//const Animation::Keyframe& nextFrame = animation.Keyframes[(currentKeyframeIndex + 1) % animation.Keyframes.size()];
|
||||
double alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
|
||||
//double alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
|
||||
|
||||
////auto animationFrame = Animations[""].Keyframes[frame];
|
||||
std::map<int, glm::mat4> frameBones;
|
||||
AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, static_cast<float>(alpha), frameBones, RootBone, glm::mat4(1));
|
||||
//AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, static_cast<float>(alpha), frameBones, RootBone, glm::mat4(1));
|
||||
|
||||
std::vector<glm::mat4> finalMatrices;
|
||||
for (auto &kv : frameBones) {
|
||||
|
||||
Reference in New Issue
Block a user