Skip to content

Commit

Permalink
Merge pull request #206 from OnionGalaxy/fix/carlos_suggestions
Browse files Browse the repository at this point in the history
Fix/carlos suggestions
  • Loading branch information
mariofv authored Jul 2, 2020
2 parents ffb8556 + 68f4db4 commit 084d864
Show file tree
Hide file tree
Showing 42 changed files with 133 additions and 219 deletions.
5 changes: 1 addition & 4 deletions Engine/Component/ComponentMeshRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ void ComponentMeshRenderer::RenderModel() const

void ComponentMeshRenderer::RenderMaterial(GLuint shader_program) const
{
glUniform1i(glGetUniformLocation(shader_program, "time"), App->time->real_time_delta_time);
AddDiffuseUniforms(shader_program);
AddEmissiveUniforms(shader_program);
AddSpecularUniforms(shader_program);
Expand All @@ -124,7 +123,6 @@ void ComponentMeshRenderer::AddDiffuseUniforms(unsigned int shader_program) cons
glUniform1i(glGetUniformLocation(shader_program, "material.diffuse_map"), 0);

glUniform4fv(glGetUniformLocation(shader_program, "material.diffuse_color"), 1, (float*)material_to_render->diffuse_color);
glUniform1f(glGetUniformLocation(shader_program, "material.k_diffuse"), material_to_render->k_diffuse);

}

Expand All @@ -144,7 +142,7 @@ void ComponentMeshRenderer::AddSpecularUniforms(unsigned int shader_program) con

glUniform1i(glGetUniformLocation(shader_program, "material.specular_map"), 2);
glUniform4fv(glGetUniformLocation(shader_program, "material.specular_color"), 1, (float*)material_to_render->specular_color);
glUniform1f(glGetUniformLocation(shader_program, "material.k_specular"), material_to_render->k_specular);
glUniform1f(glGetUniformLocation(shader_program, "material.smoothness"), material_to_render->smoothness);

}

Expand All @@ -153,7 +151,6 @@ void ComponentMeshRenderer::AddAmbientOclusionUniforms(unsigned int shader_progr
glActiveTexture(GL_TEXTURE3);
BindTexture(Material::MaterialTextureType::OCCLUSION);
glUniform1i(glGetUniformLocation(shader_program, "material.occlusion_map"), 3);
glUniform1f(glGetUniformLocation(shader_program, "material.k_ambient"), material_to_render->k_ambient);
}

