Skip to content

Commit

Permalink
Merge pull request #176 from carboncopies/174-Implement-PBR
Browse files Browse the repository at this point in the history
174 implement pbr
  • Loading branch information
datacrystals authored Apr 17, 2022
2 parents 08582aa + fbff76e commit b263017
Show file tree
Hide file tree
Showing 14 changed files with 618 additions and 741 deletions.
89 changes: 21 additions & 68 deletions Source/Core/Editor/Widgets/GUI_Widget_ObjectProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,18 @@ void Widget_ObjectProperties::Draw() {
unsigned long Index = SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SceneObjects_[SelectedSceneObject].Index_;
if (ImGui::CollapsingHeader("Point Light Settings", ImGuiTreeNodeFlags_DefaultOpen)) {

float DiffuseColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Diffuse, DiffuseColor);
ImGui::ColorEdit3("Diffuse", DiffuseColor);
float Color[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Color, Color);
ImGui::ColorEdit3("Color", Color);
ImGui::SameLine();
ImGui::HelpMarker("Controls the main color of the light.");
FloatToVec(DiffuseColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Diffuse);
float AmbientColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Ambient, AmbientColor);
ImGui::ColorEdit3("Ambient", AmbientColor);
ImGui::SameLine();
ImGui::HelpMarker("Controls any additions to the ambient color of the environment. Generally, you shouldn't do this with a point light, use a directional light whenever possible instead.");
FloatToVec(AmbientColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Ambient);
float SpecularColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Specular, SpecularColor);
ImGui::ColorEdit3("Specular", SpecularColor);
ImGui::SameLine();
ImGui::HelpMarker("Controls the color of the reflection.");
FloatToVec(SpecularColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Specular);
ImGui::Separator();
FloatToVec(Color, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Color);


ImGui::DragFloat("Rolloff Constant", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->RolloffConstant, 0.01f);
ImGui::SameLine();
ImGui::HelpMarker("Sets the constant offset controlling lamp attenuation over distance. If you're trying to make the rolloff sharper, try linear or quadratic.");
ImGui::DragFloat("Rolloff Linear", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->RolloffLinear, 0.01f);
ImGui::SameLine();
ImGui::HelpMarker("Component of rolloff proportional to distance from light to object. E.g. twice the distance means half the brightness.");
ImGui::DragFloat("Rolloff Quadratic", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->RolloffQuadratic, 0.01f);
ImGui::DragFloat("Intensity", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Intensity, 0.01f);
ImGui::SameLine();
ImGui::HelpMarker("Exponential component of rolloff. Increasing this, makes the rolloff much sharper. For a linear rolloff, use the 'Rolloff Linear' value.");
ImGui::HelpMarker("Sets the brightness of the light source, increase this for a brighter light.");


}

Expand All @@ -84,25 +67,13 @@ void Widget_ObjectProperties::Draw() {
unsigned long Index = SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SceneObjects_[SelectedSceneObject].Index_;
if (ImGui::CollapsingHeader("Directional Light Settings", ImGuiTreeNodeFlags_DefaultOpen)) {

float DiffuseColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Diffuse, DiffuseColor);
ImGui::ColorEdit3("Diffuse", DiffuseColor);
float Color[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Color, Color);
ImGui::ColorEdit3("Color", Color);
ImGui::SameLine();
ImGui::HelpMarker("Controls the main color of the light.");
FloatToVec(DiffuseColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Diffuse);
float AmbientColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Ambient, AmbientColor);
ImGui::ColorEdit3("Ambient", AmbientColor);
ImGui::SameLine();
ImGui::HelpMarker("Controls any additions to the ambient color of the environment.");
FloatToVec(AmbientColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Ambient);
float SpecularColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Specular, SpecularColor);
ImGui::ColorEdit3("Specular", SpecularColor);
ImGui::SameLine();
ImGui::HelpMarker("Controls the color of the reflection. Generally, you shouldn't do this with a directional light, use a spot or point light instead.");
FloatToVec(SpecularColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Specular);
ImGui::Separator();
FloatToVec(Color, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Color);


}

Expand All @@ -111,36 +82,18 @@ void Widget_ObjectProperties::Draw() {
unsigned long Index = SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SceneObjects_[SelectedSceneObject].Index_;
if (ImGui::CollapsingHeader("Spot Light Settings", ImGuiTreeNodeFlags_DefaultOpen)) {

float DiffuseColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Diffuse, DiffuseColor);
ImGui::ColorEdit3("Diffuse", DiffuseColor);
float Color[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Color, Color);
ImGui::ColorEdit3("Color", Color);
ImGui::SameLine();
ImGui::HelpMarker("Controls the main color of the light.");
FloatToVec(DiffuseColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Diffuse);
float AmbientColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Ambient, AmbientColor);
ImGui::ColorEdit3("Ambient", AmbientColor);
ImGui::SameLine();
ImGui::HelpMarker("Controls any additions to the ambient color of the environment. Generally, you shouldn't do this with a spot light, use a directional light whenever possible instead.");
FloatToVec(AmbientColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Ambient);
float SpecularColor[3];
VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Specular, SpecularColor);
ImGui::ColorEdit3("Specular", SpecularColor);
ImGui::SameLine();
ImGui::HelpMarker("Controls the color of the reflection.");
FloatToVec(SpecularColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Specular);
ImGui::Separator();
FloatToVec(Color, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Color);

