Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ICE/Components/include/LightComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#include "Component.h"

namespace ICE {
enum LightType { PointLight, DirectionalLight, SpotLight };
enum LightType { PointLight = 0, DirectionalLight = 1, SpotLight = 2 };

struct LightComponent : public Component {
LightComponent(LightType t, const Eigen::Vector3f &col) : type(t), color(col) {}
LightType type;
Eigen::Vector3f color;
float distance_dropoff = 0;
};
} // namespace ICE

Expand Down
6 changes: 1 addition & 5 deletions ICE/Core/include/ICEEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ICEEngine {

void step();

Eigen::Vector4i getPickingTextureAt(int x, int y);
void setupScene(const std::shared_ptr<Camera>& camera_);

std::shared_ptr<Camera> getCamera();

Expand All @@ -49,10 +49,6 @@ class ICEEngine {
std::shared_ptr<Framebuffer> getInternalFramebuffer() const;
void setRenderFramebufferInternal(bool use_internal);

void importMesh();

void importTexture(bool cubeMap);

private:
std::shared_ptr<GraphicsFactory> m_graphics_factory;
std::shared_ptr<Context> ctx;
Expand Down
69 changes: 12 additions & 57 deletions ICE/Core/src/ICEEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ void ICEEngine::step() {
project->getCurrentScene()->getRegistry()->updateSystems(0.0);
}

void ICEEngine::setupScene(const std::shared_ptr<Camera> &camera_) {
auto renderer = std::make_shared<ForwardRenderer>(api, m_graphics_factory, project->getCurrentScene()->getRegistry(), project->getAssetBank());
auto rs = std::make_shared<RenderSystem>();
rs->setCamera(camera_);
rs->setRenderer(renderer);
project->getCurrentScene()->getRegistry()->addSystem(rs);

auto [w, h] = m_window->getSize();
renderer->resize(w, h);
}

std::shared_ptr<Camera> ICEEngine::getCamera() {
return camera;
}
Expand All @@ -45,31 +56,6 @@ std::shared_ptr<AssetBank> ICEEngine::getAssetBank() {
return project->getAssetBank();
}

Eigen::Vector4i ICEEngine::getPickingTextureAt(int x, int y) {
/* pickingFB->bind();
pickingFB->resize(gui.getSceneViewportWidth(), gui.getSceneViewportHeight());
api->setViewport(0, 0, gui.getSceneViewportWidth(), gui.getSceneViewportHeight());
camera.setParameters({60, (float) gui.getSceneViewportWidth() / (float) gui.getSceneViewportHeight(), 0.01f, 1000});
api->setClearColor(0, 0, 0, 0);
api->clear();
getAssetBank()->getAsset<Shader>("__ice__picking_shader")->bind();
getAssetBank()->getAsset<Shader>("__ice__picking_shader")->loadMat4("projection", camera.getProjection());
getAssetBank()->getAsset<Shader>("__ice__picking_shader")->loadMat4("view", camera.lookThrough());
int id = 1;
for (auto e : currentScene->getRegistry()->getEntities()) {
//getAssetBank()->getAsset<Shader>("__ice__picking_shader")->loadMat4("model", e->getComponent<TransformComponent>()->getTransformation());
//getAssetBank()->getAsset<Shader>("__ice__picking_shader")->loadInt("objectID", id++);
//if(e->hasComponent<RenderComponent>()) {
// api->renderVertexArray(getAssetBank()->getAsset<Mesh>(e->getComponent<RenderComponent>()->getMesh())->getVertexArray());
//}
}
auto color = internalFB->readPixel(x, y);
internalFB->unbind();
return color;
*/
return Eigen::Vector4i();
}

std::shared_ptr<RendererAPI> ICEEngine::getApi() const {
return api;
}
Expand All @@ -94,15 +80,7 @@ void ICEEngine::setProject(const std::shared_ptr<Project> &project) {
this->project = project;
this->camera->getPosition() = project->getCameraPosition();
this->camera->getRotation() = project->getCameraRotation();

auto renderer = std::make_shared<ForwardRenderer>(api, m_graphics_factory, project->getCurrentScene()->getRegistry(), project->getAssetBank());
auto rs = std::make_shared<RenderSystem>();
rs->setCamera(camera);
rs->setRenderer(renderer);
project->getCurrentScene()->getRegistry()->addSystem(rs);

auto [w, h] = m_window->getSize();
renderer->resize(w, h);
setupScene(camera);
}

EngineConfig &ICEEngine::getConfig() {
Expand All @@ -116,27 +94,4 @@ std::shared_ptr<GraphicsFactory> ICEEngine::getGraphicsFactory() const {
std::shared_ptr<Context> ICEEngine::getContext() const {
return ctx;
}

int import_cnt = 0;
void ICEEngine::importMesh() {
const std::string file = FileUtils::openFileDialog("obj");
if (file != "") {
std::string aname = "imported_mesh_" + std::to_string(import_cnt++);
getAssetBank()->addAsset<Mesh>(aname, {file});
project->copyAssetFile("Meshes", aname, file);
}
}

void ICEEngine::importTexture(bool cubeMap) {
const std::string file = FileUtils::openFileDialog("");
if (file != "") {
std::string aname = "imported_texture_" + std::to_string(import_cnt++);
if (cubeMap) {
getAssetBank()->addAsset<TextureCube>(aname, {file});
} else {
getAssetBank()->addAsset<Texture2D>(aname, {file});
}
project->copyAssetFile("Textures", aname, file);
}
}
} // namespace ICE
2 changes: 1 addition & 1 deletion ICE/Entity/include/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EntityManager {
void setSignature(Entity e, Signature s) { signatures[e] = s; }

Signature getSignature(Entity e) const {
if (e == 0) {
if (e == 0 || !signatures.contains(e)) {
return 0;
}
return signatures.at(e);
Expand Down
10 changes: 7 additions & 3 deletions ICE/Graphics/src/ForwardRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ ForwardRenderer::ForwardRenderer(const std::shared_ptr<RendererAPI>& api, const
}

void ForwardRenderer::submit(Entity e) {
if (std::find(m_render_queue.begin(), m_render_queue.end(), e) == m_render_queue.end() && m_registry->entityHasComponent<RenderComponent>(e)) {
remove(e);
if (m_registry->entityHasComponent<RenderComponent>(e)) {
m_render_queue.emplace_back(e);
}
if (std::find(m_lights.begin(), m_lights.end(), e) == m_lights.end() && m_registry->entityHasComponent<LightComponent>(e)) {
if (m_registry->entityHasComponent<LightComponent>(e)) {
m_lights.emplace_back(e);
}
if (m_registry->entityHasComponent<SkyboxComponent>(e)) {
Expand Down Expand Up @@ -71,7 +72,10 @@ void ForwardRenderer::prepareFrame(Camera& camera) {
auto rc_b = m_registry->getComponent<RenderComponent>(b);
auto material_b = m_asset_bank->getAsset<Material>(rc_b->material);

if (!material_a->isTransparent() && material_b->isTransparent()) {
bool a_transparent = material_a ? material_a->isTransparent() : false;
bool b_transparent = material_b ? material_b->isTransparent() : false;

if (!a_transparent && b_transparent) {
return true;
} else {
return false;
Expand Down
7 changes: 6 additions & 1 deletion ICE/GraphicsAPI/OpenGL/src/OpenGLFramebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ Eigen::Vector4i OpenGLFramebuffer::readPixel(int x, int y) {
glFlush();
glFinish();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
unsigned char data[4];
auto pixels = Eigen::Vector4i();
glReadPixels(x, format.height - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glReadPixels(x, format.height - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
pixels.x() = data[0];
pixels.y() = data[1];
pixels.z() = data[2];
pixels.w() = data[3];
return pixels;
}
} // namespace ICE
1 change: 1 addition & 0 deletions ICE/Scene/include/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Scene {
Entity createEntity();
void addEntity(Entity e, const std::string& alias, Entity parent);
void removeEntity(Entity e);
bool hasEntity(Entity e);

private:
std::string name;
Expand Down
5 changes: 5 additions & 0 deletions ICE/Scene/src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ void Scene::removeEntity(Entity e) {
aliases.erase(e);
m_graph->removeEntity(e);
}

bool Scene::hasEntity(Entity e) {
return aliases.contains(e);
}

} // namespace ICE
107 changes: 62 additions & 45 deletions ICEBERG/Components/UniformInputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ class UniformInputs {
std::string getLabel() const { return m_label; }

void setAssetComboList(const std::vector<std::string> &paths, const std::vector<ICE::AssetUID> &ids) {
m_asset_combo.setValues(paths);
m_assets_ids = ids;
auto it = std::find(ids.begin(), ids.end(), std::get<ICE::AssetUID>(m_value));
if (it != ids.end()) {
m_asset_combo.setSelected(std::distance(ids.begin(), it));
std::vector<std::string> path_with_none = {"<None>"};
path_with_none.insert(path_with_none.end(), paths.begin(), paths.end());
m_asset_combo.setValues(path_with_none);
m_assets_ids = {0};
m_assets_ids.insert(m_assets_ids.end(), ids.begin(), ids.end());
auto it = std::find(m_assets_ids.begin(), m_assets_ids.end(), std::get<ICE::AssetUID>(m_value));
if (it != m_assets_ids.end()) {
m_asset_combo.setSelected(std::distance(m_assets_ids.begin(), it));
}
m_asset_combo.onSelectionChanged(
[cb = this->m_callback, id_list = this->m_assets_ids](const std::string &, int index) { cb(id_list[index]); });
}

void setForceVectorNumeric(bool force_vector_numeric) { m_force_vector_numeric = force_vector_numeric; }

private:
void render(int &i) {
if (ImGui::InputInt(m_label.c_str(), &i)) {
Expand All @@ -55,24 +60,30 @@ class UniformInputs {
ImGui::PushID(m_label.c_str());
ImGui::PushItemWidth(60);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f);
renderLabel("X", 0x990000FF);
if (ImGui::InputFloat("##X", &v.x())) {
m_callback(v);
}
ImGui::SameLine();
renderLabel("Y", 0x9900FF00);
if (ImGui::InputFloat("##Y", &v.y())) {
m_callback(v);
}
ImGui::SameLine();
renderLabel("Z", 0x99FF0000);
if (ImGui::InputFloat("##Z", &v.z())) {
m_callback(v);
}
ImGui::SameLine();
renderLabel("W", 0x99FFFFFF);
if (ImGui::InputFloat("##W", &v.w())) {
m_callback(v);
if (m_force_vector_numeric) {
renderLabel("X", 0x990000FF);
if (ImGui::InputFloat("##X", &v.x())) {
m_callback(v);
}
ImGui::SameLine();
renderLabel("Y", 0x9900FF00);
if (ImGui::InputFloat("##Y", &v.y())) {
m_callback(v);
}
ImGui::SameLine();
renderLabel("Z", 0x99FF0000);
if (ImGui::InputFloat("##Z", &v.z())) {
m_callback(v);
}
ImGui::SameLine();
renderLabel("W", 0x99FFFFFF);
if (ImGui::InputFloat("##W", &v.w())) {
m_callback(v);
}
} else {
if (ImGui::ColorEdit4("##vector_picker", v.data(), ImGuiColorEditFlags_NoInputs)) {
m_callback(v);
}
}
ImGui::PopStyleVar();
ImGui::PopItemWidth();
Expand All @@ -83,29 +94,34 @@ class UniformInputs {
ImGui::PushID(m_label.c_str());
ImGui::PushItemWidth(60);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f);

ImGui::BeginGroup();
renderLabel("X", 0x990000FF);
if (ImGui::InputFloat("##X", &v.x())) {
m_callback(v);
if (m_force_vector_numeric) {
ImGui::BeginGroup();
renderLabel("X", 0x990000FF);
if (ImGui::InputFloat("##X", &v.x())) {
m_callback(v);
}
ImGui::EndGroup();
ImGui::SameLine();

ImGui::BeginGroup();
renderLabel("Y", 0x9900FF00);
if (ImGui::InputFloat("##Y", &v.y())) {
m_callback(v);
}
ImGui::EndGroup();
ImGui::SameLine();

ImGui::BeginGroup();
renderLabel("Z", 0x99FF0000);
if (ImGui::InputFloat("##Z", &v.z())) {
m_callback(v);
}
ImGui::EndGroup();
} else {
if (ImGui::ColorEdit3("##vector_picker", v.data(), ImGuiColorEditFlags_NoInputs)) {
m_callback(v);
}
}
ImGui::EndGroup();
ImGui::SameLine();

ImGui::BeginGroup();
renderLabel("Y", 0x9900FF00);
if (ImGui::InputFloat("##Y", &v.y())) {
m_callback(v);
}
ImGui::EndGroup();
ImGui::SameLine();

ImGui::BeginGroup();
renderLabel("Z", 0x99FF0000);
if (ImGui::InputFloat("##Z", &v.z())) {
m_callback(v);
}
ImGui::EndGroup();
ImGui::PopStyleVar();
ImGui::PopItemWidth();
ImGui::PopID();
Expand Down Expand Up @@ -161,4 +177,5 @@ class UniformInputs {
//Used when it's an asset input
ComboBox m_asset_combo;
std::vector<ICE::AssetUID> m_assets_ids;
bool m_force_vector_numeric = false;
};
Loading