Skip to content

Commit 6d4632d

Browse files
committed
Was done long time ago.
1 parent 486d780 commit 6d4632d

File tree

7 files changed

+90
-23
lines changed

7 files changed

+90
-23
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ find_package(spdlog CONFIG REQUIRED)
99
find_package(imgui CONFIG REQUIRED)
1010
find_package(imguizmo CONFIG REQUIRED)
1111
find_package(glm CONFIG REQUIRED)
12-
find_package(SDL2 CONFIG REQUIRED)
13-
find_package(sdl2-image CONFIG REQUIRED)
12+
# find_package(SDL2 CONFIG REQUIRED)
13+
# find_package(sdl2-image CONFIG REQUIRED)
1414

1515
find_path(TINYGLTF_INCLUDE_DIRS "tiny_gltf.h")
1616
include_directories(${TINYGLTF_INCLUDE_DIRS})

sources/app/CEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void CEngine::initializeVideo()
161161

162162
mMainWindow->setSize(mSettings.mWindowSize);
163163
mMainWindow->setTitle("wtf.e");
164-
mMainWindow->setFlags(SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
164+
mMainWindow->setFlags(SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_ALLOW_HIGHDPI);
165165

166166
std::map<SDL_GLattr, int> attributes = {
167167
{SDL_GL_CONTEXT_MAJOR_VERSION, 4},

sources/app/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ target_link_libraries(foss.app
3030
imgui::imgui
3131
imguizmo::imguizmo
3232

33-
X11 Xrandr Xi Xxf86vm Xext GL
34-
SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static SDL2::SDL2_image
33+
GL SDL2 SDL2_image
34+
# X11 Xrandr Xi Xxf86vm Xext GL
35+
# SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static SDL2::SDL2_image
3536
fmt::fmt
3637
spdlog::spdlog spdlog::spdlog_header_only
3738
)

sources/app/entities/windows/CEntityManagerWindow.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void CEntityManagerWindow::draw()
228228
auto light = component.getLight();
229229

230230
ImGui::InputFloat3("Position", &light->mPosition[0]);
231-
// ImGui::ColorEdit3("Color", &light->mColor[0], ImGuiColorEditFlags_Float);
231+
ImGui::ColorEdit3("Color", &light->mColor[0], ImGuiColorEditFlags_Float);
232232
ImGui::SliderFloat("Strength", &light->mStrength, 0.0f, 65536.0f, "%.4f", 1.f);
233233
}
234234
}
@@ -262,6 +262,26 @@ void CEntityManagerWindow::draw()
262262
updated |= ImGui::SliderFloat3("Noise center", &noise.center[0], 0.0f, 5.0f, "%.4f", 1.f);
263263
}
264264

265+
auto title2 = fmt::format("Noise Settings 2 ({})", static_cast<size_t>(entity));
266+
if (ImGui::CollapsingHeader(title2.c_str()))
267+
{
268+
auto& noise = settings.mNoiseSettings2;
269+
270+
updated |= ImGui::SliderFloat("Strength", &noise.strength, 0.0f, 1.0f, "%.4f");
271+
updated |= ImGui::SliderFloat("Roughness", &noise.roughness, 0.0f, 1.0f, "%.4f");
272+
updated |= ImGui::SliderFloat3("Noise center", &noise.center[0], 0.0f, 5.0f, "%.4f", 1.f);
273+
}
274+
275+
auto title3 = fmt::format("Noise Settings 3 ({})", static_cast<size_t>(entity));
276+
if (ImGui::CollapsingHeader(title3.c_str()))
277+
{
278+
auto& noise = settings.mNoiseSettings3;
279+
280+
updated |= ImGui::SliderFloat("Strength", &noise.strength, 0.0f, 100.0f, "%.4f");
281+
updated |= ImGui::SliderFloat("Roughness", &noise.roughness, 0.0f, 1.0f, "%.4f");
282+
updated |= ImGui::SliderFloat3("Noise center", &noise.center[0], 0.0f, 5.0f, "%.4f", 1.f);
283+
}
284+
265285
if (updated)
266286
{
267287
component.setSettings(settings);
@@ -321,11 +341,11 @@ void CEntityManagerWindow::draw()
321341
material->setEmissiveFactor(emissive);
322342
}
323343