ImGui::DragFloat("Rolloff Constant", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->RolloffConstant, 0.01f);
ImGui::SameLine();
ImGui::HelpMarker("Sets the constant offset controlling lamp attenuation over distance. If you're trying to make the rolloff sharper, try linear or quadratic.");
ImGui::DragFloat("Rolloff Linear", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->RolloffLinear, 0.01f);
ImGui::SameLine();
ImGui::HelpMarker("Component of rolloff proportional to distance from light to object. E.g. twice the distance means half the brightness.");
ImGui::DragFloat("Rolloff Quadratic", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->RolloffQuadratic, 0.01f);

ImGui::DragFloat("Intensity", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Intensity, 0.01f);
ImGui::SameLine();
ImGui::HelpMarker("Exponential component of rolloff. Increasing this, makes the rolloff much sharper. For a linear rolloff, use the 'Rolloff Linear' value.");
ImGui::Separator();
ImGui::HelpMarker("Sets the brightness of the light source, increase this for a brighter light.");


ImGui::DragFloat("Cutoff", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->CutOff, 0.01f);
ImGui::SameLine();
Expand Down
86 changes: 29 additions & 57 deletions Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,15 @@ ERS_STRUCT_Scene ERS_CLASS_SceneLoader::ProcessScene(YAML::Node RawSceneData, lo
int LightIndex = Scene.DirectionalLights.size() - 1;

Scene.DirectionalLights[LightIndex]->UserDefinedName = AssetName;

Scene.DirectionalLights[LightIndex]->Ambient = glm::vec3(
SceneDataNode[i]["AmbientRed"].as<float>(),
SceneDataNode[i]["AmbientGreen"].as<float>(),
SceneDataNode[i]["AmbientBlue"].as<float>()
);
Scene.DirectionalLights[LightIndex]->Diffuse = glm::vec3(
SceneDataNode[i]["DiffuseRed"].as<float>(),
SceneDataNode[i]["DiffuseGreen"].as<float>(),
SceneDataNode[i]["DiffuseBlue"].as<float>()
);
Scene.DirectionalLights[LightIndex]->Specular = glm::vec3(
SceneDataNode[i]["SpecularRed"].as<float>(),
SceneDataNode[i]["SpecularGreen"].as<float>(),
SceneDataNode[i]["SpecularBlue"].as<float>()
);

if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) {
Scene.DirectionalLights[LightIndex]->Color = glm::vec3(
SceneDataNode[i]["ColorRed"].as<float>(),
SceneDataNode[i]["ColorGreen"].as<float>(),
SceneDataNode[i]["ColorBlue"].as<float>()
);
}


