Clean up code

This commit is contained in:
antopilo
2023-03-03 15:16:27 -05:00
parent bbafd0c4e0
commit 8195d6879b
10 changed files with 54 additions and 33 deletions

View File

@@ -121,7 +121,7 @@ vec3 scatter(vec3 o, vec3 d, float L, vec3 Lo) {
I_R = I_M = vec3(0.);
// Compute T(P -> O) and I_M and I_R
scatterIn(o, d, L, 32.);
scatterIn(o, d, L, 16.);
// mu = cos(alpha)
float mu = dot(d, SunDirection);
@@ -151,9 +151,9 @@ void main()
vec3 direction = normalize(camSpace.xyz);
vec3 D = direction;
vec3 col = vec3(0.0);
float L = escape(O, D, AtmosphereRadius);
col = scatter(O, D, L, col);
FragColor = vec4(col, 1.);
FragColor = vec4(sqrt(col), 1.);
}

View File

@@ -37,11 +37,11 @@ void main()
{
vec3 color = texture(u_Source, UV).rgb;
color = mix(color, color * u_Exposure, 0.1f);
//color = vec3(1.0) - exp(-color * u_Exposure);
// reinhard
color = color / (color + vec3(1.0));
//color = color / (color + vec3(1.0));
// gamma correct
color = pow(color, vec3(1.0 / u_Gamma));
//color = pow(color, vec3(1.0 / u_Gamma));
FragColor = vec4(color, 1.0);
}

View File

@@ -26,7 +26,7 @@ namespace Nuake
void Engine::Init()
{
Logger::Log("Engine initialization...");
Logger::Log("Nuake initializing");
PhysicsManager::Get()->Init();
Logger::Log("Physics initialized");
@@ -53,18 +53,22 @@ namespace Nuake
CurrentWindow->Update(timestep);
// Play mode update all the entities, Editor does not.
if (Engine::IsPlayMode) {
if (Engine::IsPlayMode)
{
m_FixedUpdateDifference += timestep;
// Fixed update
if (m_FixedUpdateDifference >= m_FixedUpdateRate) {
if (m_FixedUpdateDifference >= m_FixedUpdateRate)
{
CurrentWindow->FixedUpdate(m_FixedUpdateDifference);
m_FixedUpdateDifference = 0.0f;
}
}
else
{
GetCurrentScene()->EditorUpdate(timestep);
}
}
Input::Update();
@@ -74,19 +78,30 @@ namespace Nuake
{
// Dont trigger init if already in player mode.
if (IsPlayMode)
{
Logger::Log("Cannot enter play mode if is already in play mode.", WARNING);
return;
}
if (GetCurrentScene()->OnInit())
{
IsPlayMode = true;
}
else
{
Logger::Log("Cannot enter play mode. Scene OnInit failed", CRITICAL);
GetCurrentScene()->OnExit();
}
}
void Engine::ExitPlayMode()
{
// Dont trigger exit if already not in play mode.
if (IsPlayMode)
if (IsPlayMode)
{
Logger::Log("Cannot exit play mode. Scene must be in play mode.", WARNING);
GetCurrentScene()->OnExit();
}
Input::ShowMouse();
IsPlayMode = false;
@@ -135,7 +150,9 @@ namespace Nuake
CurrentProject = project;
if (!Engine::LoadScene(CurrentProject->DefaultScene))
{
return false;
}
FileSystem::SetRootDirectory(project->FullPath + "/../");
return true;

View File

@@ -159,13 +159,17 @@ namespace Nuake
for (auto& k : m_Keys)
{
if (!IsKeyDown(k.first))
{
k.second = false;
}
}
for (int i = 0; i < 5; i++)
{
if (!IsMouseButtonDown(i))
{
m_MouseButtons[i] = false;
}
}
}
}

View File

@@ -8,7 +8,7 @@ namespace Nuake
{
std::vector<LogEntry> Logger::m_Logs = std::vector<LogEntry>();
void Logger::Log(std::string log, LOG_TYPE type)
void Logger::Log(const std::string& log, LOG_TYPE type)
{
char buff[100];
time_t now = time(0);

View File

@@ -21,10 +21,10 @@ namespace Nuake
class Logger
{
public:
static void Log(std::string log, LOG_TYPE type = VERBOSE);
static void Log(const std::string& log, LOG_TYPE type = VERBOSE);
static std::vector<LogEntry> GetLogs();
private:
static const int MAX_LOG = 64;
static std::vector<LogEntry> m_Logs; // TODO: Use log struct.
static std::vector<LogEntry> m_Logs;
};
}

View File

@@ -74,7 +74,6 @@ namespace Nuake
Shader* shader = ShaderManager::GetShader("resources/Shaders/bloom.shader");
m_ThresholdFB->Bind();
{
m_ThresholdFB->Clear();

View File

@@ -21,13 +21,13 @@ namespace Nuake
TextShader = ShaderManager::GetShader("resources/Shaders/sdf_text.shader");
float quad_Vertices[] = {
// positions // texture Coords
// positions texture Coords
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f
1.0f, 1.0f, 1.0f, 1.0f, 1.0f
};
// setup plane VAO
@@ -40,7 +40,6 @@ namespace Nuake
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
}
void Renderer2D::BeginDraw(Vector2 size)

View File

@@ -93,6 +93,19 @@ namespace Nuake {
}
mToneMapBuffer->Unbind();
RenderCommand::Disable(RendererEnum::FACE_CULL);
Ref<Environment> environment = scene.GetEnvironment();
if (environment->CurrentSkyType == SkyType::ProceduralSky)
{
environment->ProceduralSkybox->Draw(mProjection, mView, environment->Exposure);
}
else if (environment->CurrentSkyType == SkyType::ClearColor)
{
RenderCommand::SetClearColor(environment->AmbientColor);
RenderCommand::Clear();
}
RenderCommand::Enable(RendererEnum::FACE_CULL);
//mSSR->Resize(framebuffer.GetSize());
//mSSR->Draw(mGBuffer.get(), framebuffer.GetTexture(), mView, mProjection, scene.GetCurrentCamera());
@@ -220,19 +233,6 @@ namespace Nuake {
{
RenderCommand::Disable(RendererEnum::DEPTH_TEST);
RenderCommand::Disable(RendererEnum::FACE_CULL);
Ref<Environment> environment = scene.GetEnvironment();
if (environment->CurrentSkyType == SkyType::ProceduralSky)
{
environment->ProceduralSkybox->Draw(mProjection, mView);
}
else if (environment->CurrentSkyType == SkyType::ClearColor)
{
RenderCommand::SetClearColor(environment->AmbientColor);
RenderCommand::Clear();
}
RenderCommand::Enable(RendererEnum::FACE_CULL);
Shader* shadingShader = ShaderManager::GetShader("resources/Shaders/deferred.shader");
shadingShader->Bind();
shadingShader->SetUniformMat4f("u_Projection", mProjection);

View File

@@ -20,9 +20,11 @@
namespace Nuake {
class Entity;
class SceneRenderer;
class Scene : public ISerializable
{
friend Entity;
private:
std::string Name;
bool has_changed = true;