refactoring scene rendering

This commit is contained in:
antopilo
2021-09-20 06:49:45 -04:00
parent 519d9165e1
commit 4d1e134eaa
44 changed files with 604 additions and 826 deletions

View File

@@ -55,8 +55,8 @@ int main()
// Register Gizmo textures
Ref<Nuake::Texture> lightTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Light.png");
Ref<Nuake::Texture> camTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Camera.png");
Ref<Nuake::Shader> GuizmoShader = Nuake::ShaderManager::GetShader("resources/Shaders/gizmo.shader");
Ref<Nuake::Shader> ditherShader = Nuake::ShaderManager::GetShader("resources/Shaders/dither.shader");
Nuake::Shader* GuizmoShader = Nuake::ShaderManager::GetShader("resources/Shaders/gizmo.shader");
Nuake::Shader* ditherShader = Nuake::ShaderManager::GetShader("resources/Shaders/dither.shader");
//Nuake::NewEditor newEditor = Nuake::NewEditor();

View File

@@ -107,7 +107,7 @@ class Vector3 {
}
Normalize() {
var length = this.Sqrt()
var length = this.Length()
var x = _x / length
var y = _y / length
var z = _z / length

View File

@@ -136,8 +136,8 @@ vec3 scatter(vec3 o, vec3 d, float L, vec3 Lo) {
return vec3(1.0);
}
uniform mat4 InvProjection;
uniform mat4 InvView;
uniform mat4 Projection;
uniform mat4 View;
void main()
{
// Might add camera position in here.
@@ -145,7 +145,7 @@ void main()
vec2 NDC = UV * 2.0 - 1;
vec4 camSpace = inverse(InvProjection * InvView) * vec4(vec3(NDC, 1.0), 1.0);
vec4 camSpace = inverse(Projection * View) * vec4(vec3(NDC, 1.0), 1.0);
vec3 direction = normalize(camSpace.xyz);
vec3 D = direction;
@@ -153,9 +153,5 @@ void main()
vec3 col = vec3(1.0);
float L = escape(O, D, AtmosphereRadius);
col = scatter(O, D, L, col);
col = col / (col + vec3(1.0));
// gamma correct
col = pow(col, vec3(1.0 / u_Exposure));
FragColor = vec4(col, 1.);
}

View File

@@ -151,9 +151,9 @@ void main()
vec3 color = outputColor.rgb;
color = acesOperator(color);
//color = acesOperator(color);
color = color / (color + vec3(1.0));
color = color / (color + vec3(2.0));
color = vec3(1.0) - exp(-color * 1.0);
color = pow(color, vec3(1.0 / 2.2));

View File

@@ -0,0 +1,27 @@
#shader vertex
#version 460 core
layout(location = 0) in vec3 VertexPosition;
layout(location = 1) in vec2 UVPosition;
out flat vec2 UV;
void main()
{
UV = UVPosition;
gl_Position = vec4(VertexPosition, 1.0f);
}
#shader fragment
#version 460 core
uniform sampler2D u_Source;
in vec2 UV;
out vec4 FragColor;
void main()
{
FragColor = texture(u_Source, UV);
}

View File

@@ -302,16 +302,7 @@ void main()
vec3 kD = 1.0 - kS;
kD *= 1.0 - metallic;
vec3 irradiance = mix(texture(u_IrradianceMap, N).rgb, vec3(0.1f), 0.9f);
vec3 diffuse = irradiance * albedo;
// sample both the pre-filter map and the BRDF lut and combine them together as per the Split-Sum approximation to get the IBL specular part.
const float MAX_REFLECTION_LOD = 4.0;
vec3 prefilteredColor = textureLod(u_PrefilterMap, R, roughness * MAX_REFLECTION_LOD).rgb;
vec2 brdf = texture(u_BrdfLUT, vec2(max(dot(N, V), 0.0), roughness)).rg;
vec3 specular = prefilteredColor * (F * brdf.x + brdf.y);
vec3 ambient = (kD * diffuse + specular) * ao;
vec3 ambient = (kD * albedo) * ao;
vec3 color = ambient + Lo;
color += fog;

View File

@@ -22,6 +22,7 @@
#include "Dependencies/GLEW/include/GL/glew.h"
#include "src/Scene/Scene.h"
#include "src/Scene/Components/Components.h"
#include "src/Scene/Components/BoxCollider.h"
#include "src/Scene/Components/LuaScriptComponent.h"
@@ -70,12 +71,9 @@ namespace Nuake {
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
Vector2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
Ref<FrameBuffer> framebuffer = Engine::GetCurrentWindow()->GetDeferredBuffer();
Ref<FrameBuffer> framebuffer = Engine::GetCurrentWindow()->GetFrameBuffer();
if (framebuffer->GetSize() != viewportPanelSize)
{
Engine::GetCurrentWindow()->GetGBuffer()->QueueResize(viewportPanelSize);
framebuffer->QueueResize(viewportPanelSize);
}
Ref<Texture> texture = framebuffer->GetTexture();
ImGui::Image((void*)texture->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0));
@@ -341,7 +339,7 @@ namespace Nuake {
if (ImGui::Begin("Environnement"))
{
Ref<Environment> env = Engine::GetCurrentScene()->GetEnvironment();
const Ref<Environment> env = Engine::GetCurrentScene()->GetEnvironment();
if (ImGui::CollapsingHeader("Procedural Sky", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::DragFloat("Sun Intensity", &env->ProceduralSkybox->SunIntensity, 0.1f, 0.0f);
@@ -356,16 +354,23 @@ namespace Nuake {
}
if (ImGui::CollapsingHeader("Bloom", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::DragFloat("Threshold", &env->BloomThreshold, 0.01f, 0.0f, 300.0f);
ImGui::DragFloat("Blur", &env->BloomBlurAmount, 0.01f, 0.0f, 300.0f);
float threshold = env->mBloom->GetThreshold();
ImGui::DragFloat("Threshold", &threshold, 0.01f, 0.0f, 500.0f);
env->mBloom->SetThreshold(threshold);
int iteration = env->mBloom->GetIteration();
ImGui::DragInt("Iteration", &iteration, 1.0f, 0, 8);
env->mBloom->SetIteration(iteration);
}
if (ImGui::CollapsingHeader("Fog", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::DragFloat("Volumetric Scattering", &env->VolumetricFog, .01f, 0.0f, 1.0f);
ImGui::DragFloat("Volumetric Step Count", &env->VolumetricStepCount, 1.f, 0.0f);
}
if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::DragFloat("Exposure", &Engine::GetCurrentScene()->m_EditorCamera->Exposure, .01f, 0.0f, 5.0f);
}
}
ImGui::End();
@@ -1515,10 +1520,6 @@ namespace Nuake {
}
if (ImGui::BeginMenu("View"))
{
if (ImGui::MenuItem("Reload Interfaces", NULL))
{
Engine::GetCurrentScene()->ReloadInterfaces();
}
if (ImGui::MenuItem("Lighting", NULL, true)) {}
if (ImGui::MenuItem("Draw grid", NULL, m_DrawGrid))
m_DrawGrid = !m_DrawGrid;