Scene.DirectionalLights[LightIndex]->Pos = glm::vec3(
SceneDataNode[i]["PosX"].as<float>(),
Expand Down Expand Up @@ -164,28 +157,18 @@ ERS_STRUCT_Scene ERS_CLASS_SceneLoader::ProcessScene(YAML::Node RawSceneData, lo
int LightIndex = Scene.PointLights.size() - 1;

Scene.PointLights[LightIndex]->UserDefinedName = AssetName;


Scene.PointLights[LightIndex]->RolloffConstant = SceneDataNode[i]["RolloffConstant"].as<float>();
Scene.PointLights[LightIndex]->RolloffLinear = SceneDataNode[i]["RolloffLinear"].as<float>();
Scene.PointLights[LightIndex]->RolloffQuadratic = SceneDataNode[i]["RolloffQuadratic"].as<float>();
if (SceneDataNode[i]["Intensity"]) {
Scene.PointLights[LightIndex]->Intensity = SceneDataNode[i]["Intensity"].as<float>();
}


Scene.PointLights[LightIndex]->Ambient = glm::vec3(
SceneDataNode[i]["AmbientRed"].as<float>(),
SceneDataNode[i]["AmbientGreen"].as<float>(),
SceneDataNode[i]["AmbientBlue"].as<float>()
);
Scene.PointLights[LightIndex]->Diffuse = glm::vec3(
SceneDataNode[i]["DiffuseRed"].as<float>(),
SceneDataNode[i]["DiffuseGreen"].as<float>(),
SceneDataNode[i]["DiffuseBlue"].as<float>()
);
Scene.PointLights[LightIndex]->Specular = glm::vec3(
SceneDataNode[i]["SpecularRed"].as<float>(),
SceneDataNode[i]["SpecularGreen"].as<float>(),
SceneDataNode[i]["SpecularBlue"].as<float>()
);
if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) {
Scene.PointLights[LightIndex]->Color = glm::vec3(
SceneDataNode[i]["ColorRed"].as<float>(),
SceneDataNode[i]["ColorGreen"].as<float>(),
SceneDataNode[i]["ColorBlue"].as<float>()
);
}

Scene.PointLights[LightIndex]->Pos = glm::vec3(
SceneDataNode[i]["PosX"].as<float>(),
Expand All @@ -209,31 +192,20 @@ ERS_STRUCT_Scene ERS_CLASS_SceneLoader::ProcessScene(YAML::Node RawSceneData, lo

Scene.SpotLights[LightIndex]->UserDefinedName = AssetName;


Scene.SpotLights[LightIndex]->RolloffConstant = SceneDataNode[i]["RolloffConstant"].as<float>();
Scene.SpotLights[LightIndex]->RolloffLinear = SceneDataNode[i]["RolloffLinear"].as<float>();
Scene.SpotLights[LightIndex]->RolloffQuadratic = SceneDataNode[i]["RolloffQuadratic"].as<float>();


if (SceneDataNode[i]["Intensity"]) {
Scene.SpotLights[LightIndex]->Intensity = SceneDataNode[i]["Intensity"].as<float>();
}
Scene.SpotLights[LightIndex]->CutOff = SceneDataNode[i]["CutOff"].as<float>();
Scene.SpotLights[LightIndex]->OuterCutOff = SceneDataNode[i]["OuterCutOff"].as<float>();

if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) {
Scene.SpotLights[LightIndex]->Color = glm::vec3(
SceneDataNode[i]["ColorRed"].as<float>(),
SceneDataNode[i]["ColorGreen"].as<float>(),
SceneDataNode[i]["ColorBlue"].as<float>()
);
}

Scene.SpotLights[LightIndex]->Ambient = glm::vec3(
SceneDataNode[i]["AmbientRed"].as<float>(),
SceneDataNode[i]["AmbientGreen"].as<float>(),
SceneDataNode[i]["AmbientBlue"].as<float>()
);
Scene.SpotLights[LightIndex]->Diffuse = glm::vec3(
SceneDataNode[i]["DiffuseRed"].as<float>(),
SceneDataNode[i]["DiffuseGreen"].as<float>(),
SceneDataNode[i]["DiffuseBlue"].as<float>()
);
Scene.SpotLights[LightIndex]->Specular = glm::vec3(
SceneDataNode[i]["SpecularRed"].as<float>(),
SceneDataNode[i]["SpecularGreen"].as<float>(),
SceneDataNode[i]["SpecularBlue"].as<float>()
);

Scene.SpotLights[LightIndex]->Pos = glm::vec3(
SceneDataNode[i]["PosX"].as<float>(),
Expand Down
23 changes: 8 additions & 15 deletions Source/Core/Manager/ERS_SceneManager/ERS_SceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,10 @@ void ERS_CLASS_SceneManager::AddPointLight() {
std::shared_ptr<ERS_STRUCT_PointLight> Light = std::make_shared<ERS_STRUCT_PointLight>();

Light->UserDefinedName = "New Point Light";
Light->Ambient = glm::vec3(0.0f);
Light->Diffuse = glm::vec3(0.5f);
Light->Specular = glm::vec3(0.5f);
Light->Color = glm::vec3(0.0f);

Light->RolloffConstant = 1.0f;
Light->RolloffLinear = 0.18f;
Light->RolloffQuadratic = 0.064f;

Light->Intensity = 1.0f;

Scenes_[ActiveScene_]->PointLights.push_back(Light);
Scenes_[ActiveScene_]->IndexSceneObjects();
Expand All @@ -138,9 +135,8 @@ void ERS_CLASS_SceneManager::AddDirectionalLight() {
std::shared_ptr<ERS_STRUCT_DirectionalLight> Light = std::make_shared<ERS_STRUCT_DirectionalLight>();

Light->UserDefinedName = "New Directional Light";
Light->Ambient = glm::vec3(0.0f);
Light->Diffuse = glm::vec3(0.5f);
Light->Specular = glm::vec3(0.5f);
Light->Color = glm::vec3(0.0f);


Scenes_[ActiveScene_]->DirectionalLights.push_back(Light);
Scenes_[ActiveScene_]->IndexSceneObjects();
Expand All @@ -152,13 +148,10 @@ void ERS_CLASS_SceneManager::AddSpotLight() {
std::shared_ptr<ERS_STRUCT_SpotLight> Light = std::make_shared<ERS_STRUCT_SpotLight>();

Light->UserDefinedName = "New Spot Light";
Light->Ambient = glm::vec3(0.0f);
Light->Diffuse = glm::vec3(0.5f);
Light->Specular = glm::vec3(0.5f);
Light->Color = glm::vec3(0.0f);


Light->RolloffConstant = 1.0f;
Light->RolloffLinear = 0.18f;
Light->RolloffQuadratic = 0.064f;
Light->Intensity = 1.0f;

Light->CutOff = 0.970f;
Light->OuterCutOff = 0.960f;
Expand Down
Loading

0 comments on commit b263017

Please sign in to comment.