Commit cb15e52b authored by Marc Schikowski's avatar Marc Schikowski
Browse files

Add materials to new gui features

parent a7c12e13
......@@ -6,6 +6,19 @@
namespace dino
{
std::vector<const char*> materialNames = {"No Texture",
"Checker Board (p)",
"Grid (p)",
"Squares (p)",
"Crosses (p)",
"Flower Noise (p)",
"Wood (p)",
"Voronoi (p)",
"Cube Map",
"Hatch",
"Stippling"};
int materialID = 0;
Editor::Editor(std::shared_ptr<Window> window, std::shared_ptr<dino::RendererDeferred> renderer)
: m_window(std::move(window))
, m_renderer(std::move(renderer))
......@@ -36,6 +49,8 @@ Editor::Editor(std::shared_ptr<Window> window, std::shared_ptr<dino::RendererDef
m_previewFramebuffer = std::make_unique<dino::FrameBuffer>();
m_previewTexture = std::make_shared<dino::Texture>(GL_TEXTURE_2D, GL_RGBA8, glm::ivec2{w, h});
m_previewFramebuffer->addColorAttachment(0, m_previewTexture);
prepareTextures();
}
void Editor::loadField(const std::filesystem::path path)
......@@ -72,6 +87,33 @@ void Editor::loadField(const std::filesystem::path path)
bool Editor::editorShown() const { return glfwGetWindowAttrib(*m_editorWindow, GLFW_VISIBLE); }
void Editor::prepareTextures()
{
/************************************** Load Images **************************************/
m_stipplingTexture = &textureResourceStippling.generate2DResource(
dino::RESOURCES_PATH / "textures/stippling/stippling.png");
m_hatchingTexture = &textureResourceHatching.generate3DResource(
dino::RESOURCES_PATH / "textures/hatching", ".png");
m_brickTexture = &textureResourceBrick.generateCubeResource(
dino::RESOURCES_PATH / "textures/png", ".png");
auto stipplingTextureMat = std::make_shared<dino::Material>(
glm::vec3(1.0f), 1.0f, 0.0f, 1.0f, dino::TextureType::STIPPLING_TEXTURE);
stipplingTextureMat->setTextureHandle(m_stipplingTexture->handle());
auto hatchingTextureMat = std::make_shared<dino::Material>(
glm::vec3(1.0f), 1.0f, 0.0f, 1.0f, dino::TextureType::HATCH_TEXTURE);
hatchingTextureMat->setTextureHandle(m_hatchingTexture->handle());
auto brickTextureMat = std::make_shared<dino::Material>(
glm::vec3(1.0f), 1.0f, 0.0f, 1.0f, dino::TextureType::BOX_TEXTURE);
brickTextureMat->setTextureHandle(m_brickTexture->handle());
}
void Editor::deleteField(uint32_t index)
{
const auto id = m_allFieldIds[index];
......@@ -144,7 +186,8 @@ void Editor::drawFieldsTab()
m_selectedFieldIndices.clear();
m_activeFieldIndex = std::nullopt;
--field_index;
glfwHideWindow(*m_editorWindow);;
glfwHideWindow(*m_editorWindow);
;
}
ImGui::SameLine();
const bool is_new_field = !field_id;
......@@ -246,63 +289,60 @@ void Editor::drawFieldsTab()
}
ImGui::PopStyleColor();
ImGui::EndHorizontal();
// auto mat = renderer->getMaterials()[pixelObjectId];
// if(ImGui::BeginCombo(" ", materialNames[mat->getTextureType()]))
//{
// for(int i = 0; i < materialNames.size(); i++)
// {
// if(ImGui::Selectable(materialNames[i], materialID == i))
// {
// materialID = i;
// Fill in behavior of material drop down menue
// TODO textures (loading etc.)
// /*switch(materialID)
// {
// case 8:
// mat->setTextureHandle(brickTexture.handle());
// break;
// case 9:
// mat->setTextureHandle(hatchingTexture.handle());
// break;
// case 10:
// mat->setTextureHandle(stipplingTexture.handle());
// break;
// }*/
// mat->setTextureType(static_cast<dino::TextureType>(materialID));
// }
// if(materialID == i)
// ImGui::SetItemDefaultFocus();
// }
// ImGui::EndCombo();
//}
// ImGui::Text(
// "%s",
// (std::string("Material ") + std::to_string(pixelObjectId))
// .c_str());
// glm::vec3 col = mat->getColor();
// std::vector<float> colv{col.x, col.y, col.z};
// if(ImGui::ColorEdit3("Mat-Color ", &colv[0]))
//{
// mat->setColor(glm::vec3(colv[0], colv[1], colv[2]));
//}
// float roughness = mat->getRoughness();
// if(ImGui::DragFloat(
// (std::string("Roughness ") + std::to_string(pixelObjectId)).c_str(),
// &roughness,
// 0.01f))
// mat->setRoughness(roughness);
// float metalness = mat->getMetalness();
// if(ImGui::DragFloat(
// (std::string("Metalness ") + std::to_string(pixelObjectId)).c_str(),
// &metalness,
// 0.01f))
// mat->setMetalness(metalness);
// float ior = mat->getIOR();
// if(ImGui::DragFloat((std::string("IOR ") +
// std::to_string(pixelObjectId)).c_str(),
// &ior,
// 0.01f))
// mat->setIOR(ior);
auto mat = m_renderer->getMaterials()[*m_allFieldIds[*m_activeFieldIndex]];
if(ImGui::BeginCombo(" ", materialNames[mat->getTextureType()]))
{
for(int i = 0; i < materialNames.size(); i++)
{
if(ImGui::Selectable(materialNames[i], materialID == i))
{
materialID = i;
switch(materialID)
{
case 8:
mat->setTextureHandle(m_brickTexture->handle());
break;
case 9:
mat->setTextureHandle(m_hatchingTexture->handle());
break;
case 10:
mat->setTextureHandle(m_stipplingTexture->handle());
break;
}
mat->setTextureType(static_cast<dino::TextureType>(materialID));
}
if(materialID == i)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::Text("%s",
(std::string("Material ") + std::to_string(*m_activeFieldIndex)).c_str());
glm::vec3 col = mat->getColor();
std::vector<float> colv{col.x, col.y, col.z};
if(ImGui::ColorEdit3("Mat-Color ", &colv[0]))
{
mat->setColor(glm::vec3(colv[0], colv[1], colv[2]));
}
float roughness = mat->getRoughness();
if(ImGui::DragFloat(
(std::string("Roughness ") + std::to_string(*m_activeFieldIndex)).c_str(),
&roughness,
0.01f))
mat->setRoughness(roughness);
float metalness = mat->getMetalness();
if(ImGui::DragFloat(
(std::string("Metalness ") + std::to_string(*m_activeFieldIndex)).c_str(),
&metalness,
0.01f))
mat->setMetalness(metalness);
float ior = mat->getIOR();
if(ImGui::DragFloat(
(std::string("IOR ") + std::to_string(*m_activeFieldIndex)).c_str(),
&ior,
0.01f))
mat->setIOR(ior);
}
}
}
......@@ -491,13 +531,13 @@ void Editor::drawBlueprint()
void Editor::processInputs()
{
if (m_ctrlC.pressed(*m_window))
{
m_copiedNodes = m_blueprints[*m_activeFieldIndex]->copyNodes();
}
if (m_ctrlV.pressed(*m_window))
{
//blueprints[pixelObjectId]->pasteNodes();
}
if(m_ctrlC.pressed(*m_window))
{
m_copiedNodes = m_blueprints[*m_activeFieldIndex]->copyNodes();
}
if(m_ctrlV.pressed(*m_window))
{
// blueprints[pixelObjectId]->pasteNodes();
}
}
} // namespace dino
\ No newline at end of file
......@@ -5,6 +5,7 @@
#include <optional>
#include <unordered_set>
#include <vector>
#include "dino\opengl\TextureResource.h"
namespace dino
{
......@@ -55,7 +56,7 @@ private:
void drawLightsTab();
void drawRenderingTab();
void drawPreview();
void processInputs();
void processInputs();
void deleteField(uint32_t index);
void saveField(uint32_t index, std::filesystem::path path);
......@@ -63,6 +64,15 @@ private:
bool editorShown() const;
void prepareTextures();
const dino::Texture* m_stipplingTexture;
const dino::Texture* m_hatchingTexture;
const dino::Texture* m_brickTexture;
dino::TextureResource m_textureResourceStippling;
dino::TextureResource m_textureResourceHatching;
dino::TextureResource m_textureResourceBrick;
float m_previewScale = 200.f;
float m_windowAspect = 9.f / 16.f;
std::unique_ptr<dino::FrameBuffer> m_previewFramebuffer;
......@@ -75,10 +85,10 @@ private:
std::vector<std::optional<uint32_t>> m_allFieldIds;
std::optional<uint32_t> m_activeFieldIndex = std::nullopt;
std::vector<std::unique_ptr<Blueprints>> m_blueprints;
KeyboardButton m_ctrlC = KeyboardButton(GLFW_KEY_C, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlV = KeyboardButton(GLFW_KEY_V, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlS = KeyboardButton(GLFW_KEY_S, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_shiftTab = KeyboardButton(GLFW_KEY_LEFT_SHIFT, GLFW_KEY_TAB);
std::vector<dino::Node> m_copiedNodes;
KeyboardButton m_ctrlC = KeyboardButton(GLFW_KEY_C, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlV = KeyboardButton(GLFW_KEY_V, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlS = KeyboardButton(GLFW_KEY_S, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_shiftTab = KeyboardButton(GLFW_KEY_LEFT_SHIFT, GLFW_KEY_TAB);
std::vector<dino::Node> m_copiedNodes;
};
} // namespace dino
\ No newline at end of file
......@@ -28,18 +28,8 @@ bool mainHasFocus = true;
int pixelObjectId = -1;
bool didSelect = false;
bool openBlueprint = false;
int materialID = 0;
std::vector<const char*> materialNames = {"No Texture",
"Checker Board (p)",
"Grid (p)",
"Squares (p)",
"Crosses (p)",
"Flower Noise (p)",
"Wood (p)",
"Voronoi (p)",
"Cube Map",
"Hatch",
"Stippling"};
void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{
......@@ -294,35 +284,7 @@ int main()
glm::vec3(0.6f, 1.f, 0.65f),
15.f));
/************************************** Load Images **************************************/
dino::SkyBox skyBox;
bool valid_skyBox =
skyBox.generateCubeMap(dino::RESOURCES_PATH / "textures/spruit_sunrise_8k.hdr/hdr/");
skyBox.getTexture().bind(5);
skyBox.setFolderPath((dino::RESOURCES_PATH / "textures/spruit_sunrise_8k.hdr/hdr/").string());
dino::TextureResource textureResourceStippling;
dino::TextureResource textureResourceHatching;
dino::TextureResource textureResourceBrick;
const dino::Texture& stipplingTexture = textureResourceStippling.generate2DResource(
dino::RESOURCES_PATH / "textures/stippling/stippling.png");
const dino::Texture& hatchingTexture = textureResourceHatching.generate3DResource(
dino::RESOURCES_PATH / "textures/hatching", ".png");
const dino::Texture& brickTexture = textureResourceBrick.generateCubeResource(
dino::RESOURCES_PATH / "textures/png", ".png");
auto stipplingTextureMat = std::make_shared<dino::Material>(
glm::vec3(1.0f), 1.0f, 0.0f, 1.0f, dino::TextureType::STIPPLING_TEXTURE);
stipplingTextureMat->setTextureHandle(stipplingTexture.handle());
auto hatchingTextureMat = std::make_shared<dino::Material>(
glm::vec3(1.0f), 1.0f, 0.0f, 1.0f, dino::TextureType::HATCH_TEXTURE);
hatchingTextureMat->setTextureHandle(hatchingTexture.handle());
auto brickTextureMat = std::make_shared<dino::Material>(
glm::vec3(1.0f), 1.0f, 0.0f, 1.0f, dino::TextureType::BOX_TEXTURE);
brickTextureMat->setTextureHandle(brickTexture.handle());
/********************************************************************************************/
GLFWwindow* wind = *editorWindow;
......@@ -429,10 +391,10 @@ int main()
{
auto filename = std::filesystem::path(
*(std::filesystem::directory_iterator(folderPath)));
if(skyBox.generateCubeMap(folderPath, filename.extension().string()))
if(renderer->getSkyBox().generateCubeMap(folderPath, filename.extension().string()))
{
skyBox.getTexture().bind(5);
skyBox.setFolderPath(folderPath);
renderer->getSkyBox().getTexture().bind(5);
renderer->getSkyBox().setFolderPath(folderPath);
}
else
{
......
......@@ -7,6 +7,7 @@ namespace dino
Renderer::Renderer(const Shader::ShaderSource& onTrace)
: m_onTrace(onTrace)
{
createSkybox();
}
void Renderer::add(const std::shared_ptr<Operator>& op, const std::shared_ptr<Material>& material)
......@@ -130,7 +131,7 @@ void Renderer::render(const glm::mat4& view, const glm::mat4& projection)
m_dataProxy.insert(m_dataProxy.end(),
(fieldIter->second)->data().begin(),
(fieldIter->second)->data().end());
++fieldIter;
++fieldIter;
}
if(m_infoBuffer.size() < static_cast<GLsizeiptr>(m_distanceFields.size()))
......@@ -180,12 +181,12 @@ void Renderer::render(const glm::mat4& view, const glm::mat4& projection)
shader << "float map(int in_id, vec3 in_position) {\n float distance = "
<< std::numeric_limits<float>::max() << ";\nswitch(in_id) {\n";
auto dfIter = m_distanceFields.begin();
auto dfIter = m_distanceFields.begin();
for(int i = 0; i < m_distanceFields.size(); ++i)
{
shader << "case " << i << ": { uint in_dataOffset = " << m_infos[i].dataOffset
<< "; return " << dfIter->second->mapFunction() << ";}\n ";
++dfIter;
++dfIter;
}
shader << "default: return 1.f/0.f;\n}\n}\n\n";
......@@ -360,8 +361,8 @@ int Renderer::fieldCount() const { return m_distanceFields.size(); }
std::shared_ptr<Function> Renderer::getFunctionByID(int id) const
{
if (m_distanceFields.count(id) == 0)
return nullptr;
if(m_distanceFields.count(id) == 0)
return nullptr;
return m_distanceFields.at(id)->target();
}
int Renderer::getFunctionId(const std::shared_ptr<Function>& func) const
......@@ -374,6 +375,18 @@ int Renderer::getFunctionId(const std::shared_ptr<Function>& func) const
->first;
}
void Renderer::createSkybox()
{
bool valid_skyBox =
m_skyBox.generateCubeMap(dino::RESOURCES_PATH / "textures/spruit_sunrise_8k.hdr/hdr/");
m_skyBox.getTexture().bind(5);
m_skyBox.setFolderPath((dino::RESOURCES_PATH / "textures/spruit_sunrise_8k.hdr/hdr/").string());
}
const dino::SkyBox& Renderer::getSkyBox() const { return m_skyBox; }
dino::SkyBox& Renderer::getSkyBox() { return m_skyBox; }
std::unordered_map<uint32_t, std::shared_ptr<Function>> Renderer::packFunctions() const
{
std::unordered_map<uint32_t, std::shared_ptr<Function>> result;
......
......@@ -8,6 +8,7 @@
#include "../opengl/Shader.h"
#include "../opengl/Texture.h"
#include "../opengl/VertexArray.h"
#include "dino\rendering\SkyBox.h"
#include "Light.h"
#include "Material.h"
......@@ -173,8 +174,9 @@ public:
virtual void removeLight(int lightIndex);
/**
* @brief Converts the shadow type of a light source at a given index to another shadow type
* (creates a new light object with the same lighting parameters but a different shadow technique)
* @brief Converts the shadow type of a light source at a given index to another shadow type
* (creates a new light object with the same lighting parameters but a different shadow
* technique)
*/
void convertLight(int lightIndex, ShadowType toType);
......@@ -201,7 +203,11 @@ public:
*/
int getFunctionId(const std::shared_ptr<Function>& func) const;
std::unordered_map<uint32_t, std::shared_ptr<Function>> packFunctions() const;
void createSkybox();
const dino::SkyBox& getSkyBox() const;
dino::SkyBox& getSkyBox();
std::unordered_map<uint32_t, std::shared_ptr<Function>> packFunctions() const;
protected:
Program m_program;
......@@ -214,6 +220,7 @@ protected:
private:
std::vector<float> m_dataProxy;
Buffer<float> m_data;
dino::SkyBox m_skyBox;
struct RenderInfo
{
......@@ -221,15 +228,15 @@ private:
alignas(4) uint32_t dataOffset = 0;
alignas(4) uint32_t dataSize = 0;
alignas(4) float normalPrec = 0.0001f;
alignas(4) uint32_t id = 0;
alignas(4) uint32_t id = 0;
};
std::vector<RenderInfo> m_infos;
Buffer<RenderInfo> m_infoBuffer;
std::vector<RenderInfo> m_infos;
Buffer<RenderInfo> m_infoBuffer;
std::unordered_map<uint32_t, std::shared_ptr<DistanceField>> m_distanceFields;
Buffer<CameraInfo> m_cameraInfo;
Buffer<Light> m_lightBuffer;
Buffer<ShadowMapLight::GpuSm> m_smBuffer;
Buffer<Material> m_materialBuffer;
Buffer<CameraInfo> m_cameraInfo;
Buffer<Light> m_lightBuffer;
Buffer<ShadowMapLight::GpuSm> m_smBuffer;
Buffer<Material> m_materialBuffer;
};
} // namespace dino
Subproject commit da1805f3c0542d6c584eddf627b2ebc34d2ce64d
Subproject commit ef594607829ad6ed2bd462a0ddcbb0ee698b3f4f
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment