Commit a3a5fb02 authored by Lukas Tietze's avatar Lukas Tietze

Kleinkram :D

parent 85918bcd
......@@ -149,6 +149,48 @@
"reveal": "always"
},
"problemMatcher": []
},
//----------------------------------------------------------------------------------------------------
// Texterzeugung
//----------------------------------------------------------------------------------------------------
{
"label": "tex - Forschungspraktikum",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "doc/common/build.py",
"args": [
"doc/Forschungspraktikum"
],
"problemMatcher": []
},
{
"label": "tex - Themenvorschlag",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "doc/common/build.py",
"args": [
"doc/Themenvorschlag"
],
"problemMatcher": []
},
{
"label": "tex - Masterarbeit",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "doc/common/build.py",
"args": [
"doc/Masterarbeit"
],
"problemMatcher": []
}
]
}
\ No newline at end of file
......@@ -116,6 +116,7 @@ target_compile_features(Lib
add_executable(App
src/App/src/main.cpp
src/App/src/VkrtApp.cpp
src/App/src/Animation.cpp
)
target_include_directories(App
......
\section{Grundlagen der Aufgabe}
Die Ausarbeitung soll sich sprachlich auf einem Niveau befinden, das f眉r Leser mit grundlegenden Kenntnissen
眉ber Computergrafik, euklidische Geometrie und Programmierung in modernem C++, verst盲ndlich ist. Fachbegriffe
sollen dennoch kurz wiederholt werden. Oft haben Fachbegriffe keine deutsche Entsprechung oder die deutsche
眉ber Computergrafik, Geometrie im dreidimensionalen Raum und Programmierung in modernem C++, verst盲ndlich ist.
Fachbegriffe sollen dennoch kurz wiederholt werden. Oft haben Fachbegriffe keine deutsche Entsprechung oder die deutsche
Entsprechung ist zu unhandlich und zu unbekannt, sodass auf englische Begriffe im Flie脽text nicht verzichtet
werden kann. Sooft m枚glich sollen Prinzipien nicht nur beschrieben, sondern grafisch dargestellt werden.
#pragma once
#include "Defs.hpp"
namespace app
{
struct Animation
{
bool animate;
float progress;
float progressMax;
float progressSpeed;
void Update(lib::time_diff_t delta);
};
} // namespace app
\ No newline at end of file
#pragma once
#include "Core/App.hpp"
#include "Animation.hpp"
#include "glm/glm.hpp"
namespace app
{
constexpr glm::vec3 Light0BasePos{0, 3, 3};
class VkrtApp : public lib::IAppAdapter
{
private:
struct
{
bool animate = true;
float currentHDeg = 0;
float changeSpeed = 5.f;
} background;
glm::vec3 light0BasePos{0, 3, 3};
struct
{
bool animate = true;
float y = 0.f;
float yMax = 2.f;
float yBase = 2.f;
float speed = 5.f;
} light;
Animation lightAnimation;
Animation backgroundAnimation;
struct
{
......@@ -35,16 +23,18 @@ namespace app
void HandleCameraMovement(lib::App &app, lib::time_diff_t delta);
void HandleOtherKeys(lib::App &app);
void AnimateBackground(lib::App &app, lib::time_diff_t delta);
void UpdateBackground(lib::App &app, lib::time_diff_t delta);
void AnimateLight(lib::App &app, lib::time_diff_t delta);
void UpdateLight(lib::App &app, lib::time_diff_t delta);
void RenderUi(lib::App &app);
public:
VkrtApp();
void Update(lib::App &app, lib::time_diff_t delta) override;
void AfterInit(lib::App &app) override;
void BeforeClose(lib::App &app) override;
void AfterClose(lib::App &app) override;
lib::AppCreateInfo CreateInitInfo() const;
};
} // namespace app
#include "Animation.hpp"
void app::Animation::Update(lib::time_diff_t delta)
{
if (this->animate)
{
this->progress += this->progressSpeed * delta.count();
while (this->progress > this->progressMax)
{
this->progress -= this->progressMax;
}
}
}
\ No newline at end of file
......@@ -8,6 +8,19 @@
#include "glm/glm.hpp"
#include "glm/gtx/rotate_vector.hpp"
app::VkrtApp::VkrtApp()
{
this->backgroundAnimation.animate = true;
this->backgroundAnimation.progress = 0.f;
this->backgroundAnimation.progressMax = 360.f;
this->backgroundAnimation.progressSpeed = 1.f;
this->lightAnimation.animate = false;
this->lightAnimation.progress = 0.f;
this->lightAnimation.progressMax = 4.f;
this->lightAnimation.progressSpeed = 1.f;
}
void app::VkrtApp::HandleCameraMovement(lib::App &app, lib::time_diff_t delta)
{
if (app.IsMouseCaptured())
......@@ -91,27 +104,15 @@ void app::VkrtApp::HandleOtherKeys(lib::App &app)
app.ToogleUi();
}
}
void app::VkrtApp::AnimateBackground(lib::App &app, lib::time_diff_t delta)
{
this->background.currentHDeg += delta.count() * this->background.changeSpeed;
while (this->background.currentHDeg >= 360.f)
{
this->background.currentHDeg -= 360.f;
}
}
void app::VkrtApp::UpdateBackground(lib::App &app, lib::time_diff_t delta)
{
if (this->background.animate)
{
this->AnimateBackground(app, delta);
}
this->backgroundAnimation.Update(delta);
auto &col = app.GetContext().GetClearColor();
auto hi = static_cast<uint32_t>(this->background.currentHDeg / 60.f);
auto f = (this->background.currentHDeg / 60.f - hi);
auto hi = static_cast<uint32_t>(this->backgroundAnimation.progress / 60.f);
auto f = (this->backgroundAnimation.progress / 60.f - hi);
switch (hi)
{
......@@ -137,28 +138,15 @@ void app::VkrtApp::UpdateBackground(lib::App &app, lib::time_diff_t delta)
}
}
void app::VkrtApp::AnimateLight(lib::App &app, lib::time_diff_t delta)
{
this->light.y += delta.count() * this->light.speed;
while (this->light.y > this->light.yMax)
{
this->light.y -= this->light.yMax;
}
}
void app::VkrtApp::UpdateLight(lib::App &app, lib::time_diff_t delta)
{
if (this->light.animate)
{
this->AnimateLight(app, delta);
}
this->lightAnimation.Update(delta);
auto &light = app.GetContext().GetLightSources()[0];
light.SetPosition({0,
this->light.yBase + std::abs(this->light.y - this->light.yMax / 2.f),
0});
light.SetPosition({this->light0BasePos.x,
this->light0BasePos.y + std::abs(this->lightAnimation.progress - this->lightAnimation.progressMax / 2.f),
this->light0BasePos.z});
}
void app::VkrtApp::RenderUi(lib::App &app)
......@@ -171,47 +159,58 @@ void app::VkrtApp::RenderUi(lib::App &app)
ImGui::SetWindowSize({app.GetWindowWidth() / 2.f, app.GetWindowHeight() / 2.f}, ImGuiCond_FirstUseEver);
{
static glm::vec3 lightPos;
lightPos = app.GetContext().GetLightSources()[0].GetPosition();
auto &light = app.GetContext().GetLightSources()[0];
auto pos = light.GetPosition();
auto color = light.GetColor();
static float intensityBuf = glm::length(color);
color = glm::normalize(color);
static float lightColorBuf[3]{color.r, color.g, color.b};
static float lightPosBuf[3]{pos.x, pos.y, pos.z};
ImGui::BeginGroup();
ImGui::Text("Lichtquelle:");
ImGui::Checkbox("Animieren##L", &this->light.animate);
ImGui::SliderFloat("Geschwindigkeit##L", &this->light.speed, 0, 20.f);
ImGui::SliderFloat("Basis-Y##L", &this->light.yBase, 0.f, 4.f);
ImGui::SliderFloat("Y-Reichweite##L", &this->light.yMax, 0.f, 4.f);
ImGui::InputFloat("X", &lightPos.x, 0.5f, 4.f, 1);
ImGui::InputFloat("Y", &lightPos.y, 0.5f, 4.f, 1);
ImGui::InputFloat("Z", &lightPos.z, 0.5f, 4.f, 1);
ImGui::Separator();
ImGui::EndGroup();
app.GetContext().GetLightSources()[0].SetPosition(lightPos);
}
if (ImGui::InputFloat3("Position", lightPosBuf, "%.1f"))
{
light.SetPosition({lightPosBuf[0],
lightPosBuf[1],
lightPosBuf[2]});
}
if (ImGui::ColorPicker3("Color", lightColorBuf) ||
ImGui::InputFloat("Intensity", &intensityBuf, 0.1f, 0.5f, "%.1f"))
{
light.SetColor(glm::vec3{lightColorBuf[0],
lightColorBuf[1],
lightColorBuf[2]} *
intensityBuf);
}
ImGui::Separator();
ImGui::BeginGroup();
ImGui::Text("Hintergrund:");
ImGui::Checkbox("Animieren##H", &this->background.animate);
ImGui::SliderFloat("Farbgrad##H", &this->background.currentHDeg, 0.f, 360.f);
ImGui::SliderFloat("Geschwindigkeit##H", &this->background.changeSpeed, 1.f, 10.f);
ImGui::EndGroup();
ImGui::EndGroup();
}
ImGui::Separator();
{
static glm::vec3 camPos;
camPos = app.GetContext().GetCameraModel().GetPosition();
static float camPosBuf[3];
const auto pos = app.GetContext().GetCameraModel().GetPosition();
camPosBuf[0] = pos.x;
camPosBuf[1] = pos.y;
camPosBuf[2] = pos.z;
ImGui::BeginGroup();
ImGui::Text("Kamera:");
ImGui::InputFloat("X", &camPos.x, 0.5f, 4.f, 1);
ImGui::InputFloat("Y", &camPos.y, 0.5f, 4.f, 1);
ImGui::InputFloat("Z", &camPos.z, 0.5f, 4.f, 1);
if (ImGui::InputFloat3("pos", camPosBuf, "%.1f"))
{
app.GetContext().GetCameraModel().SetPosition({camPosBuf[0],
camPosBuf[1],
camPosBuf[2]});
}
ImGui::EndGroup();
app.GetContext().GetCameraModel().SetPosition(camPos);
}
ImGui::End();
......@@ -240,3 +239,47 @@ void app::VkrtApp::AfterInit(lib::App &app) {}
void app::VkrtApp::BeforeClose(lib::App &app) {}
void app::VkrtApp::AfterClose(lib::App &app) {}
lib::AppCreateInfo app::VkrtApp::CreateInitInfo() const
{
lib::AppCreateInfo info;
info.shaderTable.raygenShader.type = lib::ShaderType::Raygen_GLSL;
info.shaderTable.raygenShader.path = "./assets/shaders/raygen.rgen";
info.shaderTable.raygenShader.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo miss;
miss.type = lib::ShaderType::Miss_GLSL;
miss.path = "./assets/shaders/miss.rmiss";
miss.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo closestHit;
closestHit.type = lib::ShaderType::ClosestHit_GLSL;
closestHit.path = "./assets/shaders/closestHitDefault.rchit";
closestHit.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo shadowMiss;
shadowMiss.type = lib::ShaderType::Miss_GLSL;
shadowMiss.path = "./assets/shaders/shadow.rmiss";
shadowMiss.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
info.shaderTable.closestHitShaders.push_back(closestHit);
info.shaderTable.missShaders.push_back(miss);
info.shaderTable.missShaders.push_back(shadowMiss);
info.validationInfo.useValidationLayers = true;
info.validationInfo.requireValidationLayers = false;
info.loggingInfo.debugEnabled = true;
info.loggingInfo.infosEnabled = true;
info.modelInfo.path = "assets/models/cornell-box.obj";
info.modelInfo.clearColor = glm::vec3(0.f, 0.f, 0.f);
info.modelInfo.lightSources[0].SetType(lib::LightSourceType::Point);
info.modelInfo.lightSources[0].SetAmbientFactor(0.15f);
info.modelInfo.lightSources[0].SetColor(glm::vec3(1.f, 1.f, 1.f) * 4.f);
info.modelInfo.lightSources[0].SetEnabled(true);
info.modelInfo.lightSources[0].SetPosition(this->light0BasePos);
return info;
}
\ No newline at end of file
......@@ -4,47 +4,8 @@
int main()
{
lib::AppCreateInfo info;
info.shaderTable.raygenShader.type = lib::ShaderType::Raygen_GLSL;
info.shaderTable.raygenShader.path = "./assets/shaders/raygen.rgen";
info.shaderTable.raygenShader.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo miss;
miss.type = lib::ShaderType::Miss_GLSL;
miss.path = "./assets/shaders/miss.rmiss";
miss.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo closestHit;
closestHit.type = lib::ShaderType::ClosestHit_GLSL;
closestHit.path = "./assets/shaders/closestHitDefault.rchit";
closestHit.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo shadowMiss;
shadowMiss.type = lib::ShaderType::Miss_GLSL;
shadowMiss.path = "./assets/shaders/shadow.rmiss";
shadowMiss.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
info.shaderTable.closestHitShaders.push_back(closestHit);
info.shaderTable.missShaders.push_back(miss);
info.shaderTable.missShaders.push_back(shadowMiss);
info.validationInfo.useValidationLayers = true;
info.validationInfo.requireValidationLayers = false;
info.loggingInfo.debugEnabled = true;
info.loggingInfo.infosEnabled = true;
info.modelInfo.path = "assets/models/cornell-box.obj";
info.modelInfo.clearColor = glm::vec3(0.f, 0.f, 0.f);
info.modelInfo.lightSources[0].SetType(lib::LightSourceType::Point);
info.modelInfo.lightSources[0].SetAmbientFactor(0.15f);
info.modelInfo.lightSources[0].SetColor(glm::vec3(1.f, 1.f, 1.f) * 4.f);
info.modelInfo.lightSources[0].SetEnabled(true);
info.modelInfo.lightSources[0].SetPosition(app::Light0BasePos);
app::VkrtApp handler;
lib::App app(info);
lib::App app(handler.CreateInitInfo());
if (app.IsOk())
{
......
......@@ -95,9 +95,9 @@ glm::vec3 lib::LightSource::GetColor() const
void lib::LightSource::SetColor(const glm::vec3 &value)
{
this->colorRGB_ambientFactor.r = value.r;
this->colorRGB_ambientFactor.g = value.g;
this->colorRGB_ambientFactor.b = value.b;
this->colorRGB_ambientFactor.r = std::isnan(value.r) ? 0.f : value.r;
this->colorRGB_ambientFactor.g = std::isnan(value.g) ? 0.f : value.g;
this->colorRGB_ambientFactor.b = std::isnan(value.b) ? 0.f : value.b;
}
float lib::LightSource::GetAmbientFactor() const
......
Markdown is supported
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