324-
// auto baseColor = material->getBaseColorFactor();
325-
// if (ImGui::ColorEdit4("Base color", &(baseColor[0]), ImGuiColorEditFlags_Float))
326-
// {
327-
// material->setBaseColorFactor(baseColor);
328-
// }
344+
auto baseColor = material->getBaseColorFactor();
345+
if (ImGui::ColorEdit4("Base color", &(baseColor[0]), ImGuiColorEditFlags_Float))
346+
{
347+
material->setBaseColorFactor(baseColor);
348+
}
329349

330350
if (auto tex = material->getBaseColorTexture())
331351
{
@@ -334,7 +354,7 @@ void CEntityManagerWindow::draw()
334354

335355
if (auto tex = material->getNormalTexture())
336356
{
337-
ImGui::Image(reinterpret_cast<void*>(tex->id()), {64, 64}, ImVec2(0, 1), ImVec2(1, 0));
357+
ImGui::Image(reinterpret_cast<void*>(tex->id()), {256, 256}, ImVec2(0, 1), ImVec2(1, 0));
338358
}
339359

340360
if (auto tex = material->getMetallicTexture())

sources/app/resources/CTextureManager.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ std::tuple<std::shared_ptr<SDL_Surface>, bool> get_image(const std::filesystem::
1919
} // namespace
2020

2121
template <>
22-
void CTextureManager::getTexture(const std::filesystem::path path,
23-
std::shared_ptr<CTexture2D> texture)
22+
void CTextureManager::getTexture(const std::filesystem::path path, std::shared_ptr<CTexture2D> texture)
2423
{
2524
const auto [surface, is_alpha] = get_image(path);
2625
const auto size = glm::ivec2(surface->w, surface->h);
@@ -38,17 +37,15 @@ void CTextureManager::getTexture(const std::filesystem::path path,
3837

3938
gl::tex_parameteri(params);
4039

41-
glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, format, GL_UNSIGNED_BYTE,
42-
surface->pixels);
40+
glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, format, GL_UNSIGNED_BYTE, surface->pixels);
4341

4442
glGenerateMipmap(GL_TEXTURE_2D);
4543

4644
texture->unbind();
4745
}
4846

4947
template <>
50-
void CTextureManager::getTexture(const std::filesystem::path path,
51-
std::shared_ptr<CTextureCubeMap> texture)
48+
void CTextureManager::getTexture(const std::filesystem::path path, std::shared_ptr<CTextureCubeMap> texture)
5249
{
5350
texture->bind();
5451

@@ -74,8 +71,8 @@ void CTextureManager::getTexture(const std::filesystem::path path,
7471
const auto [surface, is_alpha] = get_image(file);
7572
const GLenum format = is_alpha ? GL_RGBA : GL_RGB;
7673

77-
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GLint(format), surface->w, surface->h,
78-
0, format, GL_UNSIGNED_BYTE, surface->pixels);
74+
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GLint(format), surface->w, surface->h, 0, format,
75+
GL_UNSIGNED_BYTE, surface->pixels);
7976
}
8077

8178
texture->unbind();

sources/app/scene/CSpaceBodyGenerator.cpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,42 @@
1010
#include "app/scene/Model.hpp"
1111
#include "app/textures/CTexture2D.hpp"
1212