void ComponentMeshRenderer::AddNormalUniforms(unsigned int shader_program) const
Expand Down
21 changes: 3 additions & 18 deletions Engine/EditorUI/Panel/InspectorSubpanel/PanelMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,7 @@ bool PanelMaterial::ShowMaterialTextureMap(std::shared_ptr<Material> material, M
ImGui::Spacing();
ImGui::Indent();

if (ImGui::ColorEdit3("Color", material->diffuse_color))
{
modified_by_user = true;
}
if (ImGui::SliderFloat("K diffuse", &material->k_diffuse, 0.f, 1.f))
if (ImGui::ColorEdit3("Color", material->diffuse_color, ImGuiColorEditFlags_Float))
{
modified_by_user = true;
}
Expand Down Expand Up @@ -263,13 +259,6 @@ bool PanelMaterial::ShowMaterialTextureMap(std::shared_ptr<Material> material, M
ImGui::Text("Occlusion");

ImGui::Spacing();
ImGui::Indent();

if (ImGui::SliderFloat("k ambient", &material->k_ambient, 0, 1))
{
modified_by_user = true;
}
ImGui::Unindent();

break;

Expand All @@ -279,15 +268,11 @@ bool PanelMaterial::ShowMaterialTextureMap(std::shared_ptr<Material> material, M
ImGui::Spacing();
ImGui::Indent();

if (ImGui::ColorEdit3("Color", material->specular_color))
{
modified_by_user = true;
}
if (ImGui::SliderFloat("k specular", &material->k_specular, 0.f, 1.f))
if (ImGui::ColorEdit3("Color", material->specular_color, ImGuiColorEditFlags_Float))
{
modified_by_user = true;
}
if (ImGui::SliderFloat("Shininess", &material->specular_color[3], 0.f, 1.f))
if (ImGui::SliderFloat("Smoothenss", &material->smoothness, 0.f, 1.f))
{
modified_by_user = true;
}
Expand Down
5 changes: 5 additions & 0 deletions Engine/EditorUI/Panel/PanelScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Component/ComponentCamera.h"
#include "EditorUI/Panel/PanelHierarchy.h"
#include "Filesystem/PathAtlas.h"
#include "Main/Application.h"
#include "Main/GameObject.h"
#include "Module/ModuleAI.h"
Expand Down Expand Up @@ -135,6 +136,10 @@ void PanelScene::RenderSceneBar()
App->debug->show_debug_metrics = !App->debug->show_debug_metrics;
}

if (ImGui::Selectable("Reload shaders", false, ImGuiSelectableFlags_None, ImVec2(100, 0)))
{
App->program->LoadPrograms(SHADERS_PATH);
}
ImGui::EndMenuBar();

}
Expand Down
2 changes: 1 addition & 1 deletion Engine/Module/ModuleProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class ModuleProgram : public Module
bool Init() override;
bool CleanUp() override;

void LoadPrograms(const char* file_path);
unsigned int GetShaderProgramId(const std::string & program_name) const;

private:
bool LoadProgram(std::string name, const char* vertex_shader_file_name, const char* fragment_shader_file_name);
void LoadPrograms(const char* file_path);
bool InitVertexShader(GLuint &vertex_shader, const char* vertex_shader_file_name) const;
bool InitFragmentShader(GLuint &fragment_shader, const char* fragment_shader_file_name) const;
bool InitProgram(GLuint &shader_program,GLuint vertex_shader,GLuint fragment_shader) const;
Expand Down
1 change: 1 addition & 0 deletions Engine/Module/ModuleResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ update_status ModuleResourceManager::PreUpdate()
#if !GAME
if (!App->time->isGameRunning() && last_imported_time > 0.0f && (thread_timer->Read() - last_imported_time) >= importer_interval_millis)
{
assert(importing_thread.joinable());
importing_thread.join();
importing_thread = std::thread(&ModuleResourceManager::StartThread, this);
}
Expand Down
34 changes: 8 additions & 26 deletions Engine/ResourceManagement/Importer/MaterialImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "ResourceManagement/Importer/TextureImporter.h"
#include "ResourceManagement/Resources/Material.h"
#include "ResourceManagement/Metafile/TextureMetafile.h"

#include <assimp/scene.h>

Expand All @@ -34,6 +35,7 @@ FileData MaterialImporter::ExtractMaterialFromAssimp(const aiMaterial* assimp_me
assimp_mesh_material->GetTexture(type, j, &file, &mapping, 0);
uint32_t material_texture_uuid = ImportMaterialTexture(file.data, material_file_folder_path);

Metafile* metafile = App->resources->resource_DB->GetEntry(material_texture_uuid);
if (material_texture_uuid != 0)
{
switch (type)
Expand All @@ -50,6 +52,12 @@ FileData MaterialImporter::ExtractMaterialFromAssimp(const aiMaterial* assimp_me
case aiTextureType_AMBIENT_OCCLUSION:
material_config.AddUInt(material_texture_uuid, "Occlusion");
break;
case aiTextureType_NORMALS:
material_config.AddUInt(material_texture_uuid, "Normal");
break;
case aiTextureType_LIGHTMAP:
material_config.AddUInt(material_texture_uuid, "Lightmap");
break;
default:
material_config.AddUInt(material_texture_uuid, "Unknown");
break;
Expand All @@ -60,10 +68,6 @@ FileData MaterialImporter::ExtractMaterialFromAssimp(const aiMaterial* assimp_me
material_config.AddBool(imported_material.show_checkerboard_texture, "Checkboard");
material_config.AddString(imported_material.shader_program, "ShaderProgram");

//k
material_config.AddFloat(imported_material.k_ambient, "kAmbient");
material_config.AddFloat(imported_material.k_specular, "kSpecular");
material_config.AddFloat(imported_material.k_diffuse, "kDiffuse");

//colors
material_config.AddColor(
Expand Down Expand Up @@ -140,25 +144,3 @@ uint32_t MaterialImporter::ImportMaterialTexture(const std::string& texture_desc

return 0;
}

Material::MaterialTextureType MaterialImporter::GetTextureTypeFromAssimpType(aiTextureType type) const
{
switch (type)
{
case aiTextureType_DIFFUSE:
return Material::MaterialTextureType::DIFFUSE;
break;
case aiTextureType_SPECULAR:
return Material::MaterialTextureType::SPECULAR;
break;
case aiTextureType_EMISSIVE:
return Material::MaterialTextureType::EMISSIVE;
break;
case aiTextureType_AMBIENT_OCCLUSION:
return Material::MaterialTextureType::OCCLUSION;
break;
default:
return Material::MaterialTextureType::UNKNOWN;
break;
}
}
1 change: 0 additions & 1 deletion Engine/ResourceManagement/Importer/MaterialImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class MaterialImporter : public Importer

private:
uint32_t ImportMaterialTexture(const std::string& texture_file_name, const Path& material_file_folder_path) const;
Material::MaterialTextureType GetTextureTypeFromAssimpType(aiTextureType type) const;
};

#endif // !_MATERIALIMPORTER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Module/ModuleFileSystem.h"
#include "Module/ModuleResourceManager.h"
#include "ResourceManagement/Resources/Skeleton.h"

#include "Helper/Utils.h"
#include <map>

FileData MeshImporter::ExtractData(Path& assets_file_path, const Metafile& metafile) const
Expand All @@ -24,6 +24,8 @@ FileData MeshImporter::ExtractMeshFromAssimp(const aiMesh* mesh, const aiMatrix4

node_transformation = scaling_matrix * node_transformation;

float3x3 node_rotation = Utils::GetTransform(mesh_current_transformation, 1.0f).RotatePart();

std::vector<uint32_t> indices;
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
{
Expand Down Expand Up @@ -54,6 +56,8 @@ FileData MeshImporter::ExtractMeshFromAssimp(const aiMesh* mesh, const aiMatrix4
Mesh::Vertex new_vertex;
aiVector3D transformed_position = node_transformation * mesh->mVertices[i];
new_vertex.position = float3(transformed_position.x, transformed_position.y, transformed_position.z);


for (size_t j = 0; j < UVChannel::TOTALUVS; j++)
{
float2 text_coordinate(float2::zero);
Expand All @@ -65,15 +69,15 @@ FileData MeshImporter::ExtractMeshFromAssimp(const aiMesh* mesh, const aiMatrix4
}
if (mesh->mNormals)
{
new_vertex.normals = float3(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z).Normalized();
new_vertex.normals = (node_rotation * float3(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z)).Normalized();
}
if (mesh->mTangents)
{
new_vertex.tangent = float3(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z).Normalized();
new_vertex.tangent = (node_rotation * float3(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z)).Normalized();
}
if (mesh->mBitangents)
{
new_vertex.bitangent = float3(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z).Normalized();
new_vertex.bitangent = (node_rotation*float3(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z)).Normalized();
}
if (vertex_skinning__info.size() > 0)
{
Expand Down
14 changes: 4 additions & 10 deletions Engine/ResourceManagement/Resources/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ void Material::Save(Config& config) const
config.AddBool(show_checkerboard_texture, "Checkboard");
config.AddString(shader_program, "ShaderProgram");

//k
config.AddFloat(k_ambient, "kAmbient");
config.AddFloat(k_specular, "kSpecular");
config.AddFloat(k_diffuse, "kDiffuse");
config.AddFloat(smoothness, "Smoothness");

config.AddFloat(transparency, "Transparency");
// config.AddFloat(roughness, "Roughness");
Expand Down Expand Up @@ -107,12 +104,9 @@ void Material::Load(const Config& config)

material_type = static_cast<MaterialType>(config.GetInt("MaterialType", 0));

//k
k_ambient = config.GetFloat("kAmbient", 1.0f);
k_specular = config.GetFloat("kSpecular", 1.0f);
k_diffuse = config.GetFloat("kDiffuse", 1.0f);

transparency = config.GetFloat("Transparency", 1.f);
smoothness = config.GetFloat("Smoothness", 1.0F);


tiling_x = config.GetFloat("Tiling X", 1.0f);
tiling_y = config.GetFloat("Tiling Y", 1.0f);
Expand All @@ -137,7 +131,7 @@ void Material::Load(const Config& config)

config.GetColor("difusseColor", diffuse, float4(1.f, 1.f, 1.f, 1.f));
config.GetColor("emissiveColor", emissive, float4(0.0f, 0.0f, 0.0f, 1.0f));
config.GetColor("specularColor", specular, float4(0.0f, 0.0f, 0.0f, 1.0f));
config.GetColor("specularColor", specular, float4(0.125f, 0.125f, 0.125f, 0.125f));

diffuse_color[0] = diffuse.x;
diffuse_color[1] = diffuse.y;
Expand Down
6 changes: 2 additions & 4 deletions Engine/ResourceManagement/Resources/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ class Material : public Resource

float diffuse_color[4] = { 1.0f, 1.0f,1.0f,1.0f };
float emissive_color[4] = { 1.0f, 1.0f, 1.0f , 1.0f };
float specular_color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
float k_diffuse = 1.0f;
float k_specular = 1.0f;
float k_ambient = 1.0f;
float specular_color[4] = { 0.125f, 0.125f, 0.125f, 0.125f };
float smoothness = 1.0F;

float2 coords = float2(1.0f, 1.0f);

Expand Down
Binary file modified Game/Resources/Fonts/Montserrat-Light.ttf.meta
Binary file not shown.
Binary file modified Game/Resources/Fonts/fa-brands-400.ttf.meta
Binary file not shown.
Binary file modified Game/Resources/Fonts/fa-regular-400.ttf.meta
Binary file not shown.
Binary file modified Game/Resources/Fonts/fa-solid-900.ttf.meta
Binary file not shown.
Binary file modified Game/Resources/Materials/default.mat.meta
Binary file not shown.
Binary file modified Game/Resources/Meshes/Cube/Cube.FBX.meta
Binary file not shown.
Binary file modified Game/Resources/Meshes/Cylinder/Cylinder.FBX.meta
Binary file not shown.
Binary file modified Game/Resources/Meshes/Quad/Plane.FBX.meta
Binary file not shown.
Binary file modified Game/Resources/Meshes/Sphere/Sphere.FBX.meta
Binary file not shown.
Binary file modified Game/Resources/Meshes/Torus/Torus.FBX.meta
Binary file not shown.
Binary file modified Game/Resources/Primitives/Cube/cube.fbx.meta
Binary file not shown.
Binary file modified Game/Resources/Primitives/Cylinder/cylinder.fbx.meta
Binary file not shown.
Binary file modified Game/Resources/Primitives/Quad/quad.fbx.meta
Binary file not shown.
Binary file modified Game/Resources/Primitives/Sphere/sphere.fbx.meta
Binary file not shown.
Binary file modified Game/Resources/Primitives/Torus/torus.fbx.meta
Binary file not shown.
Binary file modified Game/Resources/Scenes/default_scene.scene.meta
Binary file not shown.
Binary file modified Game/Resources/Scenes/tmp_scene.scene.meta
Binary file not shown.
Loading

0 comments on commit 084d864

Please sign in to comment.