13+
namespace
14+
{
15+
16+
void tex(ITexture* texture, Noise& noise, TNoiseSettings& cfg, const size_t size, const glm::vec3 color)
17+
{
18+
texture->bind();
19+
// set texture wrap parameters
20+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
21+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
22+
// set texture filter parameters
23+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
24+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
25+
26+
std::vector<glm::tvec3<unsigned char>> data;
27+
data.resize(size * size);
28+
29+
for (int y = 0; y < size; ++y)
30+
{
31+
for (int x = 0; x < size; ++x)
32+
{
33+
int i = x + y * size;
34+
auto f = (noise.evaluate(glm::vec3((float)x, (float)y, 0.f) * cfg.roughness + cfg.center) * cfg.strength);
35+
auto c = (color * 255.0f) + f;
36+
data[i] = glm::tvec3<unsigned char>(c);
37+
}
38+
}
39+
40+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, &data[0]);
41+
glGenerateMipmap(GL_TEXTURE_2D);
42+
43+
texture->unbind();
44+
}
45+
46+
} // namespace
47+
48+
1349
CSpaceBodyGenerator::CSpaceBodyGenerator(IProceduralSettings& settings)
1450
: mSettings(static_cast<TSpaceBodySettings&>(settings))
1551
, mMeshes()
@@ -48,8 +84,9 @@ void CSpaceBodyGenerator::generate2(std::function<glm::vec3(glm::vec3)> shapeFil
4884
auto roughness = std::make_shared<CTexture2D>();
4985
auto ao = std::make_shared<CTexture2D>();
5086

51-
CTextureManager::setTexture(albedo.get(), 128, glm::vec3(0.1f, 0.1f, 0.1f));
52-
CTextureManager::setTexture(normal.get(), 128, glm::vec3(0.5f, 0.5f, 1.f));
87+
// CTextureManager::setTexture(albedo.get(), 128, glm::vec3(0.1f, 0.1f, 0.1f));
88+
tex(albedo.get(), mNoise, mSettings.mNoiseSettings3, 128, glm::vec3(0.1f, 0.1f, 0.1f));
89+
tex(normal.get(), mNoise, mSettings.mNoiseSettings2, 128, glm::vec3(0.5f, 0.5f, 1.f));
5390
CTextureManager::setTexture(metallic.get(), 128, glm::vec3(0.f, 1.f, 1.f));
5491
CTextureManager::setTexture(roughness.get(), 128, glm::vec3(0.f, 1.f, 1.f));
5592
CTextureManager::setTexture(ao.get(), 128, glm::vec3(1.f, 1.f, 1.f));
@@ -108,12 +145,22 @@ void CSpaceBodyGenerator::generate()
108145
{
109146
std::function<glm::vec3(glm::vec3)> filter = [this](glm::vec3 point) -> glm::vec3 {
110147
auto& settings = mSettings.mNoiseSettings;
148+
auto& settings2 = mSettings.mNoiseSettings2;
149+
auto& settings3 = mSettings.mNoiseSettings3;
111150

112151
auto noiseValue = mNoise.evaluate(point * settings.roughness + settings.center);
113152
noiseValue = (noiseValue + 1.f) * 0.5f;
114153
noiseValue = noiseValue * settings.strength;
115154

116-
return point * glm::vec3(mSettings.mRadius) * (1 + noiseValue);
155+
auto noiseValue2 = mNoise.evaluate(point * settings2.roughness + settings2.center);
156+
noiseValue2 = (noiseValue2 + 1.f) * 0.5f;
157+
noiseValue2 = noiseValue2 * settings2.strength;
158+
159+
auto noiseValue3 = mNoise.evaluate(point * settings3.roughness + settings3.center);
160+
noiseValue3 = (noiseValue3 + 1.f) * 0.5f;
161+
noiseValue3 = noiseValue3 * settings2.strength;
162+
163+
return point * glm::vec3(mSettings.mRadius) * (1 + noiseValue + noiseValue2 + noiseValue3);
117164
};
118165

119166
generate2(filter);

sources/app/scene/CSpaceBodyGenerator.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class TSpaceBodySettings : public IProceduralSettings
2828
int mResolution;
2929

3030
TNoiseSettings mNoiseSettings;
31+
TNoiseSettings mNoiseSettings2;
32+
TNoiseSettings mNoiseSettings3;
3133
};
3234

3335

0 commit comments

Comments
 (0)