diff --git a/CMakeLists.txt b/CMakeLists.txt index a622779..e739b4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,10 +126,12 @@ ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/PhysicalBasedRendering) ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Subgroup) ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/ShadowVolume) -ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/SimpleOcean) + ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/SimpleReflection) +ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/SimpleOcean) ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Ocean) + ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Terrain) ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/SkinnedMesh) diff --git a/LICENSE b/LICENSE index 2f52d07..0f80545 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2021 Valdemar Lindberg +Copyright (c) 2024 Valdemar Lindberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Samples/Instance/instance.cpp b/Samples/Instance/instance.cpp index ed8de8a..aabcc07 100644 --- a/Samples/Instance/instance.cpp +++ b/Samples/Instance/instance.cpp @@ -24,11 +24,11 @@ namespace glsample { } struct uniform_buffer_block { - glm::mat4 model; - glm::mat4 view; - glm::mat4 proj; - glm::mat4 modelView; - glm::mat4 modelViewProjection; + glm::mat4 model{}; + glm::mat4 view{}; + glm::mat4 proj{}; + glm::mat4 modelView{}; + glm::mat4 modelViewProjection{}; /* Light source. */ glm::vec4 direction = glm::vec4(1.0f / sqrt(2.0f), -1.0f / sqrt(2.0f), 0.0f, 0.0f); @@ -36,7 +36,7 @@ namespace glsample { glm::vec4 ambientColor = glm::vec4(0.15f, 0.15f, 0.15f, 1.0f); glm::vec4 specularColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); - glm::vec4 viewPos; + glm::vec4 viewPos{}; float shininess = 16.0f; } uniformData; @@ -53,18 +53,18 @@ namespace glsample { MeshObject instanceGeometry; /* */ - unsigned int diffuse_texture; + unsigned int diffuse_texture{}; /* */ - unsigned int instance_program; + unsigned int instance_program{}; /* Instance buffer model matrix. */ - unsigned int instance_model_buffer; + unsigned int instance_model_buffer{}; /* */ unsigned int uniform_buffer_binding = 0; unsigned int uniform_instance_buffer_binding = 1; - unsigned int uniform_mvp_buffer; - unsigned int uniform_instance_buffer; + unsigned int uniform_mvp_buffer{}; + unsigned int uniform_instance_buffer{}; const size_t nrUniformBuffers = 3; size_t uniformSharedBufferSize = sizeof(uniform_buffer_block); diff --git a/Samples/ModelViewer/ModelViewer.cpp b/Samples/ModelViewer/ModelViewer.cpp index dc3f363..c4f0c39 100644 --- a/Samples/ModelViewer/ModelViewer.cpp +++ b/Samples/ModelViewer/ModelViewer.cpp @@ -1,6 +1,7 @@ #include "ModelViewer.h" #include "ImageImport.h" #include "ModelImporter.h" +#include "Skybox.h" #include #include #include @@ -40,11 +41,6 @@ namespace glsample { const std::vector pbr_evolution_binary = IOUtil::readFileData(this->PBREvoluationShaderPath, this->getFileSystem()); - const std::vector vertex_skybox_binary = - IOUtil::readFileData(this->vertexSkyboxPanoramicShaderPath, this->getFileSystem()); - const std::vector fragment_skybox_binary = - IOUtil::readFileData(this->fragmentSkyboxPanoramicShaderPath, this->getFileSystem()); - /* Setup compiler convert options. */ fragcore::ShaderCompiler::CompilerConvertOption compilerOptions; compilerOptions.target = fragcore::ShaderLanguage::GLSL; @@ -56,20 +52,12 @@ namespace glsample { &pbr_control_binary, &pbr_evolution_binary); /* Create skybox graphic pipeline program. */ - this->skybox_program = - ShaderLoader::loadGraphicProgram(compilerOptions, &vertex_skybox_binary, &fragment_skybox_binary); + this->skybox_program = Skybox::loadDefaultProgram(this->getFileSystem()); } - /* Setup graphic pipeline. */ - glUseProgram(this->skybox_program); - int uniform_buffer_index = glGetUniformBlockIndex(this->skybox_program, "UniformBufferBlock"); - glUniformBlockBinding(this->skybox_program, uniform_buffer_index, 0); - glUniform1i(glGetUniformLocation(this->skybox_program, "PanoramaTexture"), 0); - glUseProgram(0); - /* Setup graphic pipeline. */ glUseProgram(this->physical_based_rendering_program); - uniform_buffer_index = glGetUniformBlockIndex(this->physical_based_rendering_program, "UniformBufferBlock"); + int uniform_buffer_index = glGetUniformBlockIndex(this->physical_based_rendering_program, "UniformBufferBlock"); glUniform1i(glGetUniformLocation(this->physical_based_rendering_program, "albedoMap"), 0); glUniform1i(glGetUniformLocation(this->physical_based_rendering_program, "normalMap"), 1); diff --git a/Samples/ModelViewer/ModelViewer.h b/Samples/ModelViewer/ModelViewer.h index 39e835c..b92fa21 100644 --- a/Samples/ModelViewer/ModelViewer.h +++ b/Samples/ModelViewer/ModelViewer.h @@ -1,3 +1,4 @@ +#include "SampleHelper.h" #include "Scene.h" #include "Skybox.h" #include "Util/CameraController.h" @@ -5,7 +6,6 @@ #include #include #include -#include namespace glsample { @@ -16,26 +16,11 @@ namespace glsample { public: ModelViewer(); - struct point_light { - glm::vec3 position; - float range; - glm::vec4 color; - float intensity; - float constant_attenuation; - float linear_attenuation; - float quadratic_attenuation; - }; - struct light_settings { - glm::vec4 ambientColor; - glm::vec4 specularColor; - glm::vec4 direction; - glm::vec4 lightColor; - /* */ - struct point_light pointLights[4]; - float gamma; - float exposure; + DirectionalLight directionalLight; + /* */ + PointLightInstance pointLights[4]; }; struct camera_settings { glm::vec4 gEyeWorldPos; @@ -47,17 +32,17 @@ namespace glsample { }; struct uniform_buffer_block { - glm::mat4 model; - glm::mat4 view; - glm::mat4 proj; - glm::mat4 modelView; - glm::mat4 viewProjection; - glm::mat4 modelViewProjection; + glm::mat4 model{}; + glm::mat4 view{}; + glm::mat4 proj{}; + glm::mat4 modelView{}; + glm::mat4 viewProjection{}; + glm::mat4 modelViewProjection{}; struct light_settings lightsettings; struct tessellation_settings tessellation; /* Camera settings. */ - struct camera_settings camera; + struct camera_settings camera{}; } uniformStageBuffer; @@ -74,10 +59,6 @@ namespace glsample { const size_t nrUniformBuffer = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); - /* Skybox. */ - const std::string vertexSkyboxPanoramicShaderPath = "Shaders/skybox/skybox.vert.spv"; - const std::string fragmentSkyboxPanoramicShaderPath = "Shaders/skybox/panoramic.frag.spv"; - /* Advanced. */ const std::string PBRvertexShaderPath = "Shaders/pbr/physicalbasedrendering.vert.spv"; const std::string PBRfragmentShaderPath = "Shaders/pbr/physicalbasedrendering.frag.spv"; @@ -98,6 +79,7 @@ namespace glsample { // ImGui::ColorEdit4("Ambient", &this->uniform.ambientColor[0], // ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); // ImGui::DragFloat3("Direction", &this->uniform.direction[0]); + ImGui::TextUnformatted("Light Settings"); for (size_t i = 0; i < sizeof(uniform.lightsettings.pointLights) / sizeof(uniform.lightsettings.pointLights[0]); @@ -118,13 +100,11 @@ namespace glsample { } ImGui::TextUnformatted("Light"); - ImGui::ColorEdit4("Color", &this->uniform.lightsettings.lightColor[0], ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR); - ImGui::ColorEdit4("Ambient Color", &this->uniform.lightsettings.ambientColor[0], - ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); - ImGui::DragFloat3("Direction", &this->uniform.lightsettings.direction[0]); - - ImGui::DragFloat("Exposure", &this->uniform.lightsettings.exposure); - ImGui::DragFloat("Gamma", &this->uniform.lightsettings.gamma); + // ImGui::ColorEdit4("Color", &this->uniform.lightsettings.lightColor[0], + // ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR); + // ImGui::ColorEdit4("Ambient Color", &this->uniform.lightsettings.ambientColor[0], + // ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); + // ImGui::DragFloat3("Direction", &this->uniform.lightsettings.direction[0]); ImGui::TextUnformatted("Tessellation"); ImGui::DragFloat("Displacement", &this->uniform.tessellation.gDispFactor, 1, 0.0f, 100.0f); diff --git a/Samples/NormalMapping/NormalMap.cpp b/Samples/NormalMapping/NormalMap.cpp index 1306e11..36b0023 100644 --- a/Samples/NormalMapping/NormalMap.cpp +++ b/Samples/NormalMapping/NormalMap.cpp @@ -20,17 +20,17 @@ namespace glsample { this->addUIComponent(this->normalMapSettingComponent); /* Default camera position and orientation. */ - this->camera.setPosition(glm::vec3(-2.5f)); + this->camera.setPosition(glm::vec3(20.5f)); this->camera.lookAt(glm::vec3(0.f)); } struct uniform_buffer_block { - glm::mat4 model; - glm::mat4 view; - glm::mat4 proj; - glm::mat4 modelView; - glm::mat4 ViewProj; - glm::mat4 modelViewProjection; + glm::mat4 model{}; + glm::mat4 view{}; + glm::mat4 proj{}; + glm::mat4 modelView{}; + glm::mat4 ViewProj{}; + glm::mat4 modelViewProjection{}; /* */ glm::vec4 tintColor = glm::vec4(1, 1, 1, 1); @@ -51,11 +51,11 @@ namespace glsample { Scene scene; /* World Scene. */ /* */ - unsigned int normalMapping_program; + unsigned int normalMapping_program{}; /* Uniform buffer. */ unsigned int uniform_buffer_binding = 0; - unsigned int uniform_buffer; + unsigned int uniform_buffer{}; const size_t nrUniformBuffer = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); diff --git a/Samples/OcclusionCulling/OcclusionCulling.cpp b/Samples/OcclusionCulling/OcclusionCulling.cpp index c09721c..358fc52 100644 --- a/Samples/OcclusionCulling/OcclusionCulling.cpp +++ b/Samples/OcclusionCulling/OcclusionCulling.cpp @@ -37,12 +37,12 @@ namespace glsample { } struct uniform_buffer_block { - glm::mat4 model; - glm::mat4 view; - glm::mat4 proj; - glm::mat4 modelView; - glm::mat4 ViewProj; - glm::mat4 modelViewProjection; + glm::mat4 model{}; + glm::mat4 view{}; + glm::mat4 proj{}; + glm::mat4 modelView{}; + glm::mat4 ViewProj{}; + glm::mat4 modelViewProjection{}; /* */ glm::vec4 tintColor = glm::vec4(1, 1, 1, 1); @@ -62,15 +62,15 @@ namespace glsample { ConditionalScene scene; /* Textures. */ - unsigned int diffuse_texture; - unsigned int normal_texture; + unsigned int diffuse_texture{}; + unsigned int normal_texture{}; /* */ - unsigned int normalMapping_program; + unsigned int normalMapping_program{}; /* Uniform buffer. */ unsigned int uniform_buffer_binding = 0; - unsigned int uniform_buffer; + unsigned int uniform_buffer{}; const size_t nrUniformBuffer = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); diff --git a/Samples/Ocean/Ocean.cpp b/Samples/Ocean/Ocean.cpp index 0dbd2a9..df8f18d 100644 --- a/Samples/Ocean/Ocean.cpp +++ b/Samples/Ocean/Ocean.cpp @@ -1,3 +1,4 @@ +#include "PostProcessing/MistPostProcessing.h" #include "Skybox.h" #include #include @@ -23,69 +24,68 @@ namespace glsample { this->camera.lookAt(glm::vec3(0.f)); } - typedef struct _ocean_vertex_t { + using OceanVertex = struct _ocean_vertex_t { /* */ float h0[2]; float ht_real_img[2]; - } OceanVertex; + }; /* */ MeshObject ocean; + Skybox skybox; + MistPostProcessing mistProcessing; /* */ - int skybox_panoramic_texture; + unsigned int skybox_panoramic_texture = 0; + unsigned int irradiance_texture = 0; + unsigned int color_texture = 0; /* */ - unsigned int skybox_program; - unsigned int ocean_graphic_program; - unsigned int spectrum_compute_program; - unsigned int kff_compute_program; + unsigned int ocean_graphic_program = 0; + unsigned int spectrum_compute_program = 0; + unsigned int kff_compute_program = 0; /* */ unsigned int ocean_width = 128; unsigned int ocean_height = 128; struct uniform_buffer_block { - glm::mat4 model; - glm::mat4 view; - glm::mat4 proj; - glm::mat4 modelView; - glm::mat4 modelViewProjection; + glm::mat4 model{}; + glm::mat4 view{}; + glm::mat4 proj{}; + glm::mat4 modelView{}; + glm::mat4 modelViewProjection{}; /*light source. */ glm::vec4 direction = glm::vec4(1.0f / sqrt(2.0f), -1.0f / sqrt(2.0f), 0, 0); glm::vec4 lightColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); glm::vec4 ambientColor = glm::vec4(0.4); - float width, height; - float speed; - float delta; - float patchSize; + float width{}, height{}; + float speed{}; + float delta{}; + float patchSize{}; - glm::vec4 gEyeWorldPos; - float gDispFactor; - float tessLevel; + glm::vec4 gEyeWorldPos{}; + float gDispFactor{}; + float tessLevel{}; } uniformStageBuffer; unsigned int uniform_buffer_binding = 0; - unsigned int uniform_buffer; + unsigned int uniform_buffer{}; const size_t nrUniformBuffer = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); unsigned int ssbo_ocean_buffer_binding = 1; CameraController camera; - Skybox skybox; - typedef struct particle_t { + using Particle = struct particle_t { glm::vec4 position; /* Position, time */ glm::vec4 velocity; /* Velocity. */ - } Particle; + }; - /* */ - const std::string vertexSkyboxShaderPath = "Shaders/skybox/skybox.vert.spv"; - const std::string fragmentSkyboxShaderPath = "Shaders/skybox/panoramic.frag.spv"; /* */ const std::string vertexShaderPath = "Shaders/ocean/ocean.vert.spv"; const std::string fragmentShaderPath = "Shaders/ocean/ocean.frag.spv"; @@ -119,7 +119,6 @@ namespace glsample { void Release() override { /* */ - glDeleteProgram(this->skybox_program); glDeleteProgram(this->ocean_graphic_program); glDeleteProgram(this->spectrum_compute_program); glDeleteProgram(this->kff_compute_program); @@ -199,7 +198,6 @@ namespace glsample { const std::vector compute_kff_binary = IOUtil::readFileData(computeKFFShaderPath, this->getFileSystem()); - /* Load graphic program for skybox. */ this->ocean_graphic_program = ShaderLoader::loadGraphicProgram(compilerOptions, &vertex_ocean_binary, &fragment_binary, nullptr, &control_binary, &evolution_binary); @@ -208,15 +206,6 @@ namespace glsample { this->spectrum_compute_program = ShaderLoader::loadComputeProgram(compilerOptions, &compute_spectrum_binary); this->kff_compute_program = ShaderLoader::loadComputeProgram(compilerOptions, &compute_kff_binary); - - /* Load shader binaries. */ - std::vector vertex_skybox_binary = - IOUtil::readFileData(this->vertexSkyboxShaderPath, this->getFileSystem()); - std::vector fragment_skybox_binary = - IOUtil::readFileData(this->fragmentSkyboxShaderPath, this->getFileSystem()); - - this->skybox_program = - ShaderLoader::loadGraphicProgram(compilerOptions, &vertex_skybox_binary, &fragment_skybox_binary); } /* Setup ocean Graphic Pipeline. */ @@ -247,13 +236,6 @@ namespace glsample { this->ssbo_ocean_buffer_binding); glUseProgram(0); - /* Setup graphic pipeline. */ - glUseProgram(this->skybox_program); - uniform_buffer_index = glGetUniformBlockIndex(this->skybox_program, "UniformBufferBlock"); - glUniformBlockBinding(this->skybox_program, uniform_buffer_index, 0); - glUniform1i(glGetUniformLocation(this->skybox_program, "PanoramaTexture"), 0); - glUseProgram(0); - /* Compute uniform size that is aligned with the requried for the hardware. */ GLint minMapBufferSize = 0; glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &minMapBufferSize); @@ -266,47 +248,16 @@ namespace glsample { glBindBuffer(GL_UNIFORM_BUFFER, 0); /* Load Ocean plan geometry. */ - { - std::vector vertices; - std::vector indices; - ProceduralGeometry::generatePlan(1, vertices, indices, this->ocean_width, this->ocean_height); - - /* Create array buffer, for rendering static geometry. */ - glGenVertexArrays(1, &this->ocean.vao); - glBindVertexArray(this->ocean.vao); - - glGenBuffers(1, &this->ocean.vbo); - glBindBuffer(GL_ARRAY_BUFFER, ocean.vbo); - glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(ProceduralGeometry::Vertex), vertices.data(), - GL_STATIC_DRAW); - - glGenBuffers(1, &this->ocean.ibo); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->ocean.ibo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), - GL_STATIC_DRAW); - this->ocean.nrIndicesElements = indices.size(); - - /* */ - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ProceduralGeometry::Vertex), nullptr); - - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(ProceduralGeometry::Vertex), - (void *)(sizeof(float) * 3)); - - glEnableVertexAttribArray(2); - glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(OceanVertex), (void *)(sizeof(float) * 2)); - - glEnableVertexAttribArray(3); - glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(OceanVertex), (void *)(sizeof(float) * 2)); - - glBindVertexArray(0); - } + Common::loadPlan(this->ocean, 1); /* Load skybox for reflective. */ TextureImporter textureImporter(this->getFileSystem()); this->skybox_panoramic_texture = textureImporter.loadImage2D(skyboxPath); - this->skybox.Init(this->skybox_panoramic_texture, this->skybox_program); + this->skybox.Init(this->skybox_panoramic_texture, Skybox::loadDefaultProgram(this->getFileSystem())); + + /* */ + ProcessData util(this->getFileSystem()); + util.computeIrradiance(this->skybox_panoramic_texture, this->irradiance_texture, 256, 128); } void draw() override { @@ -345,38 +296,55 @@ namespace glsample { /* Render ocean. */ { + glUseProgram(this->ocean_graphic_program); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glDepthFunc(GL_LESS); + /* Bind reflective material. */ glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, this->skybox_panoramic_texture); - glUseProgram(this->ocean_graphic_program); + /* Bind reflective material. */ + glActiveTexture(GL_TEXTURE0 + 11);//TODO:fix + glBindTexture(GL_TEXTURE_2D, this->irradiance_texture); /* Draw triangle. */ glBindVertexArray(this->ocean.vao); glPatchParameteri(GL_PATCH_VERTICES, 3); glDrawElements(GL_PATCHES, this->ocean_width * this->ocean_height * 2, GL_UNSIGNED_INT, nullptr); + + if (this->oceanSettingComponent->showWireFrame) { + + glPolygonMode(GL_FRONT_AND_BACK, this->oceanSettingComponent->showWireFrame ? GL_LINE : GL_FILL); + glDepthFunc(GL_LEQUAL); + + /* */ + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, this->color_texture); + + glPatchParameteri(GL_PATCH_VERTICES, 3); + glDrawElements(GL_PATCHES, this->ocean.nrIndicesElements, GL_UNSIGNED_INT, nullptr); + } + glBindVertexArray(0); + glUseProgram(0); } /* Render Skybox. */ - { - /* Draw triangle*/ - this->skybox.Render(this->camera); - } + this->skybox.Render(this->camera); + - /* Post processing. */ - {} } void update() override { /* */ - const float elapsedTime = getTimer().getElapsed(); - camera.update(getTimer().deltaTime()); + this->camera.update(getTimer().deltaTime()); /* */ this->uniformStageBuffer.model = glm::mat4(1.0f); - this->uniformStageBuffer.model = glm::scale(this->uniformStageBuffer.model, glm::vec3(0.95f)); + this->uniformStageBuffer.model = glm::scale(this->uniformStageBuffer.model, glm::vec3(1)); this->uniformStageBuffer.view = camera.getViewMatrix(); this->uniformStageBuffer.modelViewProjection = this->uniformStageBuffer.proj * camera.getViewMatrix() * this->uniformStageBuffer.model; @@ -403,8 +371,6 @@ namespace glsample { }; } // namespace glsample -// TODO param, ocean with,height, skybox - int main(int argc, const char **argv) { try { glsample::OceanGLSample sample; diff --git a/Samples/PointLight/pointlights.cpp b/Samples/PointLight/pointlights.cpp index 9e1d73e..22df2e2 100644 --- a/Samples/PointLight/pointlights.cpp +++ b/Samples/PointLight/pointlights.cpp @@ -35,31 +35,31 @@ namespace glsample { static const size_t nrPointLights = 4; struct uniform_buffer_block { - glm::mat4 model; - glm::mat4 view; - glm::mat4 proj; - glm::mat4 modelView; - glm::mat4 modelViewProjection; + glm::mat4 model{}; + glm::mat4 view{}; + glm::mat4 proj{}; + glm::mat4 modelView{}; + glm::mat4 modelViewProjection{}; /* Material. */ glm::vec4 ambientColor = glm::vec4(0.075f, 0.075f, 0.075f, 1.0f); - PointLightSource pointLights[nrPointLights]; + PointLightSource pointLights[nrPointLights]{}; } uniformStageBuffer; /* */ MeshObject plan; /* Textures. */ - unsigned int diffuse_texture; + unsigned int diffuse_texture{}; /* Program. */ - unsigned int pointLight_program; + unsigned int pointLight_program{}; /* Uniforms. */ - unsigned int uniform_buffer_index; + unsigned int uniform_buffer_index{}; unsigned int uniform_buffer_binding = 0; - unsigned int uniform_buffer; + unsigned int uniform_buffer{}; const size_t nrUniformBuffer = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); diff --git a/Samples/RayTracing/RayTracing.cpp b/Samples/RayTracing/RayTracing.cpp index 2871141..d9a5732 100644 --- a/Samples/RayTracing/RayTracing.cpp +++ b/Samples/RayTracing/RayTracing.cpp @@ -40,33 +40,33 @@ namespace glsample { unsigned int sampleIndex; - } uniformBuffer; + } uniformBuffer{}; /* Framebuffers. */ - unsigned int raytracing_framebuffer; - unsigned int raytracing_render_texture; /* No round robin required, since once updated, it is instantly + unsigned int raytracing_framebuffer{}; + unsigned int raytracing_render_texture{}; /* No round robin required, since once updated, it is instantly blitted. thus no implicit sync between frames. */ - unsigned int raytracing_display_texture; - size_t raytracing_texture_width; - size_t raytracing_texture_height; + unsigned int raytracing_display_texture{}; + size_t raytracing_texture_width{}; + size_t raytracing_texture_height{}; Scene scene; /* World Scene. */ Skybox skybox; /* */ CameraController camera; /* */ - unsigned int raytracing_program; - int localWorkGroupSize[3]; + unsigned int raytracing_program{}; + int localWorkGroupSize[3]{}; unsigned int nthTexture = 0; - unsigned int skytexture; + unsigned int skytexture{}; /* */ unsigned int uniform_buffer_binding = 0; unsigned int uniform_pointlight_buffer_binding = 1; - unsigned int uniform_buffer; - unsigned int uniform_pointlight_buffer; + unsigned int uniform_buffer{}; + unsigned int uniform_pointlight_buffer{}; const size_t nrUniformBuffer = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); size_t uniformLightBufferSize = 0; @@ -88,7 +88,7 @@ namespace glsample { // ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR); ImGui::DragFloat3("Direction", // &this->uniform.direction[0]); - int tmp; + int tmp = 0; if (ImGui::DragInt("Max Samples", &MaxSamples)) { // TODO add } @@ -100,7 +100,7 @@ namespace glsample { bool showWireFrame = false; bool showLight = false; - int MaxSamples; + int MaxSamples{}; private: struct uniform_buffer_block &uniform; @@ -144,7 +144,7 @@ namespace glsample { glUseProgram(0); /* Align uniform buffer in respect to driver requirement. */ - GLint minMapBufferSize; + GLint minMapBufferSize = 0; glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &minMapBufferSize); this->uniformAlignBufferSize = fragcore::Math::align(this->uniformAlignBufferSize, (size_t)minMapBufferSize); @@ -216,7 +216,7 @@ namespace glsample { void draw() override { - int width, height; + int width = 0, height = 0; this->getSize(&width, &height); glBindBufferRange(GL_UNIFORM_BUFFER, this->uniform_buffer_binding, this->uniform_buffer, diff --git a/Samples/Rigidbody/Rigidbody.cpp b/Samples/Rigidbody/Rigidbody.cpp index 830b46f..5389032 100644 --- a/Samples/Rigidbody/Rigidbody.cpp +++ b/Samples/Rigidbody/Rigidbody.cpp @@ -38,11 +38,11 @@ namespace glsample { } using UniformBufferBlock = struct uniform_buffer_block { - glm::mat4 model; - glm::mat4 view; - glm::mat4 proj; - glm::mat4 modelView; - glm::mat4 modelViewProjection; + glm::mat4 model{}; + glm::mat4 view{}; + glm::mat4 proj{}; + glm::mat4 modelView{}; + glm::mat4 modelViewProjection{}; /*light source. */ glm::vec4 direction = glm::vec4(1.0f / sqrt(2.0f), -1.0f / sqrt(2.0f), 0.0f, 0.0f); @@ -58,8 +58,8 @@ namespace glsample { std::vector rigidbodies_box; std::vector rigidbodies_sphere; - fragcore::RigidBody *planeRigibody; - fragcore::RigidBody *sphere_camera_collider_rig; + fragcore::RigidBody *planeRigibody{}; + fragcore::RigidBody *sphere_camera_collider_rig{}; const std::array grid_aray = {8, 16, 8}; @@ -69,17 +69,17 @@ namespace glsample { MeshObject sphereMesh; /* White texture for each object. */ - unsigned int white_texture; + unsigned int white_texture{}; /* */ - unsigned int graphic_program; - unsigned int hyperplane_program; + unsigned int graphic_program{}; + unsigned int hyperplane_program{}; /* */ unsigned int uniform_buffer_binding = 0; unsigned int uniform_instance_buffer_binding = 1; - unsigned int uniform_buffer; - unsigned int ssbo_instance_buffer; + unsigned int uniform_buffer{}; + unsigned int ssbo_instance_buffer{}; const size_t nrUniformBuffers = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); @@ -91,7 +91,7 @@ namespace glsample { size_t instanceBatch = 0; - PhysicInterface *physic_interface; + PhysicInterface *physic_interface{}; /* RigidBody Rendering Path. */ const std::string vertexInstanceShaderPath = "Shaders/instance/instance_ssbo.vert.spv"; diff --git a/Samples/SimpleOcean/SimpleOcean.cpp b/Samples/SimpleOcean/SimpleOcean.cpp index 704a61d..df90011 100644 --- a/Samples/SimpleOcean/SimpleOcean.cpp +++ b/Samples/SimpleOcean/SimpleOcean.cpp @@ -1,3 +1,5 @@ +#include "PostProcessing/MistPostProcessing.h" +#include "SampleHelper.h" #include "Skybox.h" #include "imgui.h" #include @@ -28,13 +30,15 @@ namespace glsample { /* Default camera position and orientation. */ this->camera.setPosition(glm::vec3(200.5f)); this->camera.lookAt(glm::vec3(0.f)); + this->camera.setNear(1); + this->camera.setFar(4500.0f); } - static const size_t nrMaxWaves = 64; + static const size_t nrMaxWaves = 128; using Wave = struct wave_t { - glm::vec4 waveAmpSpeed; /* */ - glm::vec4 direction; /* */ + glm::vec4 waveAmpSpeedStepness; /* */ + glm::vec4 direction; /* */ }; struct UniformOceanBufferBlock { @@ -45,24 +49,24 @@ namespace glsample { glm::mat4 modelViewProjection{}; /* light source. */ - glm::vec4 lookDirection{}; - glm::vec4 lightDirection = glm::vec4(1.0f / sqrt(2.0f), -1.0f / sqrt(2.0f), 0, 0.0f); - glm::vec4 lightColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); - glm::vec4 specularColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); - glm::vec4 ambientColor = glm::vec4(0.4, 0.4, 0.4, 1.0f); - glm::vec4 position{}; + DirectionalLight directional; + CameraInstance camera; /* */ Wave waves[nrMaxWaves]{}; /* */ - int nrWaves = 32; + int nrWaves = 64; float time = 0.0f; + float stepness = 1; + float rolling = 1; /* Material */ + glm::vec4 oceanColor = glm::vec4(0.4, 0.65, 1, 1); + glm::vec4 specularColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); + glm::vec4 ambientColor = glm::vec4(0.4, 0.4, 0.4, 1.0f); float shininess = 8; float fresnelPower = 1.333f; - glm::vec4 oceanColor = glm::vec4(0.4, 0.65, 1, 1); }; /* Combined uniform block. */ @@ -74,25 +78,26 @@ namespace glsample { /* */ MeshObject plan; Skybox skybox; + MistPostProcessing mistprocessing; /* */ unsigned int normal_texture{}; unsigned int reflection_texture{}; unsigned int irradiance_texture{}; + unsigned int color_texture{}; /* */ - unsigned int simpleOcean_program{}; - unsigned int skybox_program{}; + unsigned int simpleOcean_program = 0; + unsigned int simpleOceanGerstner_program = 0; /* Uniform buffers. */ unsigned int uniform_buffer_binding = 0; - unsigned int uniform_buffer{}; + unsigned int uniform_buffer = 0; const size_t nrUniformBuffer = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); size_t oceanUniformSize = 0; class SimpleOceanSettingComponent : public nekomimi::UIComponent { - public: SimpleOceanSettingComponent(struct uniform_buffer_block &uniform) : uniform(uniform) { this->setName("Simple Ocean Settings"); @@ -101,19 +106,23 @@ namespace glsample { void draw() override { /* */ ImGui::TextUnformatted("Light Setting"); - ImGui::ColorEdit4("Light", &this->uniform.ocean.lightColor[0], + ImGui::ColorEdit4("Light", &this->uniform.ocean.directional.lightColor[0], ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); ImGui::ColorEdit4("Ambient", &this->uniform.ocean.ambientColor[0], ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); ImGui::ColorEdit4("Specular Color", &this->uniform.ocean.specularColor[0], ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); - if (ImGui::DragFloat3("Light Direction", &this->uniform.ocean.lightDirection[0])) { - this->uniform.ocean.lightDirection = glm::normalize(this->uniform.ocean.lightDirection); + if (ImGui::DragFloat3("Light Direction", &this->uniform.ocean.directional.lightDirection[0])) { + this->uniform.ocean.directional.lightDirection = + glm::normalize(this->uniform.ocean.directional.lightDirection); } /* */ ImGui::TextUnformatted("Ocean"); + ImGui::Checkbox("Use Gerstner", &this->useGerstner); ImGui::DragInt("Number Waves", &this->uniform.ocean.nrWaves, 1, 0, nrMaxWaves); + ImGui::DragFloat("Stepness", &this->uniform.ocean.stepness, 1, 0); + ImGui::DragFloat("rolling", &this->uniform.ocean.rolling, 1, 0); if (ImGui::CollapsingHeader("Ocean Wave Setttings", &ocean_setting_visable, ImGuiTreeNodeFlags_CollapsingHeader)) { @@ -121,10 +130,10 @@ namespace glsample { for (int i = 0; i < this->uniform.ocean.nrWaves; i++) { ImGui::PushID(i); ImGui::Text("Wave %d", i); - ImGui::DragFloat("WaveLength", &this->uniform.ocean.waves[i].waveAmpSpeed[0]); - ImGui::DragFloat("Amplitude", &this->uniform.ocean.waves[i].waveAmpSpeed[1]); - ImGui::DragFloat("Speed", &this->uniform.ocean.waves[i].waveAmpSpeed[2]); - ImGui::DragFloat("Steepness", &this->uniform.ocean.waves[i].waveAmpSpeed[3]); + ImGui::DragFloat("WaveLength", &this->uniform.ocean.waves[i].waveAmpSpeedStepness[0]); + ImGui::DragFloat("Amplitude", &this->uniform.ocean.waves[i].waveAmpSpeedStepness[1]); + ImGui::DragFloat("Speed", &this->uniform.ocean.waves[i].waveAmpSpeedStepness[2]); + ImGui::DragFloat("Steepness", &this->uniform.ocean.waves[i].waveAmpSpeedStepness[3]); if (ImGui::DragFloat2("Direction", &this->uniform.ocean.waves[i].direction[0])) { } @@ -134,6 +143,7 @@ namespace glsample { } ImGui::TextUnformatted("Ocean Material"); + ImGui::DragFloat("Shinines", &this->uniform.ocean.shininess); ImGui::DragFloat("Fresnel Power", &this->uniform.ocean.fresnelPower); ImGui::ColorEdit4("Ocean Base Color", &this->uniform.ocean.oceanColor[0], @@ -145,6 +155,7 @@ namespace glsample { } bool showWireFrame = false; + bool useGerstner = false; private: struct uniform_buffer_block &uniform; @@ -157,6 +168,7 @@ namespace glsample { /* Simple Ocean Wave. */ const std::string vertexSimpleOceanShaderPath = "Shaders/simpleocean/simpleocean.vert.spv"; const std::string fragmentSimpleOceanShaderPath = "Shaders/simpleocean/simpleocean.frag.spv"; + const std::string vertexSimpleOceanGerstnerShaderPath = "Shaders/simpleocean/simpleocean_gerstner.vert.spv"; /* Skybox. */ const std::string vertexSkyboxPanoramicShaderPath = "Shaders/skybox/skybox.vert.spv"; @@ -186,14 +198,11 @@ namespace glsample { /* Load shader source. */ const std::vector vertex_simple_ocean_binary = IOUtil::readFileData(vertexSimpleOceanShaderPath, this->getFileSystem()); + const std::vector vertex_simple_ocean_gerstner_binary = + IOUtil::readFileData(vertexSimpleOceanGerstnerShaderPath, this->getFileSystem()); const std::vector fragment_simple_ocean_binary = IOUtil::readFileData(fragmentSimpleOceanShaderPath, this->getFileSystem()); - const std::vector vertex_skybox_binary = - IOUtil::readFileData(vertexSkyboxPanoramicShaderPath, this->getFileSystem()); - const std::vector fragment_skybox_binary = - IOUtil::readFileData(fragmentSkyboxPanoramicShaderPath, this->getFileSystem()); - fragcore::ShaderCompiler::CompilerConvertOption compilerOptions; compilerOptions.target = fragcore::ShaderLanguage::GLSL; compilerOptions.glslVersion = this->getShaderVersion(); @@ -201,8 +210,8 @@ namespace glsample { /* Load shader programs. */ this->simpleOcean_program = ShaderLoader::loadGraphicProgram( compilerOptions, &vertex_simple_ocean_binary, &fragment_simple_ocean_binary); - this->skybox_program = - ShaderLoader::loadGraphicProgram(compilerOptions, &vertex_skybox_binary, &fragment_skybox_binary); + this->simpleOceanGerstner_program = ShaderLoader::loadGraphicProgram( + compilerOptions, &vertex_simple_ocean_gerstner_binary, &fragment_simple_ocean_binary); } /* Setup graphic pipeline settings. */ @@ -210,24 +219,24 @@ namespace glsample { int uniform_buffer_index = glGetUniformBlockIndex(this->simpleOcean_program, "UniformBufferBlock"); glUniform1i(glGetUniformLocation(this->simpleOcean_program, "ReflectionTexture"), 0); glUniform1i(glGetUniformLocation(this->simpleOcean_program, "NormalTexture"), 1); + glUniform1i(glGetUniformLocation(this->simpleOcean_program, "IrradianceTexture"), 10); glUniformBlockBinding(this->simpleOcean_program, uniform_buffer_index, this->uniform_buffer_binding); glUseProgram(0); - /* Setup graphic pipeline settings. */ - glUseProgram(this->skybox_program); - uniform_buffer_index = glGetUniformBlockIndex(this->skybox_program, "UniformBufferBlock"); - glUniformBlockBinding(this->skybox_program, uniform_buffer_index, 0); - glUniform1i(glGetUniformLocation(this->skybox_program, "PanoramaTexture"), 0); - glUseProgram(0); - /* load Textures */ TextureImporter textureImporter(this->getFileSystem()); this->reflection_texture = textureImporter.loadImage2D(panoramicPath, ColorSpace::Raw); - this->skybox.Init(this->reflection_texture, this->skybox_program); + this->skybox.Init(this->reflection_texture, Skybox::loadDefaultProgram(this->getFileSystem())); + /* */ ProcessData util(this->getFileSystem()); util.computeIrradiance(this->reflection_texture, this->irradiance_texture, 256, 128); + /* */ + this->color_texture = Common::createColorTexture(1, 1, Color(0, 1, 0, 1)); + + this->mistprocessing.initialize(this->getFileSystem()); + /* Align uniform buffer in respect to driver requirement. */ GLint minMapBufferSize = 0; glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &minMapBufferSize); @@ -247,11 +256,11 @@ namespace glsample { for (size_t i = 0; i < nrMaxWaves; i++) { float waveLength = (i * 2.2 + 1); - float waveAmplitude = 0.3f / (i + 1) * (0.05f + (nrMaxWaves - i) * 0.0005f); + float waveAmplitude = 0.3f / (i + 1) * (0.05f + (nrMaxWaves - i) * 0.0008f); float waveSpeed = (i + 1) * 0.1f; - this->uniform_stage_buffer.ocean.waves[i].waveAmpSpeed = - glm::vec4(waveLength, waveAmplitude, waveSpeed, 0); + this->uniform_stage_buffer.ocean.waves[i].waveAmpSpeedStepness = + glm::vec4(waveLength, waveAmplitude, waveSpeed, 1); this->uniform_stage_buffer.ocean.waves[i].direction = glm::normalize(glm::vec4( 2 * fragcore::Math::random() - 1.0, 2 * fragcore::Math::random() - 1.0, 0, 0)); @@ -272,9 +281,6 @@ namespace glsample { /* Skybox */ this->skybox.Render(this->camera); - /* Optional - to display wireframe. */ - glPolygonMode(GL_FRONT_AND_BACK, this->simpleOceanSettingComponent->showWireFrame ? GL_LINE : GL_FILL); - /* Ocean. */ { /* */ @@ -282,14 +288,21 @@ namespace glsample { (this->getFrameCount() % this->nrUniformBuffer) * this->uniformAlignBufferSize, this->oceanUniformSize); - glUseProgram(this->simpleOcean_program); + if (this->simpleOceanSettingComponent->useGerstner) { + glUseProgram(this->simpleOceanGerstner_program); + } else { + glUseProgram(this->simpleOcean_program); + } /* */ glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glDepthFunc(GL_LESS); + glDepthMask(GL_TRUE); /* */ - glEnable(GL_BLEND); + glDisable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -301,12 +314,35 @@ namespace glsample { glActiveTexture(GL_TEXTURE0 + 1); glBindTexture(GL_TEXTURE_2D, this->normal_texture); + /* */ + glActiveTexture(GL_TEXTURE0 + 10); + glBindTexture(GL_TEXTURE_2D, this->irradiance_texture); + /* Draw triangle. */ glBindVertexArray(this->plan.vao); glDrawElements(GL_TRIANGLES, this->plan.nrIndicesElements, GL_UNSIGNED_INT, nullptr); + + if (this->simpleOceanSettingComponent->showWireFrame) { + + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glDepthFunc(GL_LEQUAL); + + /* */ + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, this->color_texture); + + glDrawElements(GL_TRIANGLES, this->plan.nrIndicesElements, GL_UNSIGNED_INT, nullptr); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } glBindVertexArray(0); + glUseProgram(0); } + + /* Post processing. */ + this->mistprocessing.render(this->irradiance_texture, this->getFrameBuffer()->attachement0, + this->getFrameBuffer()->depthbuffer); } void update() override { @@ -319,18 +355,17 @@ namespace glsample { { this->uniform_stage_buffer.ocean.model = glm::mat4(1.0f); this->uniform_stage_buffer.ocean.model = glm::rotate(this->uniform_stage_buffer.ocean.model, - glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)); + glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f)); this->uniform_stage_buffer.ocean.model = - glm::scale(this->uniform_stage_buffer.ocean.model, glm::vec3(4000.95f)); + glm::scale(this->uniform_stage_buffer.ocean.model, glm::vec3(2000.0f)); this->uniform_stage_buffer.ocean.view = this->camera.getViewMatrix(); this->uniform_stage_buffer.ocean.proj = this->camera.getProjectionMatrix(); - this->uniform_stage_buffer.ocean.lookDirection = glm::vec4(this->camera.getLookDirection(), 0); this->uniform_stage_buffer.ocean.modelViewProjection = this->uniform_stage_buffer.ocean.proj * this->uniform_stage_buffer.ocean.view * this->uniform_stage_buffer.ocean.model; - this->uniform_stage_buffer.ocean.position = glm::vec4(this->camera.getPosition(), 0); + this->uniform_stage_buffer.ocean.camera.position = glm::vec4(this->camera.getPosition(), 0); this->uniform_stage_buffer.ocean.time = elapsedTime; } @@ -353,7 +388,7 @@ namespace glsample { SimpleOceanGLSample() : GLSample() {} void customOptions(cxxopts::OptionAdder &options) override { options("S,skybox", "Skybox Texture File Path", - cxxopts::value()->default_value("asset/snowy_forest_4k.exr")); + cxxopts::value()->default_value("asset/industrial_sunset_puresky_4k.exr")); } }; diff --git a/Samples/Terrain/Terrain.cpp b/Samples/Terrain/Terrain.cpp index a23f0c1..af812b4 100644 --- a/Samples/Terrain/Terrain.cpp +++ b/Samples/Terrain/Terrain.cpp @@ -1,12 +1,13 @@ #include "Common.h" #include "GLSampleSession.h" +#include "PostProcessing/MistPostProcessing.h" #include "UIComponent.h" #include #include #include #include #include -#include +#include #include #include #include @@ -55,7 +56,7 @@ namespace glsample { glm::vec4 diffuseColor = glm::vec4(1, 1, 1, 1); glm::vec4 ambientColor = glm::vec4(0.4, 0.4, 0.4, 1.0f); glm::vec4 specularColor = glm::vec4(1, 1, 1, 1); - glm::vec4 shinines = glm::vec4(1, 1, 1, 1); + glm::vec4 shinines = glm::vec4(8, 1, 1, 1); /* light source. */ DirectionalLight directional; @@ -93,10 +94,11 @@ namespace glsample { Skybox skybox; MeshObject terrain; - MeshObject ocean_volume; + MeshObject ocean_water; + MistPostProcessing mistprocessing; - unsigned int terrain_program{}; - unsigned int ocean_program{}; + unsigned int terrain_program = 0; + unsigned int ocean_program = 0; /* Uniform buffers. */ unsigned int uniform_buffer_binding = 0; @@ -138,9 +140,9 @@ namespace glsample { glDeleteBuffers(1, &this->terrain.vbo); glDeleteBuffers(1, &this->terrain.ibo); - glDeleteVertexArrays(1, &this->ocean_volume.vao); - glDeleteBuffers(1, &this->ocean_volume.vbo); - glDeleteBuffers(1, &this->ocean_volume.ibo); + glDeleteVertexArrays(1, &this->ocean_water.vao); + glDeleteBuffers(1, &this->ocean_water.vbo); + glDeleteBuffers(1, &this->ocean_water.ibo); } class TerrainSettingComponent : public nekomimi::UIComponent { @@ -166,7 +168,7 @@ namespace glsample { ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); ImGui::ColorEdit4("Specular Color", &this->stage_uniform.terrain.specularColor[0], ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); - ImGui::DragFloat("Specular Color", &this->stage_uniform.terrain.shinines[0]); + ImGui::DragFloat("Shin", &this->stage_uniform.terrain.shinines[0]); ImGui::TextUnformatted("Fog Setting"); ImGui::DragInt("Fog Type", (int *)&this->stage_uniform.terrain.fogSettings.fogType); @@ -182,10 +184,11 @@ namespace glsample { ImGui::DragFloat("Levels", &this->stage_uniform.terrain.tessLevel, 1, 0.0f, 10.0f); ImGui::DragFloat("Min Tessellation", &this->stage_uniform.terrain.minTessellation, 1, 0.0f, 100.0f); ImGui::DragFloat("Max Tessellation", &this->stage_uniform.terrain.maxTessellation, 1, 0.0f, 100.0f); - - ImGui::TextUnformatted("Ocean Settings"); + ImGui::DragFloat("Distance Tessellation", &this->stage_uniform.terrain.maxTessellation, 1, 0.0f, + 100.0f); ImGui::TextUnformatted("Terrain Settings"); + ImGui::Checkbox("Show Terrain", &this->showTerrain); ImGui::DragFloat2("Tile Scale", &this->stage_uniform.terrain.terrainSettings.tile_offset[0]); ImGui::DragFloat2("Tile Noise Scale", &this->stage_uniform.terrain.terrainSettings.tile_noise_size[0]); @@ -193,12 +196,17 @@ namespace glsample { &this->stage_uniform.terrain.terrainSettings.tile_noise_offset[0]); ImGui::DragInt2("Size ", &this->stage_uniform.terrain.terrainSettings.size[0]); + ImGui::TextUnformatted("Ocean Settings"); + ImGui::Checkbox("Show Ocean", &this->showOcean); + /* */ ImGui::TextUnformatted("Debug"); ImGui::Checkbox("WireFrame", &this->showWireFrame); } bool showWireFrame = false; + bool showOcean = true; + bool showTerrain = true; private: struct uniform_buffer_block &stage_uniform; @@ -245,15 +253,15 @@ namespace glsample { glUniform1i(glGetUniformLocation(this->terrain_program, "DiffuseTexture"), TextureType::Diffuse); glUniform1i(glGetUniformLocation(this->terrain_program, "NormalTexture"), TextureType::Normal); glUniform1i(glGetUniformLocation(this->terrain_program, "Displacement"), TextureType::Displacement); - glUniform1i(glGetUniformLocation(this->terrain_program, "Irradiance"), TextureType::Irradiance); + glUniform1i(glGetUniformLocation(this->terrain_program, "IrradianceTexture"), TextureType::Irradiance); glUniformBlockBinding(this->terrain_program, uniform_buffer_index, this->uniform_buffer_binding); glUseProgram(0); /* */ glUseProgram(this->ocean_program); - glUniform1i(glGetUniformLocation(this->ocean_program, "DiffuseTexture"), TextureType::Diffuse); + glUniform1i(glGetUniformLocation(this->ocean_program, "DepthTexture"), TextureType::DepthBuffer); glUniform1i(glGetUniformLocation(this->ocean_program, "NormalTexture"), TextureType::Normal); - glUniform1i(glGetUniformLocation(this->ocean_program, "Irradiance"), TextureType::Irradiance); + glUniform1i(glGetUniformLocation(this->ocean_program, "IrradianceTexture"), TextureType::Irradiance); uniform_buffer_index = glGetUniformBlockIndex(this->ocean_program, "UniformBufferBlock"); glUniformBlockBinding(this->ocean_program, uniform_buffer_index, this->uniform_buffer_binding); glUseProgram(0); @@ -312,33 +320,15 @@ namespace glsample { glBindTexture(GL_TEXTURE_2D, 0); } + /* */ ProcessData util(this->getFileSystem()); util.computeIrradiance(this->skybox.getTexture(), this->irradiance_texture, 256, 128); - /* Load geometry. */ - { + this->mistprocessing.initialize(this->getFileSystem()); - Common::loadPlan(this->terrain, 1, 10, 10); - Common::loadCube(this->ocean_volume, 1, 1, 1); - - /* Update terrain height. */ - // glBindBuffer(GL_ARRAY_BUFFER, this->terrain.vbo); - // ProceduralGeometry::Vertex *vertices = (ProceduralGeometry::Vertex *)glMapBufferRange( - // GL_ARRAY_BUFFER, 0, this->terrain.nrVertices * sizeof(vertices[0]), - // GL_MAP_WRITE_BIT | GL_MAP_READ_BIT); - - // /* Create Terrain Mesh Displacement. */ - // float noiseScale = 5; - // for (size_t i = 0; i < terrain.nrVertices; i++) { - // float height = 0; - // height += - // Math::PerlinNoise(vertices[i].vertex[0] * noiseScale, vertices[i].vertex[1] * noiseScale) * - // 0.001f; - // height += Math::PerlinNoise(vertices[i].vertex[0] * 0.1, vertices[i].vertex[1] * 0.1) * 0.006; - // // vertices[i].vertex[2] = height * 0.1f; - // } - // glUnmapBuffer(GL_ARRAY_BUFFER); - } + /* Load geometry. */ + Common::loadPlan(this->terrain, 1, 10, 10); + Common::loadPlan(this->ocean_water, 20, 1, 1); } void onResize(int width, int height) override { this->camera.setAspect((float)width / (float)height); } @@ -351,22 +341,27 @@ namespace glsample { /* */ glViewport(0, 0, width, height); glClearColor(0.15f, 0.15f, 0.15f, 1.0f); + + glDepthMask(GL_TRUE); //? Why needed? + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Terrain. */ - { + if (this->terrainSettingComponent->showTerrain) { /* */ glBindBufferRange(GL_UNIFORM_BUFFER, this->uniform_buffer_binding, this->uniform_buffer, (this->getFrameCount() % nrUniformBuffer) * this->uniformAlignBufferSize, this->uniformAlignBufferSize); - glDisable(GL_CULL_FACE); + /* Draw terrain. */ + glUseProgram(this->terrain_program); + + glEnable(GL_CULL_FACE); glDisable(GL_BLEND); + glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); - - /* Draw terrain. */ - glUseProgram(this->terrain_program); + glDepthFunc(GL_LESS); /* Optional - to display wireframe. */ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); @@ -390,10 +385,12 @@ namespace glsample { glDrawElements(GL_PATCHES, this->terrain.nrIndicesElements, GL_UNSIGNED_INT, nullptr); + /* Render wireframe. */ if (this->terrainSettingComponent->showWireFrame) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glDepthFunc(GL_LEQUAL); + /* */ glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, this->color_texture); @@ -412,7 +409,7 @@ namespace glsample { this->skybox.Render(this->camera); // Ocean/Water - { + if (this->terrainSettingComponent->showOcean) { /* */ glBindBufferRange(GL_UNIFORM_BUFFER, this->uniform_buffer_binding, this->uniform_buffer, (this->getFrameCount() % nrUniformBuffer) * this->uniformAlignBufferSize, @@ -420,18 +417,29 @@ namespace glsample { /* */ glEnable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); + glDepthFunc(GL_LESS); + glDisable(GL_CULL_FACE); /* Blending. */ glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + + /* */ + glActiveTexture(GL_TEXTURE0 + TextureType::DepthBuffer); + glBindTexture(GL_TEXTURE_2D, this->getFrameBuffer()->depthbuffer); glUseProgram(this->ocean_program); - glBindVertexArray(this->ocean_volume.vao); - glDrawElements(GL_TRIANGLES, ocean_volume.nrIndicesElements, GL_UNSIGNED_INT, nullptr); + glBindVertexArray(this->ocean_water.vao); + glDrawElements(GL_TRIANGLES, this->ocean_water.nrIndicesElements, GL_UNSIGNED_INT, nullptr); glBindVertexArray(0); glUseProgram(0); } + + /* Post processing. */ + this->mistprocessing.render(this->irradiance_texture, this->getFrameBuffer()->attachement0, + this->getFrameBuffer()->depthbuffer); } void update() override { @@ -474,7 +482,7 @@ namespace glsample { TerrainGLSample() : GLSample() {} void customOptions(cxxopts::OptionAdder &options) override { options("S,skybox", "Skybox Texture File Path", - cxxopts::value()->default_value("asset/snowy_forest_4k.exr")); + cxxopts::value()->default_value("asset/industrial_sunset_puresky_4k.exr")); } }; } // namespace glsample diff --git a/Samples/VariableRateShading/VariableRateShading.cpp b/Samples/VariableRateShading/VariableRateShading.cpp index b6be81b..e089c3c 100644 --- a/Samples/VariableRateShading/VariableRateShading.cpp +++ b/Samples/VariableRateShading/VariableRateShading.cpp @@ -25,25 +25,25 @@ namespace glsample { glm::mat4 modelView; glm::mat4 modelViewProjection; - } uniformBuffer; + } uniformBuffer{}; - unsigned int variable_rate_program; - int localWorkGroupSize[3]; - unsigned int variable_rate_lut_texture; + unsigned int variable_rate_program{}; + int localWorkGroupSize[3]{}; + unsigned int variable_rate_lut_texture{}; /* G-Buffer */ - unsigned int multipass_framebuffer; + unsigned int multipass_framebuffer{}; unsigned int nthTexture = 0; - unsigned int multipass_texture_width; - unsigned int multipass_texture_height; + unsigned int multipass_texture_width{}; + unsigned int multipass_texture_height{}; std::vector multipass_textures; - unsigned int depthTexture; + unsigned int depthTexture{}; /* */ - unsigned int uniform_buffer_index; + unsigned int uniform_buffer_index{}; unsigned int uniform_buffer_binding = 0; - unsigned int uniform_buffer; + unsigned int uniform_buffer{}; const size_t nrUniformBuffer = 3; size_t uniformAlignBufferSize = sizeof(uniform_buffer_block); diff --git a/Samples/VectorField2D/VectorField2D.cpp b/Samples/VectorField2D/VectorField2D.cpp index faa3119..3c06a8e 100644 --- a/Samples/VectorField2D/VectorField2D.cpp +++ b/Samples/VectorField2D/VectorField2D.cpp @@ -496,7 +496,7 @@ namespace glsample { this->getSize(&width, &height); /* */ - glClearColor(0.08f, 0.08f, 0.08f, 1.0f); + glClearColor(0.05f, 0.05f, 0.05f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* */ glViewport(0, 0, width, height); @@ -517,11 +517,7 @@ namespace glsample { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindVertexArray(this->particles.vao); - // glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Particle), - // reinterpret_cast(read_buffer_index * this->ParticleMemorySize)); - // glVertexAttribPointer( - // 1, 4, GL_FLOAT, GL_FALSE, sizeof(Particle), - // reinterpret_cast(read_buffer_index * this->ParticleMemorySize + sizeof(glm::vec4))); + glDrawArrays(GL_POINTS, 0, this->uniformStageBuffer.particleSetting.nrparticles); glBindVertexArray(0); @@ -553,11 +549,7 @@ namespace glsample { /* Draw triangle. */ glBindVertexArray(this->particles.vao); - // glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Particle), - // reinterpret_cast(read_buffer_index * this->ParticleMemorySize)); - // glVertexAttribPointer( - // 1, 4, GL_FLOAT, GL_FALSE, sizeof(Particle), - // reinterpret_cast(read_buffer_index * this->ParticleMemorySize + sizeof(glm::vec4))); + glDrawArrays(GL_POINTS, 0, this->uniformStageBuffer.particleSetting.nrparticles); glBindVertexArray(0); diff --git a/Samples/VideoPlayback/videoplayback.cpp b/Samples/VideoPlayback/videoplayback.cpp index 9c2fc8d..ac5d478 100644 --- a/Samples/VideoPlayback/videoplayback.cpp +++ b/Samples/VideoPlayback/videoplayback.cpp @@ -253,7 +253,7 @@ namespace glsample { this->audio_bit_rate = pAudioCodecParam->bit_rate; this->audio_sample_rate = pAudioCodecParam->sample_rate; - this->audio_channel = pAudioCodecParam->channels; + this->audio_channel = pAudioCodecParam->ch_layout.nb_channels; } AVCodecParameters *pVideoCodecParam = video_st->codecpar; diff --git a/Shaders/ambientocclusion/ambientocclusion.frag b/Shaders/ambientocclusion/ambientocclusion.frag index 27fb8f8..a305ede 100644 --- a/Shaders/ambientocclusion/ambientocclusion.frag +++ b/Shaders/ambientocclusion/ambientocclusion.frag @@ -47,7 +47,7 @@ void main() { /* */ float occlusion = 0.0; - for (int i = 0; i < samples; i++) { + for (uint i = 0; i < samples; i++) { /* from tangent to view-space */ const vec3 sampleWorldDir = TBN * ubo.kernel[i].xyz; diff --git a/Shaders/ambientocclusion/ambientocclusion_depthonly.frag b/Shaders/ambientocclusion/ambientocclusion_depthonly.frag index a1917cf..9e6923f 100644 --- a/Shaders/ambientocclusion/ambientocclusion_depthonly.frag +++ b/Shaders/ambientocclusion/ambientocclusion_depthonly.frag @@ -66,7 +66,7 @@ void main() { float occlusion = 0.0; - for (int i = 0; i < ubo.samples; i++) { + for (uint i = 0; i < ubo.samples; i++) { /* from tangent to view-space */ const vec3 sampleWorldDir = TBN * ubo.kernel[i].xyz; diff --git a/Shaders/circlepacking/circlepacking.comp b/Shaders/circlepacking/circlepacking.comp index d4227fd..3e35421 100644 --- a/Shaders/circlepacking/circlepacking.comp +++ b/Shaders/circlepacking/circlepacking.comp @@ -45,7 +45,7 @@ void main() { /* Determine if it can grow. */ int canGrow = 1; - for (int i = 0; i < ubo.nrGrowing; i++) { + for (uint i = 0; i < ubo.nrGrowing; i++) { Circle circle = previous_circle_state.circles[i]; if (circle.radius < current_circle.radius) { canGrow = 0 * canGrow; diff --git a/Shaders/common/colorspace.glsl b/Shaders/common/colorspace.glsl new file mode 100644 index 0000000..b8c446d --- /dev/null +++ b/Shaders/common/colorspace.glsl @@ -0,0 +1,44 @@ +#ifndef _COMMON_COLORSPACE_H_ +#define _COMMON_COLORSPACE_H_ 1 + +vec3 hsv2rgb(const in vec3 c) { + const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + const vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + +vec3 acesFilm(const in vec3 x) { + const float a = 2.51; + const float b = 0.03; + const float c = 2.43; + const float d = 0.59; + const float e = 0.14; + return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0); +} + +float RGB2Luminance(const in vec3 rgb) { return dot(vec3(0.2126, 0.7152, 0.0722), rgb); } + +// Input color is non-negative and resides in the Linear Rec. 709 color space. +// Output color is also Linear Rec. 709, but in the [0, 1] range. + +vec3 PBRNeutralToneMapping(in vec3 color) { + const float startCompression = 0.8 - 0.04; + const float desaturation = 0.15; + + float x = min(color.r, min(color.g, color.b)); + float offset = x < 0.08 ? x - 6.25 * x * x : 0.04; + color -= offset; + + float peak = max(color.r, max(color.g, color.b)); + if (peak < startCompression) + return color; + + const float d = 1. - startCompression; + float newPeak = 1. - d * d / (peak + d - startCompression); + color *= newPeak / peak; + + float g = 1. - 1. / (desaturation * (peak - newPeak) + 1.); + return mix(color, newPeak * vec3(1, 1, 1), g); +} + +#endif \ No newline at end of file diff --git a/Shaders/common/common.glsl b/Shaders/common/common.glsl index 8c11414..d0492b9 100644 --- a/Shaders/common/common.glsl +++ b/Shaders/common/common.glsl @@ -1,4 +1,6 @@ -#include "fog.glsl" +#ifndef _COMMON_HEADER_ +#define _COMMON_HEADER_ 1 +#include "colorspace.glsl" #include "noise.glsl" // enum GBuffer : unsigned int { @@ -14,7 +16,7 @@ /* Constants. */ #define PI 3.1415926535897932384626433832795 #define PI_HALF 1.5707963267948966192313216916398 -layout(constant_id = 0) const float EPSILON = 0.00001; +layout(constant_id = 0) const float EPSILON = 1.19209e-07; struct Camera { float near; @@ -26,6 +28,25 @@ struct Camera { vec4 position_size; }; +struct FogSettings { + /* */ + vec4 fogColor; + /* */ + float CameraNear; + float CameraFar; + float fogStart; + float fogEnd; + /* */ + float fogDensity; + uint fogType; + float fogItensity; + float fogHeight; +}; + +struct Frustum { + vec4 planes; +}; + vec4 bump(const in sampler2D BumpTexture, const in vec2 uv, const in float dist) { const vec2 size = vec2(2.0, 0.0); @@ -55,6 +76,20 @@ vec4 bump(const in sampler2D BumpTexture, const in vec2 uv, const in float dist) return normal; } +vec4 bump(const in float height, const in float dist) { + + const float x = 0; // dFdx(height) * dist; + const float y = 0; // dFdy(height) * dist; + + const vec4 normal = vec4(x, y, 1, 0); + + return normalize(normal); +} + +float getExpToLinear(const in float start, const in float end, const in float expValue) { + return ((2.0f * start) / (end + start - expValue * (end - start))); +} + float rand(const in float seed) { return fract(sin(seed) * 100000.0); } float rand(const in vec2 co) { return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); } @@ -62,8 +97,7 @@ float rand(const in vec2 co) { return fract(sin(dot(co.xy, vec2(12.9898, 78.233) vec3 equirectangular(const in vec2 xy) { const vec2 tc = xy / vec2(2.0) - 0.5; - const vec2 thetaphi = - ((tc * 2.0) - vec2(1.0)) * vec2(3.1415926535897932384626433832795, 1.5707963267948966192313216916398); + const vec2 thetaphi = ((tc * 2.0) - vec2(1.0)) * vec2(PI, PI_HALF); const vec3 rayDirection = vec3(cos(thetaphi.y) * cos(thetaphi.x), sin(thetaphi.y), cos(thetaphi.y) * sin(thetaphi.x)); @@ -82,10 +116,15 @@ vec3 fresnelSchlickRoughness(const in float cosTheta, const in vec3 F0, const in return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0); } -vec3 FresnelSchlick(const vec3 SpecularColor, const vec3 E, const vec3 H) { - return SpecularColor + (1.0f - SpecularColor) * pow(1.0f - clamp(dot(E, H), 0, 1), 5); +vec3 FresnelSchlick(const in vec3 F0, const in vec3 V, const in vec3 N) { + const float cosTheta = max(dot(N, V), 0.0); + const float power = 5.0; + const float fresnel_ratio = pow(1.0 - cosTheta, power); + return mix(F0, vec3(1.0), fresnel_ratio); } +vec3 FresnelSteinberg(const in vec3 F0, const in vec3 V, const in vec3 N) { return vec3(0); } + /** * */ @@ -109,17 +148,96 @@ vec2 getParallax(const in sampler2D heightMap, const in vec2 uv, const in vec3 c return (uv + (cameraDir.xy * v)).xy; } -vec3 hsv2rgb(const in vec3 c) { - const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - const vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); - return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +#define CLAMP01(T) clamp((T), 0.0, 1.0) +#define EASE(T) smoothstep(0.0, 1.0, (T)) + +vec3 CatmulRom(in float T, vec3 D, vec3 C, vec3 B, vec3 A) { + return 0.5 * ((2.0 * B) + (-A + C) * T + (2.0 * A - 5.0 * B + 4.0 * C - D) * T * T + + (-A + 3.0 * B - 3.0 * C + D) * T * T * T); +} + +vec3 ColorRampConstant(in float T, const in vec4[4] A, const in int num) { + //[[unroll]] + for (uint i = 0; i < num; i++) { + if (T < A[i].w) { + return A[i].rgb; + } + } +} + +vec3 ColorRampLinear(in float T, const in vec4[4] Ramp, const in int num) { + + // for (uuint i = 0; i < num; i++) { + // if (T < A[i].w) { + // // return A[i].rgb; + // } + // } + vec4 A = Ramp[0]; + vec4 B = Ramp[1]; + vec4 C = Ramp[2]; + vec4 D = Ramp[3]; + + // Distances = + float AB = B.w - A.w; + float BC = C.w - B.w; + float CD = D.w - C.w; + + // Intervales : + float iAB = CLAMP01((T - A.w) / AB); + float iBC = CLAMP01((T - B.w) / BC); + float iCD = CLAMP01((T - C.w) / CD); + + // Pondérations : + float pA = 1.0 - iAB; + float pB = iAB - iBC; + float pC = iBC - iCD; + float pD = iCD; + + return pA * A.xyz + pB * B.xyz + pC * C.xyz + pD * D.xyz; +} + +vec3 ColorRamp_Smoothstep(in float T, vec4 A, in vec4 B, in vec4 C, in vec4 D) { + // Distances = + float AB = B.w - A.w; + float BC = C.w - B.w; + float CD = D.w - C.w; + + // Intervales : + float iAB = CLAMP01((T - A.w) / AB); + float iBC = CLAMP01((T - B.w) / BC); + float iCD = CLAMP01((T - C.w) / CD); + + // Pondérations : + vec4 p = vec4(1.0 - iAB, iAB - iBC, iBC - iCD, iCD); + p = EASE(p); + return p.x * A.xyz + p.y * B.xyz + p.z * C.xyz + p.w * D.xyz; +} + +vec3 ColorRamp_BSpline(in float T, vec4 A, in vec4 B, in vec4 C, in vec4 D) { + // Distances = + float AB = B.w - A.w; + float BC = C.w - B.w; + float CD = D.w - C.w; + + // Intervales : + float iAB = CLAMP01((T - A.w) / AB); + float iBC = CLAMP01((T - B.w) / BC); + float iCD = CLAMP01((T - C.w) / CD); + + // Pondérations : + vec4 p = vec4(1.0 - iAB, iAB - iBC, iBC - iCD, iCD); + vec3 cA = CatmulRom(p.x, A.xyz, A.xyz, B.xyz, C.xyz); + vec3 cB = CatmulRom(p.y, A.xyz, B.xyz, C.xyz, D.xyz); + vec3 cC = CatmulRom(p.z, B.xyz, C.xyz, D.xyz, D.xyz); + vec3 cD = D.xyz; + + if (T < B.w) + return cA.xyz; + if (T < C.w) + return cB.xyz; + if (T < D.w) + return cC.xyz; + return cD.xyz; } -vec3 acesFilm(const vec3 x) { - const float a = 2.51; - const float b = 0.03; - const float c = 2.43; - const float d = 0.59; - const float e = 0.14; - return clamp((x * (a * x + b)) / (x * (c * x + d ) + e), 0.0, 1.0); -} \ No newline at end of file +#endif \ No newline at end of file diff --git a/Shaders/common/fog.glsl b/Shaders/common/fog.glsl deleted file mode 100644 index 4073959..0000000 --- a/Shaders/common/fog.glsl +++ /dev/null @@ -1,18 +0,0 @@ -struct FogSettings { - /* */ - vec4 fogColor; - /* */ - float CameraNear; - float CameraFar; - float fogStart; - float fogEnd; - /* */ - float fogDensity; - uint fogType; - float fogItensity; - float fogHeight; -}; - -float getExpToLinear(const in float start, const in float end, const in float expValue) { - return ((2.0f * start) / (end + start - expValue * (end - start))); -} diff --git a/Shaders/common/fog_frag.glsl b/Shaders/common/fog_frag.glsl index 5523082..77d85d5 100644 --- a/Shaders/common/fog_frag.glsl +++ b/Shaders/common/fog_frag.glsl @@ -1,7 +1,8 @@ #ifndef FOG_FRAG_ #define FOG_FRAG_ 1 +#include "common.glsl" -float getFogFactor(const in FogSettings fog_settings) { +float getFogFactor(const in FogSettings fog_settings, const float depth) { const float near = fog_settings.CameraNear; const float far = fog_settings.CameraFar; @@ -10,7 +11,7 @@ float getFogFactor(const in FogSettings fog_settings) { const float startFog = fog_settings.fogStart / (far - near); const float densityFog = fog_settings.fogDensity; - const float z = getExpToLinear(near, far, gl_FragCoord.z); + const float z = getExpToLinear(near, far, depth); switch (fog_settings.fogType) { case 1: @@ -31,6 +32,8 @@ float getFogFactor(const in FogSettings fog_settings) { } } +float getFogFactor(const in FogSettings fog_settings) { return getFogFactor(fog_settings, gl_FragCoord.z); } + vec4 blendFog(const in vec4 color, const in FogSettings fogSettings) { const float fog_factor = getFogFactor(fogSettings); diff --git a/Shaders/common/light.glsl b/Shaders/common/light.glsl index 47f99cb..2acaf1f 100644 --- a/Shaders/common/light.glsl +++ b/Shaders/common/light.glsl @@ -3,7 +3,6 @@ struct DirectionalLight { vec4 direction; - //float intensity; vec4 lightColor; }; diff --git a/Shaders/common/pbr.glsl b/Shaders/common/pbr.glsl new file mode 100644 index 0000000..600fe66 --- /dev/null +++ b/Shaders/common/pbr.glsl @@ -0,0 +1,6 @@ +#ifndef _COMMON_PBR_H_ +#define _COMMON_PBR_H_ 1 + +#include "light.glsl" + +#endif \ No newline at end of file diff --git a/Shaders/compute/irradiance_env.comp b/Shaders/compute/irradiance_env.comp index f757480..1f081c3 100644 --- a/Shaders/compute/irradiance_env.comp +++ b/Shaders/compute/irradiance_env.comp @@ -27,7 +27,7 @@ void main() { const vec2 normalized_uv_coords = vec2(pixel_coords) / vec2(imageSize(targetIrradianceTexture)); // TODO: improve mapping. - const vec3 direction = -equirectangular(normalized_uv_coords); + const vec3 direction = -equirectangular(1 - normalized_uv_coords); vec3 irradiance = vec3(0.0); diff --git a/Shaders/culling/culling_aabb.comp b/Shaders/culling/culling_aabb.comp index b4c85de..da822af 100644 --- a/Shaders/culling/culling_aabb.comp +++ b/Shaders/culling/culling_aabb.comp @@ -59,7 +59,7 @@ void main() { const AABB instance = aabb.aabb[aabb_index]; uint count = 0; - [[unroll]] for (int i = 0; i < nrPlanees; i++) { + [[unroll]] for (uint i = 0; i < nrPlanees; i++) { /* */ count += intersectionAABB(ubo.planes[i], instance); diff --git a/Shaders/culling/culling_aabb_indirect.comp b/Shaders/culling/culling_aabb_indirect.comp index ae17b32..06ccbe6 100644 --- a/Shaders/culling/culling_aabb_indirect.comp +++ b/Shaders/culling/culling_aabb_indirect.comp @@ -46,7 +46,7 @@ void main() { const ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy); const int nrPlanes = 6; - [[unroll]] for (int i = 0; i < nrPlanes; i++) { + [[unroll]] for (uint i = 0; i < nrPlanes; i++) { if (intersectionAABB(vec3(0), vec3(0)) == 0) { // Assign diff --git a/Shaders/culling/culling_sphere.comp b/Shaders/culling/culling_sphere.comp index fb630c9..895c77f 100644 --- a/Shaders/culling/culling_sphere.comp +++ b/Shaders/culling/culling_sphere.comp @@ -51,7 +51,7 @@ void main() { } int count = 0; - [[unroll]] for (int i = 0; i < nrPlanees; i++) { + [[unroll]] for (uint i = 0; i < nrPlanees; i++) { const vec3 sphere_center = instance_sphere.sphere[aabb_index].center; const float radius = instance_sphere.sphere[aabb_index].radius; diff --git a/Shaders/mandelbrot/julia.comp b/Shaders/mandelbrot/julia.comp index 9b1963d..a9158b7 100644 --- a/Shaders/mandelbrot/julia.comp +++ b/Shaders/mandelbrot/julia.comp @@ -38,7 +38,7 @@ vec4 computeMandel(in vec2 uv) { const float max_range = lthreadhold * lthreadhold; - int i = 0; + uint i = 0; for (; i < samples; i++) { z = squareImaginary(z) + c + uv; diff --git a/Shaders/mandelbrot/mandelbrot.comp b/Shaders/mandelbrot/mandelbrot.comp index 3301218..529fbaa 100644 --- a/Shaders/mandelbrot/mandelbrot.comp +++ b/Shaders/mandelbrot/mandelbrot.comp @@ -38,7 +38,7 @@ vec4 computeMandel(in vec2 uv) { z = vec2(0); const float max_range = lthreadhold * lthreadhold; - int i = 0; + uint i = 0; for (; i < samples; i++) { z = squareImaginary(z) + c + uv; diff --git a/Shaders/normal/normal-triangle.geom b/Shaders/normal/normal-triangle.geom index b10e396..bdaa4b1 100644 --- a/Shaders/normal/normal-triangle.geom +++ b/Shaders/normal/normal-triangle.geom @@ -36,7 +36,7 @@ void main() { 0.5 * (gl_in[0].gl_Position.xyz - gl_in[2].gl_Position.xyz); const int NrPoints = 3; - [[unroll]] for (int i = 0; i < NrPoints; i++) { + [[unroll]] for (uint i = 0; i < NrPoints; i++) { gl_Position = ubo.ViewProj * vec4(triangle_center, 1.0); normalColor = axisColor[i]; EmitVertex(); diff --git a/Shaders/normal/normal.geom b/Shaders/normal/normal.geom index 53a9dda..79a2a54 100644 --- a/Shaders/normal/normal.geom +++ b/Shaders/normal/normal.geom @@ -30,7 +30,7 @@ void main() { const vec3 axis[3] = {normal[0], tangent[0], cross(normalize(tangent[0]), normalize(normal[0]))}; const vec4 axisColor[3] = {vec4(0, 0, 1, 0.8), vec4(1, 0, 0, 0.8), vec4(0, 1, 0, 0.8)}; - [[unroll]] for (int i = 0; i < 3; i++) { + [[unroll]] for (uint i = 0; i < 3; i++) { gl_Position = ubo.ViewProj * vec4(gl_in[0].gl_Position.xyz, 1.0); normalColor = axisColor[i]; EmitVertex(); diff --git a/Shaders/ocean/ocean.frag b/Shaders/ocean/ocean.frag index a1beb0a..2fba41f 100644 --- a/Shaders/ocean/ocean.frag +++ b/Shaders/ocean/ocean.frag @@ -8,17 +8,12 @@ layout(location = 0) out vec4 fragColor; layout(location = 1) in vec4 velocity; layout(location = 2) in vec2 normal; - /* Include common. */ -#include"ocean_base.glsl" +#include "ocean_base.glsl" layout(binding = 1) uniform sampler2D PanoramaTexture; - - void main() { - // Physical based rendering. - - - fragColor = vec4(1,1,1,1); + // Physical based rendering. + fragColor = vec4(1, 1, 1, 1); } \ No newline at end of file diff --git a/Shaders/ocean/ocean.tese b/Shaders/ocean/ocean.tese index 4da18b5..77d6189 100644 --- a/Shaders/ocean/ocean.tese +++ b/Shaders/ocean/ocean.tese @@ -15,8 +15,7 @@ layout(location = 1) out vec2 TexCoord_FS_in; layout(location = 2) out vec3 Normal_FS_in; /* Include common. */ -#include"ocean_base.glsl" - +#include "ocean_base.glsl" layout(binding = 2) uniform sampler2D gDisplacementMap; diff --git a/Shaders/ocean/ocean_base.glsl b/Shaders/ocean/ocean_base.glsl index 547a89b..e6e2ad8 100644 --- a/Shaders/ocean/ocean_base.glsl +++ b/Shaders/ocean/ocean_base.glsl @@ -1,3 +1,5 @@ +#include "common.glsl" + struct particle_t { vec2 h0; vec2 ht_real_img; @@ -35,5 +37,3 @@ layout(binding = 0) uniform UniformBufferBlock { float tessLevel; } ubo; - -const float PI = 3.14; \ No newline at end of file diff --git a/Shaders/panoramic/panoramic.geom b/Shaders/panoramic/panoramic.geom index 50076cb..35375a0 100644 --- a/Shaders/panoramic/panoramic.geom +++ b/Shaders/panoramic/panoramic.geom @@ -48,7 +48,7 @@ void main() { [[unroll]] for (int face = 0; face < NrLayers; ++face) { gl_Layer = face; // built-in variable that specifies to which face we render. - [[unroll]] for (int i = 0; i < NrFaces; ++i) // for each triangle vertex + [[unroll]] for (uint i = 0; i < NrFaces; ++i) // for each triangle vertex { OutVertex = gl_in[i].gl_Position.xyz; gl_Position = (ubo.ViewProjection[gl_Layer]) * gl_in[i].gl_Position; diff --git a/Shaders/pbr/physicalbasedrendering.frag b/Shaders/pbr/physicalbasedrendering.frag index 62d7ccd..5f72633 100644 --- a/Shaders/pbr/physicalbasedrendering.frag +++ b/Shaders/pbr/physicalbasedrendering.frag @@ -107,7 +107,7 @@ void main() { // reflectance equation vec3 Lo = vec3(0.0); - for (int i = 0; i < 4; ++i) { + for (uint i = 0; i < 4; ++i) { // calculate per-light radiance vec3 L = normalize(ubo.lightsettings.point_light[i].position - WorldPos); vec3 H = normalize(V + L); diff --git a/Shaders/pbr/physicalbasedrendering.geom b/Shaders/pbr/physicalbasedrendering.geom index 1f04258..ac37038 100644 --- a/Shaders/pbr/physicalbasedrendering.geom +++ b/Shaders/pbr/physicalbasedrendering.geom @@ -21,7 +21,7 @@ void main() { [[unroll]] for (int face = 0; face < NRFaces; ++face) { gl_Layer = face; // built-in variable that specifies to which face we render. - [[unroll]] for (int i = 0; i < 3; ++i) // for each triangle vertex + [[unroll]] for (uint i = 0; i < 3; ++i) // for each triangle vertex { FragVertex = gl_in[i].gl_Position; // FIndex = GIndex[i]; diff --git a/Shaders/pbr/physicalbasedrendering.tesc b/Shaders/pbr/physicalbasedrendering.tesc index 9c706c8..b8dfc57 100644 --- a/Shaders/pbr/physicalbasedrendering.tesc +++ b/Shaders/pbr/physicalbasedrendering.tesc @@ -75,7 +75,7 @@ float GetTessLevel(float Distance0, float Distance1) { void main() { // Set the control points of the output patch - for (int i = 0; i < 3; i++) { + for (uint i = 0; i < 3; i++) { oPatch.Normal[i] = Normal_CS_in[i]; oPatch.TexCoord[i] = TexCoord_CS_in[i]; } diff --git a/Shaders/phongblinn/blinn.frag b/Shaders/phongblinn/blinn.frag index decd8be..2742c12 100644 --- a/Shaders/phongblinn/blinn.frag +++ b/Shaders/phongblinn/blinn.frag @@ -47,7 +47,7 @@ void main() { vec4 pointLightColors = vec4(0); vec4 pointLightSpecular = vec4(0); - [[unroll]] for (int i = 0; i < NR_LIGHTS; i++) { + [[unroll]] for (uint i = 0; i < NR_LIGHTS; i++) { const vec3 diffVertex = (ubo.point_light[i].position - vertex); const vec3 lightDir = normalize(diffVertex); diff --git a/Shaders/phongblinn/blinn_directional_light.frag b/Shaders/phongblinn/blinn_directional_light.frag index 3cd2e5d..7e93757 100644 --- a/Shaders/phongblinn/blinn_directional_light.frag +++ b/Shaders/phongblinn/blinn_directional_light.frag @@ -18,6 +18,7 @@ layout(binding = 0, std140) uniform UniformBufferBlock { /* Light source. */ vec4 direction; vec4 lightColor; + /* */ vec4 specularColor; vec4 ambientColor; vec4 viewDir; @@ -35,7 +36,7 @@ void main() { // Compute directional light vec4 pointLightSpecular = vec4(0); - /* Blinn */ + /* Blinn/Phong */ const vec3 halfwayDir = normalize(ubo.direction.xyz + viewDir); const float spec = pow(max(dot(normal, halfwayDir), 0.0), ubo.shininess); float contriubtion = max(0.0, dot(-normalize(ubo.direction.xyz), normalize(normal))); diff --git a/Shaders/phongblinn/phong.frag b/Shaders/phongblinn/phong.frag index a37bc1a..ebae09f 100644 --- a/Shaders/phongblinn/phong.frag +++ b/Shaders/phongblinn/phong.frag @@ -47,7 +47,7 @@ void main() { vec4 pointLightColors = vec4(0); vec4 pointLightSpecular = vec4(0); - [[unroll]] for (int i = 0; i < NR_LIGHTS; i++) { + [[unroll]] for (uint i = 0; i < NR_LIGHTS; i++) { const vec3 diffVertex = (ubo.point_light[i].position - vertex); const vec3 lightDir = normalize(diffVertex); diff --git a/Shaders/pointlights/pointlights.frag b/Shaders/pointlights/pointlights.frag index 0fb3403..723cf37 100644 --- a/Shaders/pointlights/pointlights.frag +++ b/Shaders/pointlights/pointlights.frag @@ -25,8 +25,9 @@ layout(binding = 0, std140) uniform UniformBufferBlock { mat4 modelView; mat4 modelViewProjection; - /* Light source. */ + /* */ vec4 ambientColor; + /* Light source. */ point_light point_light[4]; } ubo; @@ -38,7 +39,7 @@ void main() { vec4 pointLightColors = vec4(0); /* Compute directional light */ - [[unroll]] for (int i = 0; i < 4; i++) { + [[unroll]] for (uint i = 0; i < 4; i++) { const vec3 diffVertex = (ubo.point_light[i].position - vertex); const float dist = length(diffVertex); diff --git a/Shaders/pointlights/pointlights.vert b/Shaders/pointlights/pointlights.vert index 4a81e84..e5faabb 100644 --- a/Shaders/pointlights/pointlights.vert +++ b/Shaders/pointlights/pointlights.vert @@ -25,8 +25,10 @@ layout(binding = 0, std140) uniform UniformBufferBlock { mat4 proj; mat4 modelView; mat4 modelViewProjection; - /* Light source. */ + + /* */ vec4 ambientColor; + /* Light source. */ point_light point_light[4]; } ubo; diff --git a/Shaders/postprocessingeffects/bloom.frag b/Shaders/postprocessingeffects/bloom.frag new file mode 100644 index 0000000..3b57925 --- /dev/null +++ b/Shaders/postprocessingeffects/bloom.frag @@ -0,0 +1,32 @@ +#version 460 +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable + +/* */ +layout(location = 0) out vec4 fragColor; +/* */ +layout(location = 0) in vec2 uv; + +/* */ +layout(set = 0, binding = 0) uniform sampler2D texture0; +layout(set = 0, binding = 1) uniform sampler2D depth0; +layout(set = 0, binding = 2) uniform sampler2D IrradianceTexture; + +#include "fog.glsl" +#include "fog_frag.glsl" +#include "postprocessing_base.glsl" + +layout(set = 0, binding = 0, std140) uniform UniformBufferBlock { + mat4 proj; + mat4 modelViewProjection; + vec4 tintColor; + FogSettings fogSettings; +} +ubo; + +void main() { + // getFogFactor() + + fragColor = texture(texture0, uv) * 1.2; +} diff --git a/Shaders/postprocessingeffects/colorspace/KhronosPBRNeutral.comp b/Shaders/postprocessingeffects/colorspace/KhronosPBRNeutral.comp new file mode 100644 index 0000000..afda6af --- /dev/null +++ b/Shaders/postprocessingeffects/colorspace/KhronosPBRNeutral.comp @@ -0,0 +1,30 @@ +#version 460 core +#extension GL_ARB_derivative_control : enable +#extension GL_ARB_enhanced_layouts : enable +#extension GL_ARB_shader_image_load_store : enable +#extension GL_ARB_explicit_attrib_location : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable + +layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; + +layout(set = 0, binding = 1, rgba16f) uniform image2D texture0; + + +#include "colorspace.glsl" + +void main() { + + /* */ + if (any(greaterThan(gl_GlobalInvocationID.xy, imageSize(texture0)))) { + return; + } + + /* Get output fragcolor texture coordinate. */ + const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy); + + vec4 fragColor = imageLoad(texture0, TexCoord); + fragColor.rgb = PBRNeutralToneMapping(fragColor.rgb); + + imageStore(texture0, TexCoord, vec4(fragColor.rgb, 1.0)); +} \ No newline at end of file diff --git a/Shaders/postprocessingeffects/colorspace/aces.comp b/Shaders/postprocessingeffects/colorspace/aces.comp new file mode 100644 index 0000000..816dcd4 --- /dev/null +++ b/Shaders/postprocessingeffects/colorspace/aces.comp @@ -0,0 +1,28 @@ +#version 460 core +#extension GL_ARB_derivative_control : enable +#extension GL_ARB_enhanced_layouts : enable +#extension GL_ARB_shader_image_load_store : enable +#extension GL_ARB_explicit_attrib_location : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable + +layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; + +layout(set = 0, binding = 1, rgba16f) uniform image2D texture0; + +#include "common.glsl" + +void main() { + + /* */ + if (any(greaterThan(gl_GlobalInvocationID.xy, imageSize(texture0)))) { + return; + } + + const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy); + + vec4 fragColor = imageLoad(texture0, TexCoord); + fragColor.rgb = acesFilm(fragColor.rgb); + + imageStore(texture0, TexCoord, vec4(fragColor.rgb, 1.0)); +} \ No newline at end of file diff --git a/Shaders/postprocessingeffects/colorspace/gamma.comp b/Shaders/postprocessingeffects/colorspace/gamma.comp new file mode 100644 index 0000000..27dfaa8 --- /dev/null +++ b/Shaders/postprocessingeffects/colorspace/gamma.comp @@ -0,0 +1,34 @@ +#version 460 core +#extension GL_ARB_derivative_control : enable +#extension GL_ARB_enhanced_layouts : enable +#extension GL_ARB_shader_image_load_store : enable +#extension GL_ARB_explicit_attrib_location : enable + +layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; + +layout(set = 0, binding = 1, rgba16f) uniform image2D texture0; + +layout(push_constant) uniform Settings { + layout(offset = 0) float exposure; + layout(offset = 4) float gamma; +} +settings; + +void main() { + + /* */ + if (any(greaterThan(gl_GlobalInvocationID.xy, imageSize(texture0)))) { + return; + } + + // Get output fragcolor texture coordinate. + const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy); + + vec4 fragColor = imageLoad(texture0, TexCoord); + fragColor = vec4(1.0) - exp(-fragColor * settings.exposure); + + const float gamma = settings.gamma; + fragColor = pow(fragColor, vec4(1.0 / gamma)); + + imageStore(texture0, TexCoord, vec4(fragColor.rgb, 1.0)); +} \ No newline at end of file diff --git a/Shaders/postprocessingeffects/colorspace/heatmap.comp b/Shaders/postprocessingeffects/colorspace/heatmap.comp new file mode 100644 index 0000000..f54b410 --- /dev/null +++ b/Shaders/postprocessingeffects/colorspace/heatmap.comp @@ -0,0 +1,43 @@ +#version 460 core +#extension GL_ARB_derivative_control : enable +#extension GL_ARB_enhanced_layouts : enable +#extension GL_ARB_shader_image_load_store : enable +#extension GL_ARB_explicit_attrib_location : enable + +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable + +layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; + +layout(set = 0, binding = 1, rgba16f) uniform image2D texture0; + +#include "../postprocessing_base.glsl" + +void main() { + + const vec4 ramp[4] = {vec4(0, 0.02, 0.05, 0.086), vec4(0.166239, 0.038374, 0.005713, 0.26), vec4(1, 1, 1, 0.527273), + vec4(0.601909, 0.678011, 1, 1.0)}; + + /* */ + if (any(greaterThan(gl_GlobalInvocationID.xy, imageSize(texture0)))) { + return; + } + + // Get output fragcolor texture coordinate. + const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy); + + vec4 fragColor = imageLoad(texture0, TexCoord); + const float lumen = RGB2Luminance(fragColor.rgb); + + const float minLumen = 0; + const float maxLumen = 5; + + // TODO: fix + const float range = minLumen + maxLumen; + + const float t = clamp(lumen / range, 0, 1); + + const vec3 heatColor = ColorRampLinear(t, ramp, 4); + + imageStore(texture0, TexCoord, vec4(heatColor, 1.0)); +} diff --git a/Shaders/postprocessingeffects/fxaa.comp b/Shaders/postprocessingeffects/fxaa.comp new file mode 100644 index 0000000..3ccd0c3 --- /dev/null +++ b/Shaders/postprocessingeffects/fxaa.comp @@ -0,0 +1,33 @@ +#version 460 core +#extension GL_ARB_derivative_control : enable +#extension GL_ARB_enhanced_layouts : enable +#extension GL_ARB_shader_image_load_store : enable +#extension GL_ARB_explicit_attrib_location : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable + +layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; + +layout(set = 0, binding = 1, rgba16f) uniform image2D texture0; + +#include "common.glsl" + +void main() { + + /* */ + if (any(greaterThan(gl_GlobalInvocationID.xy, imageSize(texture0)))) { + return; + } + + const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy); + + vec4 fragColor = imageLoad(texture0, TexCoord); + fragColor.rgb = acesFilm(fragColor.rgb); + + // fragColor = vec4(1.0) - exp(-fragColor * 1); + + const float gamma = 2.2; + fragColor = pow(fragColor, vec4(1.0 / gamma)); + + imageStore(texture0, TexCoord, vec4(fragColor.rgb, 1.0)); +} \ No newline at end of file diff --git a/Shaders/postprocessingeffects/grayscale.comp b/Shaders/postprocessingeffects/grayscale.comp new file mode 100644 index 0000000..3ccd0c3 --- /dev/null +++ b/Shaders/postprocessingeffects/grayscale.comp @@ -0,0 +1,33 @@ +#version 460 core +#extension GL_ARB_derivative_control : enable +#extension GL_ARB_enhanced_layouts : enable +#extension GL_ARB_shader_image_load_store : enable +#extension GL_ARB_explicit_attrib_location : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable + +layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; + +layout(set = 0, binding = 1, rgba16f) uniform image2D texture0; + +#include "common.glsl" + +void main() { + + /* */ + if (any(greaterThan(gl_GlobalInvocationID.xy, imageSize(texture0)))) { + return; + } + + const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy); + + vec4 fragColor = imageLoad(texture0, TexCoord); + fragColor.rgb = acesFilm(fragColor.rgb); + + // fragColor = vec4(1.0) - exp(-fragColor * 1); + + const float gamma = 2.2; + fragColor = pow(fragColor, vec4(1.0 / gamma)); + + imageStore(texture0, TexCoord, vec4(fragColor.rgb, 1.0)); +} \ No newline at end of file diff --git a/Shaders/postprocessingeffects/hdr/tonemap.vert b/Shaders/postprocessingeffects/hdr/tonemap.vert deleted file mode 100644 index 09eb555..0000000 --- a/Shaders/postprocessingeffects/hdr/tonemap.vert +++ /dev/null @@ -1,13 +0,0 @@ -#version 460 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_explicit_attrib_location : enable -#extension GL_ARB_uniform_buffer_object : enable - -layout(location = 0) in vec3 Vertex; -layout(location = 0) out vec2 uv; - -void main() { - gl_Position = vec4(Vertex.x, Vertex.y, 0, 1.0); - - uv = (vec2(Vertex.x, Vertex.y) + vec2(1, 1)) / 2.0; -} diff --git a/Shaders/postprocessingeffects/mistfog.frag b/Shaders/postprocessingeffects/mistfog.frag new file mode 100644 index 0000000..b99a503 --- /dev/null +++ b/Shaders/postprocessingeffects/mistfog.frag @@ -0,0 +1,42 @@ +#version 460 +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable + +/* */ +layout(location = 0) out vec4 fragColor; +/* */ +layout(location = 0) in vec2 uv; + +/* */ +layout(set = 0, binding = 0) uniform sampler2D texture0; +layout(set = 0, binding = 1) uniform sampler2D DepthTexture; +layout(set = 0, binding = 2) uniform sampler2D IrradianceTexture; + +#include "fog_frag.glsl" +#include "postprocessing_base.glsl" + +layout(set = 0, binding = 0, std140) uniform UniformBufferBlock { + mat4 proj; + mat4 modelViewProjection; + vec4 tintColor; + FogSettings fogSettings; + Camera camera; +} +ubo; + +void main() { + + const vec3 direction = vec3(1); + + /* */ + const vec2 irradiance_uv = inverse_equirectangular(normalize(direction)); + const vec4 irradiance_color = texture(IrradianceTexture, irradiance_uv).rgba; + + const float depth = texture(DepthTexture, gl_FragCoord.xy).r; + + const float fogFactor = getFogFactor(ubo.fogSettings, depth); + + fragColor.rgb = mix(texture(texture0, uv).rgb, irradiance_color.rgb, fogFactor); + fragColor.a = 1; +} diff --git a/Shaders/postprocessingeffects/overlay.frag b/Shaders/postprocessingeffects/overlay.frag index 85c2f23..8fe007d 100644 --- a/Shaders/postprocessingeffects/overlay.frag +++ b/Shaders/postprocessingeffects/overlay.frag @@ -5,6 +5,6 @@ layout(location = 0) out vec4 fragColor; /* */ layout(location = 0) in vec2 uv; /* */ -layout(binding = 1) uniform sampler2D diffuse; +layout(set = 0, binding = 1) uniform sampler2D diffuse; void main() { fragColor = texture(diffuse, uv); } diff --git a/Shaders/postprocessingeffects/postprocessing.vert b/Shaders/postprocessingeffects/postprocessing.vert index 373f5c4..0cd04a3 100644 --- a/Shaders/postprocessingeffects/postprocessing.vert +++ b/Shaders/postprocessingeffects/postprocessing.vert @@ -2,12 +2,19 @@ #extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_explicit_attrib_location : enable #extension GL_ARB_uniform_buffer_object : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable -layout(location = 0) in vec3 Vertex; layout(location = 0) out vec2 uv; +#include "postprocessing_base.glsl" + void main() { - gl_Position = vec4(Vertex.x, Vertex.y, 0, 1.0); - /* */ + + const vec2 vertex[4] = {vec2(-1, 1), vec2(1, 1), vec2(-1, -1), vec2(1, -1)}; + + const vec2 Vertex = vertex[gl_VertexID % 4]; + + gl_Position = vec4(Vertex, 0, 1.0); uv = (vec2(Vertex.x, Vertex.y) + vec2(1, 1)) / 2.0; } diff --git a/Shaders/postprocessingeffects/postprocessing_base.glsl b/Shaders/postprocessingeffects/postprocessing_base.glsl new file mode 100644 index 0000000..47aba54 --- /dev/null +++ b/Shaders/postprocessingeffects/postprocessing_base.glsl @@ -0,0 +1,2 @@ +#include "colorspace.glsl" +#include "common.glsl" diff --git a/Shaders/shadowmap/texture.frag b/Shaders/shadowmap/texture.frag index 1627f92..f9fea19 100644 --- a/Shaders/shadowmap/texture.frag +++ b/Shaders/shadowmap/texture.frag @@ -73,13 +73,17 @@ void main() { float contriubtion = max(0.0, dot(-normalize(ubo.direction.xyz), normalize(normal))); + /* */ + // vec4 lightColor = + // computeBlinnDirectional(ubo.directional, alteredNormal, ubo.camera.viewDir.xyz, ubo.shininess.r, vec3(1)); + /* */ const vec2 irradiance_uv = inverse_equirectangular(normalize(normal)); const vec4 irradiance_color = texture(Irradiance, irradiance_uv).rgba; vec4 color = texture(DiffuseTexture, UV); - //computeBlinnDirectional + // computeBlinnDirectional const vec4 lighting = (ubo.ambientColor * irradiance_color + (ubo.lightColor * contriubtion + spec) * shadow) * color; diff --git a/Shaders/shadowpointlight/pointlightlight.frag b/Shaders/shadowpointlight/pointlightlight.frag index d8523ff..dd2399e 100644 --- a/Shaders/shadowpointlight/pointlightlight.frag +++ b/Shaders/shadowpointlight/pointlightlight.frag @@ -50,7 +50,7 @@ layout(binding = 0, std140) uniform UniformBufferBlock { } ubo; -float ShadowCalculation(const in vec3 fragPosLightSpace, const in samplerCube ShadowTexture, const in int index) { +float ShadowCalculation(const in vec3 fragPosLightSpace, const in samplerCube ShadowTexture, const in uint index) { const vec3 frag2Light = (fragPosLightSpace - ubo.point_light[index].position); @@ -75,7 +75,7 @@ float ShadowCalculation(const in vec3 fragPosLightSpace, const in samplerCube Sh void main() { vec4 pointLightColors = vec4(0); - [[unroll]] for (int i = 0; i < 4; i++) { + [[unroll]] for (uint i = 0; i < 4; i++) { /* */ vec3 diffVertex = (ubo.point_light[i].position - vertex); diff --git a/Shaders/shadowpointlight/pointlightlight_pcf.frag b/Shaders/shadowpointlight/pointlightlight_pcf.frag index a02bfbf..5babaf8 100644 --- a/Shaders/shadowpointlight/pointlightlight_pcf.frag +++ b/Shaders/shadowpointlight/pointlightlight_pcf.frag @@ -50,7 +50,7 @@ layout(binding = 0, std140) uniform UniformBufferBlock { } ubo; -float ShadowCalculation(const in vec3 fragPosLightSpace, const in samplerCube ShadowTexture, const in int index) { +float ShadowCalculation(const in vec3 fragPosLightSpace, const in samplerCube ShadowTexture, const in uint index) { const vec3 frag2Light = (fragPosLightSpace - ubo.point_light[index].position); @@ -72,7 +72,7 @@ float ShadowCalculation(const in vec3 fragPosLightSpace, const in samplerCube Sh const float diskRadius = (1.0 + (viewDistance / far_plane)) / ubo.diskRadius; const int samples = 20; - [[unroll]] for (int i = 0; i < samples; i++) { + [[unroll]] for (uint i = 0; i < samples; i++) { /* */ float closestDepth = texture(ShadowTexture, frag2Light + ubo.PCFFilters[i].xyz * diskRadius).r; closestDepth *= far_plane; // undo mapping [0;1] @@ -86,7 +86,7 @@ float ShadowCalculation(const in vec3 fragPosLightSpace, const in samplerCube Sh void main() { vec4 pointLightColors = vec4(0); - [[unroll]] for (int i = 0; i < 4; i++) { + [[unroll]] for (uint i = 0; i < 4; i++) { /* */ vec3 diffVertex = (ubo.point_light[i].position - vertex); diff --git a/Shaders/shadowpointlight/pointlightshadow.geom b/Shaders/shadowpointlight/pointlightshadow.geom index ad66ece..4491d10 100644 --- a/Shaders/shadowpointlight/pointlightshadow.geom +++ b/Shaders/shadowpointlight/pointlightshadow.geom @@ -53,7 +53,7 @@ void main() { [[unroll]] for (int face = 0; face < 6; ++face) { gl_Layer = face; // built-in variable that specifies to which face we render. - [[unroll]] for (int i = 0; i < 3; ++i) // for each triangle vertex + [[unroll]] for (uint i = 0; i < 3; ++i) // for each triangle vertex { FragVertex = gl_in[i].gl_Position; FIndex = GIndex[i]; diff --git a/Shaders/simpleocean/simple_water.frag b/Shaders/simpleocean/simple_water.frag index a9bca77..14101cc 100644 --- a/Shaders/simpleocean/simple_water.frag +++ b/Shaders/simpleocean/simple_water.frag @@ -1,5 +1,7 @@ #version 460 #extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable layout(location = 0) out vec4 fragColor; @@ -7,6 +9,20 @@ layout(location = 0) in vec3 vertex; layout(location = 1) in vec2 UV; layout(location = 2) in vec3 normal; layout(location = 3) in vec3 tangent; + +#include "common.glsl" +#include "phongblinn.glsl" + +layout(set = 0, binding = 0) uniform sampler2D ReflectionTexture; +layout(set = 0, binding = 1) uniform sampler2D DepthTexture; + +struct Terrain { + ivec2 size; + vec2 tileOffset; + vec2 tile_noise_size; + vec2 tile_noise_offset; +}; + layout(binding = 0, std140) uniform UniformBufferBlock { mat4 model; mat4 view; @@ -15,7 +31,59 @@ layout(binding = 0, std140) uniform UniformBufferBlock { mat4 viewProjection; mat4 modelViewProjection; + // TODO: replace later. + Camera camera; + + Terrain terrain; + + /* Material */ + vec4 diffuseColor; + vec4 ambientColor; + vec4 specularColor; + vec4 shininess; + + /* Light source. */ + DirectionalLight directional; + + FogSettings fogSettings; + + /* Tessellation Settings. */ + vec4 gEyeWorldPos; + float gDispFactor; + float tessLevel; + + float maxTessellation; + float minTessellation; } ubo; -void main() { fragColor = vec4(0.3, 1, 0.3, 0.4) * vec4(UV,1,1); } \ No newline at end of file +vec4 bump2(const in float height, const in float dist) { + + const float x = dFdxFine(height) * dist; + const float y = dFdxFine(height) * dist; + + const vec4 normal = vec4(x, y, 1, 0); + + return normalize(normal); +} + +void main() { + + /* */ + const vec3 viewDir = normalize(ubo.camera.position.xyz - vertex); + + const float height = noise(vertex); + const vec3 heightNormal = normalize((ubo.model * bump2(height, 0.1)).xyz); + + const vec4 lightColor = + computePhongDirectional(ubo.directional, heightNormal.xyz, viewDir.xyz, ubo.shininess.r, ubo.specularColor.rgb); + + /* Compute depth difference */ + const float current_z = getExpToLinear(ubo.camera.near, ubo.camera.far, texture(DepthTexture, gl_FragCoord.xy).r); + const float shader_z = getExpToLinear(ubo.camera.near, ubo.camera.far, gl_FragCoord.z); + + float inter = clamp((shader_z - current_z) / 100.0, 0.2, 1); + + fragColor = (lightColor + ubo.ambientColor); + fragColor.a = inter; +} \ No newline at end of file diff --git a/Shaders/simpleocean/simple_water.vert b/Shaders/simpleocean/simple_water.vert index e4af753..7822e31 100644 --- a/Shaders/simpleocean/simple_water.vert +++ b/Shaders/simpleocean/simple_water.vert @@ -1,5 +1,7 @@ #version 460 #extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable layout(location = 0) in vec3 Vertex; layout(location = 1) in vec2 TextureCoord; @@ -11,6 +13,18 @@ layout(location = 1) out vec2 UV; layout(location = 2) out vec3 normal; layout(location = 3) out vec3 tangent; + +#include "common.glsl" +#include "phongblinn.glsl" + + +struct Terrain { + ivec2 size; + vec2 tileOffset; + vec2 tile_noise_size; + vec2 tile_noise_offset; +}; + layout(binding = 0, std140) uniform UniformBufferBlock { mat4 model; mat4 view; @@ -19,12 +33,37 @@ layout(binding = 0, std140) uniform UniformBufferBlock { mat4 viewProjection; mat4 modelViewProjection; + // TODO: replace later. + Camera camera; + + Terrain terrain; + + /* Material */ + vec4 diffuseColor; + vec4 ambientColor; + vec4 specularColor; + vec4 shininess; + + /* Light source. */ + DirectionalLight directional; + + FogSettings fogSettings; + + /* Tessellation Settings. */ + vec4 gEyeWorldPos; + float gDispFactor; + float tessLevel; + + float maxTessellation; + float minTessellation; } ubo; void main() { - vertex = (ubo.modelViewProjection * vec4(Vertex, 1.0)).xyz; + gl_Position = (ubo.modelViewProjection * vec4(Vertex, 1.0)); + + vertex = (ubo.model * vec4(Vertex, 0.0)).xyz; normal = normalize((ubo.model * vec4(Normal, 0.0)).xyz); tangent = (ubo.model * vec4(Tangent, 0.0)).xyz; UV = TextureCoord; diff --git a/Shaders/simpleocean/simpleocean.frag b/Shaders/simpleocean/simpleocean.frag index 78fdeca..876ba26 100644 --- a/Shaders/simpleocean/simpleocean.frag +++ b/Shaders/simpleocean/simpleocean.frag @@ -1,20 +1,26 @@ #version 460 #extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable layout(location = 0) out vec4 fragColor; layout(location = 0) in vec3 vertex; layout(location = 1) in vec2 UV; layout(location = 2) in vec3 normal; -layout(location = 3) in vec3 tangent; + +#include "common.glsl" +#include "phongblinn.glsl" + +layout(constant_id = 10) const int MaxWaves = 128; struct Wave { - float wavelength; - float amplitude; - float speed; - float steepness; - vec2 direction; - vec2 padding; + float wavelength; /* */ + float amplitude; /* */ + float speed; /* */ + float rolling; /* */ + vec2 direction; /* */ + vec2 creast_offset; /* */ }; layout(binding = 0, std140) uniform UniformBufferBlock { @@ -25,65 +31,54 @@ layout(binding = 0, std140) uniform UniformBufferBlock { mat4 modelViewProjection; /* Light source. */ - vec4 lookDirection; - vec4 direction; - vec4 lightColor; - vec4 specularColor; - vec4 ambientColor; - vec4 position; + DirectionalLight directional; + Camera camera; - Wave waves[64]; + Wave waves[MaxWaves]; int nrWaves; float time; + float stepness; + float rolling; /* Material */ + + vec4 oceanColor; + vec4 specularColor; + vec4 ambientColor; float shininess; float fresnelPower; - vec4 oceanColor; } ubo; -layout(binding = 1) uniform sampler2D ReflectionTexture; -layout(binding = 2) uniform sampler2D NormalTexture; - -float computeLightContributionFactor(in const vec3 direction, in const vec3 normalInput) { - return max(0.0, dot(-normalInput, direction)); -} +layout(binding = 0) uniform sampler2D ReflectionTexture; -vec2 inverse_equirectangular(const in vec3 direction) { - const vec2 invAtan = vec2(0.1591, 0.3183); - vec2 uv = vec2(atan(direction.z, direction.x), asin(direction.y)); - uv *= invAtan; - uv += 0.5; - return uv; -} +layout(binding = 10) uniform sampler2D IrradianceTexture; void main() { // Create new normal per pixel based on the normal map. const vec3 Mnormal = normalize(normal); - /* Compute directional light */ - const vec4 lightColor = computeLightContributionFactor(ubo.direction.xyz, Mnormal) * ubo.lightColor; - /* */ - const vec3 viewDir = normalize(ubo.position.xyz - vertex); - const vec3 diffVertex = (ubo.position.xyz - vertex); - const vec3 lightDir = normalize(diffVertex); - const vec3 halfwayDir = normalize(lightDir + viewDir); - const float spec = pow(max(dot(Mnormal, halfwayDir), 0.0), ubo.shininess); + const vec3 viewDir = normalize(ubo.camera.position.xyz - vertex); - const vec4 specular = ubo.specularColor * spec; + const vec4 lightColor = + computePhongDirectional(ubo.directional, Mnormal, viewDir, ubo.shininess, ubo.specularColor.rgb); /* */ - const vec3 reflection = normalize(reflect(viewDir, Mnormal)); + const vec3 reflection = normalize(reflect(-viewDir, Mnormal)); const vec2 reflection_uv = inverse_equirectangular(reflection); /* */ - float fresnel = max(dot(Mnormal, viewDir), 0); - fresnel = pow(fresnel, ubo.fresnelPower); + const vec2 irradiance_uv = inverse_equirectangular(normalize(Mnormal)); + const vec4 irradiance_color = texture(IrradianceTexture, irradiance_uv).rgba; + + /* */ + const vec3 fresnel = FresnelSchlick(vec3(0.02) * ubo.fresnelPower, viewDir, normal); + + const vec4 gradientWaterDepth = vec4(0); - const vec4 color = mix(ubo.oceanColor, texture(ReflectionTexture, reflection_uv), fresnel); - fragColor = color * (ubo.ambientColor + lightColor + specular); - fragColor.a = 1 - fresnel; + const vec4 color = mix(ubo.oceanColor, texture(ReflectionTexture, reflection_uv), vec4(fresnel.rgb, 1)); + fragColor = color * (ubo.ambientColor * irradiance_color + lightColor); + fragColor.a = 1; } \ No newline at end of file diff --git a/Shaders/simpleocean/simpleocean.vert b/Shaders/simpleocean/simpleocean.vert index 699ab2d..1a29eef 100644 --- a/Shaders/simpleocean/simpleocean.vert +++ b/Shaders/simpleocean/simpleocean.vert @@ -1,5 +1,7 @@ #version 460 #extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable layout(location = 0) in vec3 Vertex; layout(location = 1) in vec2 TextureCoord; @@ -11,15 +13,18 @@ layout(location = 1) out vec2 UV; layout(location = 2) out vec3 normal; layout(location = 3) out vec3 tangent; -layout(constant_id = 0) const int MaxWaves = 64; +#include "common.glsl" +#include "light.glsl" + +layout(constant_id = 10) const int MaxWaves = 128; struct Wave { - float wavelength; - float amplitude; - float speed; - float steepness; - vec2 direction; - vec2 padding; + float wavelength; /* */ + float amplitude; /* */ + float speed; /* */ + float rolling; /* */ + vec2 direction; /* */ + vec2 creast_offset; /* */ }; layout(binding = 0, std140) uniform UniformBufferBlock { @@ -30,96 +35,89 @@ layout(binding = 0, std140) uniform UniformBufferBlock { mat4 modelViewProjection; /* Light source. */ - vec4 lookDirection; - vec4 direction; - vec4 lightColor; - vec4 specularColor; - vec4 ambientColor; - vec4 position; + DirectionalLight directional; + Camera camera; - Wave waves[64]; + Wave waves[MaxWaves]; int nrWaves; float time; + float stepness; + float rolling; /* Material */ + vec4 oceanColor; + vec4 specularColor; + vec4 ambientColor; float shininess; float fresnelPower; - vec4 oceanColor; } ubo; -vec3 computeNormal(const in float time) { +float computeHeightStepness(const in float time, in const Wave w) { + return 2 * pow(((w.amplitude * sin(dot(w.direction, Vertex.xy) * w.wavelength + time * w.speed)) * (1.0 / 2.0)), + w.rolling); +} + +float computeHeight(const in float time, in const Wave w, const in vec2 UV) { + return w.amplitude * sin(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); +} +vec3 computeBiNormal(const in float time, const in vec2 UV) { float normalX = 0; - float normalY = 0; - for (int i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { + for (uint i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { const Wave w = ubo.waves[i]; - normalX += -(w.wavelength * w.direction.x * w.amplitude * - cos(dot(w.direction, Vertex.xy) * w.wavelength + time * w.speed)); - normalY += -(w.wavelength * w.direction.y * w.amplitude * - cos(dot(w.direction, Vertex.xy) * w.wavelength + time * w.speed)); + normalX += (w.wavelength * w.direction.x * UV.x) * w.amplitude * + cos(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); } - - return vec3(normalX, 1, normalY); + return vec3(1, 0, normalX); } -float computeHeight(const in float time, in const Wave w) { - return w.amplitude * sin(dot(w.direction, Vertex.xy) * w.wavelength + time * w.speed); -} +vec3 computeTangent(const in float time, const in vec2 UV) { + float normalX = 0; + float normalY = 0; -// Gerstner Waves -vec3 computeGerstnerWaves(const in float time, in const Wave wave) { - float height = 0; - float x = Vertex.x; - float y = Vertex.y; + for (uint i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { - for (int i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { - height += computeHeight(ubo.time, ubo.waves[i]); + const Wave w = ubo.waves[i]; + + normalY += (w.wavelength * w.direction.y * UV.y) * w.amplitude * + cos(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); } - return vec3(x, height, y); + return vec3(0, 1, normalY); } -// TODO: compute -vec3 computeTangent(const in float time) { - float normalX = 0; - float normalY = 0; +vec3 computeNormal(const in float time, const in vec2 UV) { - for (int i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { + const vec3 surface_binormal = computeBiNormal(time, UV); + const vec3 surface_tangent = computeTangent(time, UV); - const Wave w = ubo.waves[i]; - - normalX += -(w.wavelength * w.direction.x * w.amplitude * - cos(dot(w.direction, Vertex.xy) * w.wavelength + time * w.speed)); - normalY += -(w.wavelength * w.direction.y * w.amplitude * - cos(dot(w.direction, Vertex.xy) * w.wavelength + time * w.speed)); - } + const vec3 surface_normal = cross(surface_binormal, surface_tangent); - return Tangent.xyz;// vec3(normalX, 1, normalY); + return normalize(surface_normal); } void main() { + /* */ + if (ubo.rolling != 0) { + } + float height = 0; - - for (int i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { - height += computeHeight(ubo.time, ubo.waves[i]); + for (uint i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { + height += computeHeight(ubo.time, ubo.waves[i], TextureCoord); } - const vec3 surface_normal = normalize(computeNormal(ubo.time)); - const vec3 surface_tangent = normalize(computeTangent(ubo.time)); + const vec3 surface_normal = computeNormal(ubo.time, TextureCoord); const vec3 surface_vertex = Vertex + Normal * height; gl_Position = ubo.modelViewProjection * vec4(surface_vertex, 1.0); vertex = (ubo.model * vec4(surface_vertex, 1.0)).xyz; - normal = surface_normal; //(ubo.model * vec4(surface_normal, 0.0)).xyz; - // normal = normalize((ubo.model * vec4(Normal, 0.0)).xyz); - tangent = (ubo.model * vec4(Tangent, 0.0)).xyz; - + normal = normalize((ubo.model * vec4(surface_normal, 0.0)).xyz); UV = TextureCoord; } \ No newline at end of file diff --git a/Shaders/simpleocean/simpleocean_gerstner.vert b/Shaders/simpleocean/simpleocean_gerstner.vert new file mode 100644 index 0000000..e1ef3be --- /dev/null +++ b/Shaders/simpleocean/simpleocean_gerstner.vert @@ -0,0 +1,152 @@ +#version 460 +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_include : enable +#extension GL_GOOGLE_include_directive : enable + +layout(location = 0) in vec3 Vertex; +layout(location = 1) in vec2 TextureCoord; +layout(location = 2) in vec3 Normal; +layout(location = 3) in vec3 Tangent; + +layout(location = 0) out vec3 vertex; +layout(location = 1) out vec2 UV; +layout(location = 2) out vec3 normal; +layout(location = 3) out vec3 tangent; + +#include "common.glsl" +#include "light.glsl" + +layout(constant_id = 10) const int MaxWaves = 128; + +struct Wave { + float wavelength; /* */ + float amplitude; /* */ + float speed; /* */ + float rolling; /* */ + vec2 direction; /* */ + vec2 creast_offset; /* */ +}; + +layout(binding = 0, std140) uniform UniformBufferBlock { + mat4 model; + mat4 view; + mat4 proj; + mat4 modelView; + mat4 modelViewProjection; + + /* Light source. */ + DirectionalLight directional; + Camera camera; + + Wave waves[MaxWaves]; + + int nrWaves; + float time; + float stepness; + float rolling; + + /* Material */ + vec4 oceanColor; + vec4 specularColor; + vec4 ambientColor; + float shininess; + float fresnelPower; +} +ubo; + +float qFunc(const in Wave w) { return (1 / (w.wavelength * w.amplitude * ubo.nrWaves)) * ubo.stepness; } + +float sfunc(const in Wave w, const in vec2 UV, const in float time) { + return sin(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); +} +float wafunc(const in Wave w) { return w.wavelength * w.amplitude; } + +float cfunc(const in Wave w, const in vec2 UV, const in float time) { + return cos(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); +} + +float computeHeight(const in float time, in const Wave w, const in vec2 UV) { + return w.amplitude * sin(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); +} + +vec3 computeBiNormal(const in float time, const in vec2 UV) { + float normalX = 0; + + for (uint i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { + + const Wave w = ubo.waves[i]; + + normalX += (w.wavelength * w.direction.x * UV.x) * w.amplitude * + cos(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); + } + return vec3(1, 0, normalX); +} + +vec3 computeTangent(const in float time, const in vec2 UV) { + float normalX = 0; + float normalY = 0; + + for (uint i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { + + const Wave w = ubo.waves[i]; + + normalY += (w.wavelength * w.direction.y * UV.y) * w.amplitude * + cos(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); + } + + return vec3(0, 1, normalY); +} + +vec3 computeNormal(const in float time, const in vec2 UV) { + + float normalX = 0; + float normalY = 0; + float normalZ = 0; + for (uint i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { + const Wave w = ubo.waves[i]; + + // normalX += qFunc(w) * w.direction.x * w.direction.y * wafunc(w) * sfunc(w, UV, time); + normalX += w.direction.x * wafunc(w) * cfunc(w, UV, time); + normalY += w.direction.y * wafunc(w) * cfunc(w, UV, time); + normalZ += qFunc(w) * wafunc(w) * sfunc(w, UV, time); + } + + return normalize(vec3(-normalX, -normalY, 1 - normalZ)); +} + +// Gerstner Waves +vec3 computeGerstnerWaves(const in float time, const in vec3 vertex, const in vec3 Normal, const in vec2 UV) { + float height = 0; + float xOffset = 0; + float yOffset = 0; + + float x = Vertex.x; + float y = Vertex.y; + + for (uint i = 0; i < min(ubo.nrWaves, MaxWaves); i++) { + const Wave w = ubo.waves[i]; + + height += computeHeight(ubo.time, ubo.waves[i], UV); + + const float Q = qFunc(w); + xOffset += Q * w.amplitude * w.direction.x * cos(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); + yOffset += Q * w.amplitude * w.direction.y * cos(dot(w.direction, UV.xy) * w.wavelength + time * w.speed); + } + + return vec3(Vertex.x + xOffset, Vertex.y + yOffset, 0) + Normal * height; +} + +void main() { + + const vec3 surface_vertex = computeGerstnerWaves(ubo.time, Vertex, Normal, TextureCoord); + + const vec3 surface_normal = computeNormal(ubo.time, TextureCoord); + + { + gl_Position = ubo.modelViewProjection * vec4(surface_vertex, 1.0); + + vertex = (ubo.model * vec4(surface_vertex, 1.0)).xyz; + + normal = normalize((ubo.model * vec4(surface_normal, 0.0)).xyz); + } +} \ No newline at end of file diff --git a/Shaders/skybox/panoramic.frag b/Shaders/skybox/panoramic.frag index 64d0b27..eb2ee7e 100644 --- a/Shaders/skybox/panoramic.frag +++ b/Shaders/skybox/panoramic.frag @@ -18,17 +18,17 @@ layout(set = 0, binding = 0, std140) uniform UniformBufferBlock { } ubo; -#include"common.glsl" - - +#include "common.glsl" void main() { const vec2 uv = inverse_equirectangular(normalize(vVertex)); fragColor = textureLod(PanoramaTexture, uv, 0) * ubo.tintColor; - fragColor = vec4(1.0) - exp(-fragColor * ubo.exposure); + fragColor = vec4(1.0) - exp(-fragColor * ubo.exposure); const float gamma = ubo.gamma; - fragColor = pow(fragColor, vec4(1.0 / ubo.gamma)); + fragColor = pow(fragColor, vec4(1.0 / gamma)); + + fragColor = fragColor * ubo.tintColor; } \ No newline at end of file diff --git a/Shaders/subgroup/subgroup.comp b/Shaders/subgroup/subgroup.comp index 2899a35..50d849a 100644 --- a/Shaders/subgroup/subgroup.comp +++ b/Shaders/subgroup/subgroup.comp @@ -13,6 +13,7 @@ layout(std430, binding=1) buffer layout_bar { }; void main() { + uint value = subgroupMax(foo[gl_GlobalInvocationID.x]); // A single invocation in the subgroup will do the atomic operation diff --git a/Shaders/terrain/terrain.frag b/Shaders/terrain/terrain.frag index e2611fc..3275067 100644 --- a/Shaders/terrain/terrain.frag +++ b/Shaders/terrain/terrain.frag @@ -10,25 +10,29 @@ layout(location = 1) in vec2 UV; layout(location = 2) in vec3 normal; layout(location = 3) in vec3 tangent; + #include "terrain_base.glsl" -#include "phongblinn.glsl" #include "fog_frag.glsl" layout(binding = 1) uniform sampler2D DiffuseTexture; layout(binding = 2) uniform sampler2D NormalTexture; -layout(binding = 2) uniform sampler2D Irradiance; - +layout(binding = 2) uniform sampler2D IrradianceTexture; void main() { const vec3 alteredNormal = normal; /* */ - vec4 lightColor = computeBlinnDirectional(ubo.directional, alteredNormal, ubo.camera.viewDir.xyz, ubo.shininess.r, vec3(1)); + vec4 lightColor = + computeBlinnDirectional(ubo.directional, alteredNormal, ubo.camera.viewDir.xyz, ubo.shininess.r, vec3(1)); -// + /* */ + const vec2 irradiance_uv = inverse_equirectangular(normalize(normal)); + const vec4 irradiance_color = texture(IrradianceTexture, irradiance_uv).rgba; - fragColor = texture(DiffuseTexture, UV) * (in_WorldPosition.y * 0.01) * (lightColor + ubo.ambientColor); + // + fragColor = (lightColor + ubo.ambientColor * irradiance_color); fragColor = blendFog(fragColor, ubo.fogSettings); + fragColor.a = 1; // fragColor = vec4(normal, 1); } diff --git a/Shaders/terrain/terrain.tesc b/Shaders/terrain/terrain.tesc index b0bf77b..d816948 100644 --- a/Shaders/terrain/terrain.tesc +++ b/Shaders/terrain/terrain.tesc @@ -1,6 +1,7 @@ #version 460 #extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_shading_language_include : enable +#extension GL_EXT_control_flow_attributes : enable #extension GL_GOOGLE_include_directive : enable // define the number of CPs in the output patch @@ -22,7 +23,6 @@ vec3 ProjectToPlane(const vec3 Point, const vec3 PlanePoint, const vec3 PlaneNor return (Point - d); } - void CalcPositions() { // The original vertices stay the same @@ -69,11 +69,10 @@ float GetTessLevel(float Distance0, float Distance1) { return mix(minTessellation, maxTessellation, 100 / (AvgDistance + 10)); } - void main() { // Set the control points of the output patch - for (uint i = 0; i < 3; i++) { + [[unroll]] for (uint i = 0; i < 3; i++) { oPatch.Normal[i] = Normal_CS_in[i]; oPatch.Tangent[i] = Tangent_CS_in[i]; oPatch.TexCoord[i] = TexCoord_CS_in[i]; @@ -94,8 +93,3 @@ void main() { gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; } - - - - - \ No newline at end of file diff --git a/Shaders/terrain/terrain.tese b/Shaders/terrain/terrain.tese index a6ac268..0de9d0c 100644 --- a/Shaders/terrain/terrain.tese +++ b/Shaders/terrain/terrain.tese @@ -25,6 +25,16 @@ vec3 interpolate3D(vec3 v0, vec3 v1, vec3 v2) { return vec3(gl_TessCoord.x) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2; } +float calculateHeightDisplacement(const vec3 position, const vec2 tile_noise, const vec2 offset, const int octave) { + float heightMapDisp = 0; + for (uint i = 0; i < octave; i++) { + const float mag = ((i * 0.3 + 1.0) / 1); + + heightMapDisp += noise(position * tile_noise.xyx * mag + offset.xyx) * (1 + 1 / (i + 0.05)); + } + return heightMapDisp; +} + void main() { // Interpolate the attributes of the output vertex using the barycentric coordinates TexCoord_FS_in = interpolate2D(oPatch.TexCoord[0], oPatch.TexCoord[1], oPatch.TexCoord[2]); @@ -43,34 +53,39 @@ void main() { const float vPow2 = pow(v, 2); const float wPow2 = pow(w, 2); - WorldPos_FS_in = oPatch.WorldPos_B300 * wPow3 + oPatch.WorldPos_B030 * uPow3 + oPatch.WorldPos_B003 * vPow3 + - oPatch.WorldPos_B210 * 3.0 * wPow2 * u + oPatch.WorldPos_B120 * 3.0 * w * uPow2 + - oPatch.WorldPos_B201 * 3.0 * wPow2 * v + oPatch.WorldPos_B021 * 3.0 * uPow2 * v + - oPatch.WorldPos_B102 * 3.0 * w * vPow2 + oPatch.WorldPos_B012 * 3.0 * u * vPow2 + - oPatch.WorldPos_B111 * 6.0 * w * u * v; + const vec3 VertexPosition = oPatch.WorldPos_B300 * wPow3 + oPatch.WorldPos_B030 * uPow3 + + oPatch.WorldPos_B003 * vPow3 + oPatch.WorldPos_B210 * 3.0 * wPow2 * u + + oPatch.WorldPos_B120 * 3.0 * w * uPow2 + oPatch.WorldPos_B201 * 3.0 * wPow2 * v + + oPatch.WorldPos_B021 * 3.0 * uPow2 * v + oPatch.WorldPos_B102 * 3.0 * w * vPow2 + + oPatch.WorldPos_B012 * 3.0 * u * vPow2 + oPatch.WorldPos_B111 * 6.0 * w * u * v; /* Displace the vertex along the normal */ - float heightMapDisp = 0; - for (uint i = 0; i < 16; i++) { - const float mag = ((i * 0.3 + 1.0) / 1); - heightMapDisp += noise(WorldPos_FS_in * ubo.terrain.tile_noise_size.xyx * mag + - ubo.terrain.tile_noise_offset.xyx) * (1 + 1 / (i+0.05)); - } + const int ocatve = 16; + float heightMapDisp = + calculateHeightDisplacement(VertexPosition, ubo.terrain.tile_noise_size, ubo.terrain.tile_noise_offset, ocatve); - WorldPos_FS_in += Normal_FS_in * heightMapDisp * ubo.gDispFactor; + WorldPos_FS_in = VertexPosition + Normal_FS_in * heightMapDisp * ubo.gDispFactor; /* Recompute normal. */ // TODO: improve { const vec3 vertexPos0 = WorldPos_FS_in; - const vec3 vertexPos1 = WorldPos_FS_in - cross(Tangent_FS_in, Normal_FS_in) * 0.5 + - Normal_FS_in * noise(WorldPos_FS_in * 0.1 + vec3(0.001)) * ubo.gDispFactor; - const vec3 vertexPos2 = WorldPos_FS_in + Tangent_FS_in * 0.5 + - Normal_FS_in * noise(WorldPos_FS_in * 0.1 - vec3(0.001)) * ubo.gDispFactor; - - const vec3 d1 = 10 * vertexPos1 - vertexPos0; - const vec3 d2 = 10 * vertexPos2 - vertexPos0; + const vec3 vertexPos1 = + VertexPosition + cross(Tangent_FS_in, Normal_FS_in) * 0.1 + + Normal_FS_in * + calculateHeightDisplacement(VertexPosition + cross(Tangent_FS_in, Normal_FS_in) * 0.1, + ubo.terrain.tile_noise_size, ubo.terrain.tile_noise_offset, ocatve) * + ubo.gDispFactor; + const vec3 vertexPos2 = + VertexPosition + Tangent_FS_in * 0.1 + + Normal_FS_in * + calculateHeightDisplacement(VertexPosition + Tangent_FS_in * 0.1, ubo.terrain.tile_noise_size, + ubo.terrain.tile_noise_offset, ocatve) * + ubo.gDispFactor; + + const vec3 d1 = vertexPos1 - vertexPos0; + const vec3 d2 = vertexPos2 - vertexPos0; Normal_FS_in = normalize(cross(d1, d2)); } diff --git a/Shaders/terrain/terrain.vert b/Shaders/terrain/terrain.vert index 521a6f2..abde089 100644 --- a/Shaders/terrain/terrain.vert +++ b/Shaders/terrain/terrain.vert @@ -4,7 +4,6 @@ #extension GL_GOOGLE_include_directive : enable layout(location = 0) in vec3 Vertex; -layout(location = 1) in vec2 TextureCoord; layout(location = 2) in vec3 Normal; layout(location = 3) in vec3 Tangent; @@ -19,8 +18,6 @@ layout(location = 3) out vec3 FragIN_tangent; void main() { // TODO: compute X,Y from vertex ID. - // TODO: compute UV from vertex ID. - const float x = float(gl_VertexID % ubo.terrain.size.x); const float y = float(gl_VertexID / ubo.terrain.size.y); diff --git a/Shaders/vectorfield/apply_force_2D.comp b/Shaders/vectorfield/apply_force_2D.comp index 43e0610..5256261 100644 --- a/Shaders/vectorfield/apply_force_2D.comp +++ b/Shaders/vectorfield/apply_force_2D.comp @@ -20,7 +20,7 @@ writeBuffer; void main() { - [[unroll]] for (int i = 0; i < NR_Particles; i++) { + [[unroll]] for (uint i = 0; i < NR_Particles; i++) { /* Particle index. */ const uint pindex = gl_GlobalInvocationID.x * NR_Particles + i; diff --git a/Shaders/vectorfield/init_particle2D.comp b/Shaders/vectorfield/init_particle2D.comp index 9482aa3..79fbedf 100644 --- a/Shaders/vectorfield/init_particle2D.comp +++ b/Shaders/vectorfield/init_particle2D.comp @@ -18,7 +18,7 @@ writeBuffer; void main() { - [[unroll]] for (int i = 0; i < NR_Particles; i++) { + [[unroll]] for (uint i = 0; i < NR_Particles; i++) { /* Particle index. */ const uint pindex = gl_GlobalInvocationID.x * NR_Particles + i; diff --git a/Shaders/vectorfield/motion2D.geom b/Shaders/vectorfield/motion2D.geom index 11e4774..c211d74 100644 --- a/Shaders/vectorfield/motion2D.geom +++ b/Shaders/vectorfield/motion2D.geom @@ -27,7 +27,7 @@ void main() { const float arrowLength = (ubo.setting.spriteSize * ubo.setting.spriteSize) * 1.0 / 3.5; - for (int i = 0; i < gl_in.length(); i++) { + for (uint i = 0; i < gl_in.length(); i++) { const vec4 glpos = gl_in[i].gl_Position; diff --git a/Shaders/vectorfield/particle.comp b/Shaders/vectorfield/particle.comp index b9d384e..9d958b2 100644 --- a/Shaders/vectorfield/particle.comp +++ b/Shaders/vectorfield/particle.comp @@ -83,7 +83,7 @@ void main() { const vec3 max = ubo.setting.particleBox.xyz; const vec3 min = vec3(0, 0, 0); - [[unroll]] for (int i = 0; i < NR_Particles; i++) {} + [[unroll]] for (uint i = 0; i < NR_Particles; i++) {} const uvec3 index = gl_GlobalInvocationID.xyz; diff --git a/Shaders/vectorfield/particle2D.comp b/Shaders/vectorfield/particle2D.comp index 09ba2fc..780412f 100644 --- a/Shaders/vectorfield/particle2D.comp +++ b/Shaders/vectorfield/particle2D.comp @@ -18,7 +18,7 @@ writeBuffer; void main() { - [[unroll]] for (int i = 0; i < NR_Particles; i++) { + [[unroll]] for (uint i = 0; i < NR_Particles; i++) { /* Particle index. */ const uint pindex = gl_GlobalInvocationID.x * NR_Particles + i; @@ -46,29 +46,26 @@ void main() { vec2 newVelocity = velocity + (-velocity * dragVelocityChange) * delta; /* Check bounds. */ - if (position.x + EPSILON > max_bound.x) { - newVelocity = reflect(newVelocity, vec2(-1, 0)); - } - if (position.y + EPSILON > max_bound.y) { - newVelocity = reflect(newVelocity, vec2(0, -1)); - } if (position.x - EPSILON < min_bound.x) { newVelocity = reflect(newVelocity, vec2(1, 0)); - } - if (position.y - EPSILON < min_bound.y) { + } else if (position.y - EPSILON < min_bound.y) { newVelocity = reflect(newVelocity, vec2(0, 1)); } + if (position.x + EPSILON > max_bound.x) { + newVelocity = reflect(newVelocity, vec2(-1, 0)); + } else if (position.y + EPSILON > max_bound.y) { + newVelocity = reflect(newVelocity, vec2(0, -1)); + } + /* Update the position. */ position += newVelocity * delta; /* Final position update. */ - position.xy = clamp(position.xy, min_bound, max_bound); + position.xy = max(position.xy, vec2(0)); /* Update particle. */ writeBuffer.particle[pindex].position.xy = position; - // writeBuffer.particle[pindex].time = readBuffer.particle[pindex].time - ubo.deltaTime; writeBuffer.particle[pindex].velocity.xy = newVelocity; } } - diff --git a/Shaders/vectorfield/vectorField.geom b/Shaders/vectorfield/vectorField.geom index 57b1c3a..0a33883 100755 --- a/Shaders/vectorfield/vectorField.geom +++ b/Shaders/vectorfield/vectorField.geom @@ -26,7 +26,7 @@ void main() { const vec3 identity = vec3(1.0, 0.0, 0.0); const float arrowLength = 1.0 / 3.5; - for (int i = 0; i < gl_in.length(); i++) { + for (uint i = 0; i < gl_in.length(); i++) { const vec4 glpos = gl_in[i].gl_Position; diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0331f24..17c28f3 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,6 +1,8 @@ FILE(GLOB SOURCE_OPENGL_COMMON_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Util/*.cpp) + ${CMAKE_CURRENT_SOURCE_DIR}/Util/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/PostProcessing/*.cpp) FILE(GLOB HEADER_OPENGL_COMMON_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h + ${CMAKE_CURRENT_SOURCE_DIR}/PostProcessing/*.h ${CMAKE_CURRENT_SOURCE_DIR}/Util/*.h) SOURCE_GROUP(Common FILES ${HEADER_OPENGL_COMMON_FILES} ${SOURCE_OPENGL_COMMON_FILES}) diff --git a/common/ColorSpaceConverter.cpp b/common/ColorSpaceConverter.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/common/Common.cpp b/common/Common.cpp index b2ff94f..c0e1231 100644 --- a/common/Common.cpp +++ b/common/Common.cpp @@ -139,9 +139,7 @@ void Common::loadCube(MeshObject &cubeMesh, const float scale, const int segment cubeMesh.nrVertices = vertices.size(); } -void Common::mergeMeshBuffers(const std::vector &sphereMesh, std::vector &mergeMeshes) { - -} +void Common::mergeMeshBuffers(const std::vector &sphereMesh, std::vector &mergeMeshes) {} int Common::createColorTexture(unsigned int width, unsigned int height, const fragcore::Color &color) { GLuint texRef; @@ -150,9 +148,12 @@ int Common::createColorTexture(unsigned int width, unsigned int height, const fr FVALIDATE_GL_CALL(glBindTexture(GL_TEXTURE_2D, texRef)); FVALIDATE_GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_FLOAT, color.data())); - FVALIDATE_GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); + FVALIDATE_GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST)); FVALIDATE_GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); - /* Border clamped to max value, it makes the outside area. */ + + /* */ + FVALIDATE_GL_CALL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 0)); + FVALIDATE_GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)); FVALIDATE_GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)); diff --git a/common/Common.h b/common/Common.h index 9386f1e..0885a56 100644 --- a/common/Common.h +++ b/common/Common.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -19,10 +19,13 @@ namespace glsample { - enum class ColorSpace { - Raw, /* Linear. */ - SRGB, /* SRGB encoded. */ - ACES + enum class ColorSpace : unsigned int { + Raw = 0, /* Linear. */ + SRGB, /* SRGB encoded. */ + ACES, /* */ + FalseColor, + KhronosPBRNeutral, + MaxColorSpaces }; // TODO: rename diff --git a/common/FPSCounter.h b/common/FPSCounter.h index 0e9bda7..3453aa6 100644 --- a/common/FPSCounter.h +++ b/common/FPSCounter.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/common/GLSample.h b/common/GLSample.h index ddf3792..afdda71 100644 --- a/common/GLSample.h +++ b/common/GLSample.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -89,19 +89,6 @@ template class GLSample : public glsample::GLSampl const bool vsync = result["vsync"].as(); const bool gammacorrection = result["gamma-correction"].as(); - if (result.count("time") > 0) { - /* Create seperate thread that count down. */ - if (result["time"].as() > 0) { - - const int64_t timeout_mili = (int64_t)(result["time"].as() * 1000.0f); - std::thread timeout_thread = std::thread([timeout_mili]() { - std::this_thread::sleep_for(std::chrono::milliseconds(timeout_mili)); - exit(EXIT_SUCCESS); - }); - timeout_thread.detach(); - } - } - /* Default window size. */ int width = result["width"].as(); int height = result["height"].as(); @@ -188,9 +175,22 @@ template class GLSample : public glsample::GLSampl } this->sampleRef->setSize(width, height); this->sampleRef->vsync(vsync); - this->sampleRef->setColorSpace(gammacorrection); + // this->sampleRef->setColorSpace(gammacorrection); this->sampleRef->setFullScreen(fullscreen); + if (result.count("time") > 0) { + /* Create seperate thread that count down. */ + if (result["time"].as() > 0) { + + const int64_t timeout_mili = (int64_t)(result["time"].as() * 1000.0f); + std::thread timeout_thread = std::thread([timeout_mili]() { + std::this_thread::sleep_for(std::chrono::milliseconds(timeout_mili)); + exit(EXIT_SUCCESS); + }); + timeout_thread.detach(); + } + } + this->sampleRef->show(); this->sampleRef->run(); } diff --git a/common/GLSampleSession.h b/common/GLSampleSession.h index ac8dc20..d75da61 100644 --- a/common/GLSampleSession.h +++ b/common/GLSampleSession.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -40,9 +40,9 @@ namespace glsample { using MeshObject = struct geometry_object_t { /* */ - unsigned int vao = -1; - unsigned int vbo = -1; - unsigned int ibo = -1; + unsigned int vao = 0; + unsigned int vbo = 0; + unsigned int ibo = 0; size_t nrIndicesElements = 0; size_t nrVertices = 0; diff --git a/common/GLSampleWindow.cpp b/common/GLSampleWindow.cpp index 8604067..33297db 100644 --- a/common/GLSampleWindow.cpp +++ b/common/GLSampleWindow.cpp @@ -1,12 +1,15 @@ #include "GLSampleWindow.h" +#include "Common.h" #include "Core/Library.h" #include "Core/SystemInfo.h" #include "FPSCounter.h" #include "GLHelper.h" #include "GLUIComponent.h" +#include "PostProcessing/ColorSpaceConverter.h" #include "SDL_scancode.h" #include "SDL_video.h" #include "imgui.h" +#include "magic_enum.hpp" #include "spdlog/common.h" #include #include @@ -47,6 +50,51 @@ class SampleSettingComponent : public GLUIComponent { } ImGui::Text("WorkDirectory: %s", fragcore::SystemInfo::getCurrentDirectory().c_str()); // ImGui::Checkbox("Logging: %s", fragcore::SystemInfo::getCurrentDirectory().c_str()); + + if (this->getRefSample().getDefaultFramebuffer() > 0) { + GLboolean isEnabled = 0; + glGetBooleanv(GL_MULTISAMPLE, &isEnabled); + if (ImGui::Checkbox("MultiSampling (MSAA)", (bool *)&isEnabled)) { + if (isEnabled) { + glEnable(GL_MULTISAMPLE); + } else { + glDisable(GL_MULTISAMPLE); + } + } + } + + if (this->getRefSample().getColorSpaceConverter()) { + const int item_selected_idx = + (int)this->getRefSample().getColorSpace(); // Here we store our selection data as an index. + + std::string combo_preview_value = std::string(magic_enum::enum_name(this->getRefSample().getColorSpace())); + ImGuiComboFlags flags = 0; + if (ImGui::BeginCombo("ColorSpace", combo_preview_value.c_str(), flags)) { + for (int n = 0; n < (int)ColorSpace::MaxColorSpaces; n++) { + const bool is_selected = (item_selected_idx == n); + + if (ImGui::Selectable(magic_enum::enum_name((ColorSpace)n).data(), is_selected)) { + this->getRefSample().setColorSpace((ColorSpace)n); + } + + // Set the initial focus when opening the combo (scrolling + keyboard navigation focus) + if (is_selected) { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + + ImGui::BeginGroup(); + ImGui::TextUnformatted("Gamma Correction Settings"); + ImGui::DragFloat("Exposure", &this->getRefSample().getColorSpaceConverter()->getGammeSettings().exposure); +// ImGui::SameLine(); + ImGui::DragFloat("Gamma", &this->getRefSample().getColorSpaceConverter()->getGammeSettings().gamma); + ImGui::EndGroup(); + } + + if (this->getRefSample().getPostProcessingManager()) { + } } private: @@ -98,6 +146,11 @@ GLSampleWindow::GLSampleWindow() /* */ glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + /* */ + if (glMaxShaderCompilerThreadsKHR) { + glMaxShaderCompilerThreadsKHR(fragcore::SystemInfo::getCPUCoreCount() / 2); + } + std::shared_ptr settingComponent = std::make_shared(*this); this->addUIComponent(settingComponent); } @@ -106,8 +159,15 @@ void GLSampleWindow::displayMenuBar() {} void GLSampleWindow::renderUI() { + // TODO: relocate to init + if (this->colorSpace == nullptr) { + this->colorSpace = new ColorSpaceConverter(); + this->colorSpace->initialize(getFileSystem()); + } + + // TODO: relocate to init const size_t multi_sample_count = this->getResult()["multi-sample"].as(); - if (this->defaultFramebuffer == nullptr && multi_sample_count > 0) { + if (this->defaultFramebuffer == nullptr && multi_sample_count >= 0) { /* */ this->createDefaultFrameBuffer(); } @@ -147,6 +207,11 @@ void GLSampleWindow::renderUI() { this->draw(); if (this->defaultFramebuffer) { + + if (this->colorSpace) { + this->colorSpace->convert(this->defaultFramebuffer->attachement0); + } + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_READ_FRAMEBUFFER, this->defaultFramebuffer->framebuffer); @@ -289,7 +354,7 @@ void GLSampleWindow::captureScreenShot() { /* offload the image process and saving to filesystem. */ if (pixelData) { - std::thread process_thread([&, imageSizeInBytes, screen_grab_width_size, screen_grab_height_size, pixelData]() { + std::thread process_thread([&, imageSizeInBytes, screen_grab_width_size, screen_grab_height_size]() { /* */ try { fragcore::Image image(screen_grab_width_size, screen_grab_height_size, fragcore::ImageFormat::RGB24); @@ -320,7 +385,18 @@ void GLSampleWindow::captureScreenShot() { } } -void GLSampleWindow::setColorSpace(bool srgb) {} +void GLSampleWindow::setColorSpace(glsample::ColorSpace srgb) { + if (this->colorSpace != nullptr) { + this->colorSpace->setColorSpace(srgb); + } +} +glsample::ColorSpace GLSampleWindow::getColorSpace() const noexcept { + if (this->colorSpace != nullptr) { + return this->colorSpace->getColorSpace(); + } + return ColorSpace::Raw; +} + void GLSampleWindow::vsync(bool enable_vsync) { SDL_GL_SetSwapInterval(enable_vsync); } void GLSampleWindow::enableRenderDoc(bool status) { @@ -380,8 +456,10 @@ void GLSampleWindow::createDefaultFrameBuffer() { } void GLSampleWindow::updateDefaultFramebuffer() { + if (this->defaultFramebuffer != nullptr) { + /* */ // TODO: fix coupling. const int multisamples = this->getResult()["multi-sample"].as(); const int width = this->width(); @@ -398,7 +476,7 @@ void GLSampleWindow::updateDefaultFramebuffer() { if (multisamples > 0) { glTexImage2DMultisample(texture_type, multisamples, GL_RGBA, width, height, GL_TRUE); } else { - glTexImage2D(texture_type, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D(texture_type, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -427,7 +505,15 @@ void GLSampleWindow::updateDefaultFramebuffer() { glTexImage2D(texture_type, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); } + glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(texture_type, GL_TEXTURE_MAX_LOD, 0); + glTexParameterf(texture_type, GL_TEXTURE_LOD_BIAS, 0.0f); + glTexParameteri(texture_type, GL_TEXTURE_BASE_LEVEL, 0); glBindTexture(texture_type, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texture_type, this->defaultFramebuffer->depthbuffer, 0); diff --git a/common/GLSampleWindow.h b/common/GLSampleWindow.h index dec238b..ce5a47b 100644 --- a/common/GLSampleWindow.h +++ b/common/GLSampleWindow.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -14,9 +14,10 @@ * all copies or substantial portions of the Software. */ #pragma once -#include "ColorSpaceConverter.h" #include "FPSCounter.h" #include "GLRendererInterface.h" +#include "PostProcessing/ColorSpaceConverter.h" +#include "PostProcessing/PostProcessingManager.h" #include "SDLInput.h" #include "TaskScheduler/IScheduler.h" #include @@ -29,6 +30,8 @@ class FVDECLSPEC GLSampleWindow : public nekomimi::MIMIWindow { public: GLSampleWindow(); + GLSampleWindow &operator=(const GLSampleWindow &) = delete; + GLSampleWindow &operator=(GLSampleWindow &&) = delete; GLSampleWindow(const GLSampleWindow &other) = delete; GLSampleWindow(GLSampleWindow &&other) = delete; @@ -96,7 +99,11 @@ class FVDECLSPEC GLSampleWindow : public nekomimi::MIMIWindow { return &this->getRenderInterface()->as(); } - void setColorSpace(bool srgb); + void setColorSpace(glsample::ColorSpace srgb); + glsample::ColorSpace getColorSpace() const noexcept; + + glsample::ColorSpaceConverter *getColorSpaceConverter() const noexcept { return this->colorSpace; } + void vsync(bool enable_vsync); void enableRenderDoc(bool status); @@ -109,6 +116,8 @@ class FVDECLSPEC GLSampleWindow : public nekomimi::MIMIWindow { void createDefaultFrameBuffer(); void updateDefaultFramebuffer(); int getDefaultFramebuffer() const noexcept; + glsample::FrameBuffer *getFrameBuffer() { return this->defaultFramebuffer; } + glsample::PostProcessingManager *getPostProcessingManager() const noexcept { return this->postprocessingManager; } size_t prev_frame_sample_count = 0; size_t prev_frame_primitive_count = 0; @@ -124,7 +133,8 @@ class FVDECLSPEC GLSampleWindow : public nekomimi::MIMIWindow { fragcore::SDLInput input; bool debugGL = true; - glsample::ColorSpaceConverter *colorSpace; + glsample::PostProcessingManager *postprocessingManager; + glsample::ColorSpaceConverter *colorSpace = nullptr; /* */ size_t frameCount = 0; @@ -133,15 +143,10 @@ class FVDECLSPEC GLSampleWindow : public nekomimi::MIMIWindow { unsigned int queries[10]; fragcore::IFileSystem *filesystem; - int preWidth, preHeight; + int preWidth = -1; + int preHeight = -1; - /* Default framebuffer. */ - using FrameBuffer = struct framebuffer_t { - unsigned int framebuffer; - unsigned int attachement0; - unsigned int depthbuffer; - }; - FrameBuffer *defaultFramebuffer = nullptr; + glsample::FrameBuffer *defaultFramebuffer = nullptr; protected: spdlog::logger *logger; diff --git a/common/GLUIComponent.h b/common/GLUIComponent.h index 9af699f..f6f932b 100644 --- a/common/GLUIComponent.h +++ b/common/GLUIComponent.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/common/IOUtil.h b/common/IOUtil.h index 5fb0fbc..0347d6a 100644 --- a/common/IOUtil.h +++ b/common/IOUtil.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/common/Importer/ImageImport.cpp b/common/Importer/ImageImport.cpp index ea9c922..b747fd5 100644 --- a/common/Importer/ImageImport.cpp +++ b/common/Importer/ImageImport.cpp @@ -232,7 +232,7 @@ int TextureImporter::loadCubeMap(const std::vector &paths, const Co FVALIDATE_GL_CALL(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); FVALIDATE_GL_CALL(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - + /* */ FVALIDATE_GL_CALL(glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16)); const float border[4] = {1, 1, 1, 1}; diff --git a/common/Importer/ImageImport.h b/common/Importer/ImageImport.h index 8a05078..6a7143e 100644 --- a/common/Importer/ImageImport.h +++ b/common/Importer/ImageImport.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,15 +45,15 @@ namespace glsample { virtual ~TextureImporter(); int loadImage2D(const std::string &path, const ColorSpace colorSpace = ColorSpace::Raw, - const TextureCompression compression = TextureCompression::Default); + const TextureCompression compression = TextureCompression::None); int loadImage2DRaw(const fragcore::Image &image, const ColorSpace colorSpace = ColorSpace::Raw, - const TextureCompression compression = TextureCompression::Default); + const TextureCompression compression = TextureCompression::None); int loadCubeMap(const std::string &px, const std::string &nx, const std::string &py, const std::string &ny, const std::string &pz, const std::string &nz, const ColorSpace colorSpace = ColorSpace::Raw, - const TextureCompression compression = TextureCompression::Default); + const TextureCompression compression = TextureCompression::None); int loadCubeMap(const std::vector &paths, const ColorSpace colorSpace = ColorSpace::Raw, - const TextureCompression compression = TextureCompression::Default); + const TextureCompression compression = TextureCompression::None); private: fragcore::IFileSystem *filesystem = nullptr; diff --git a/common/Importer/ImportHelper.h b/common/Importer/ImportHelper.h index 5b6596b..7c680af 100644 --- a/common/Importer/ImportHelper.h +++ b/common/Importer/ImportHelper.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/common/Importer/ModelImporter.h b/common/Importer/ModelImporter.h index 05b576e..7f7d61e 100644 --- a/common/Importer/ModelImporter.h +++ b/common/Importer/ModelImporter.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/common/Importer/Scene.h b/common/Importer/Scene.h index 0d4d496..9c5ea31 100644 --- a/common/Importer/Scene.h +++ b/common/Importer/Scene.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/common/PostProcessing/CMakeLists.txt b/common/PostProcessing/CMakeLists.txt new file mode 100644 index 0000000..7ef5ec8 --- /dev/null +++ b/common/PostProcessing/CMakeLists.txt @@ -0,0 +1,12 @@ +# FILE(GLOB SOURCE_POST_PROCESSING_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +# FILE(GLOB HEADER_POST_PROCESSING_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) + +# ADD_LIBRARY(gl-sample-postprocessing ${SOURCE_POST_PROCESSING_FILES} ${HEADER_POST_PROCESSING_FILES}) +# TARGET_LINK_LIBRARIES(gl-sample-postprocessing PUBLIC fmt fragcore) +# ADD_DEPENDENCIES(gl-sample-postprocessing fragcore) + +# TARGET_INCLUDE_DIRECTORIES(gl-sample-postprocessing PUBLIC +# ${CMAKE_CURRENT_SOURCE_DIR} +# ) + +# INSTALL(TARGETS gl-sample-postprocessing DESTINATION lib) \ No newline at end of file diff --git a/common/PostProcessing/ColorSpaceConverter.cpp b/common/PostProcessing/ColorSpaceConverter.cpp new file mode 100644 index 0000000..05d8021 --- /dev/null +++ b/common/PostProcessing/ColorSpaceConverter.cpp @@ -0,0 +1,226 @@ +#include "ColorSpaceConverter.h" +#include "Common.h" +#include "ShaderLoader.h" +#include + +using namespace glsample; + +ColorSpaceConverter::~ColorSpaceConverter() { + if (this->aes_program > 0) { + glDeleteProgram(this->aes_program); + } + if (this->gamma_program > 0) { + glDeleteProgram(this->gamma_program); + } + if (this->falsecolor_program > 0) { + glDeleteProgram(this->falsecolor_program); + } +} + +void ColorSpaceConverter::initialize(fragcore::IFileSystem *filesystem) { + + const char *AES_path = "Shaders/postprocessingeffects/colorspace/aces.comp.spv"; + const char *gamma_path = "Shaders/postprocessingeffects/colorspace/gamma.comp.spv"; + + const char *heatwave_path = "Shaders/postprocessingeffects/colorspace/heatmap.comp.spv"; + const char *kronos_pbr_path = "Shaders/postprocessingeffects/colorspace/KhronosPBRNeutral.comp.spv"; + + if (this->aes_program == -1) { + /* */ + const std::vector compute_AES_binary = IOUtil::readFileData(AES_path, filesystem); + const std::vector compute_Gamma_binary = IOUtil::readFileData(gamma_path, filesystem); + const std::vector compute_HeatWave_binary = IOUtil::readFileData(heatwave_path, filesystem); + const std::vector compute_Kronas_PBR_binary = + IOUtil::readFileData(kronos_pbr_path, filesystem); + + fragcore::ShaderCompiler::CompilerConvertOption compilerOptions; + compilerOptions.target = fragcore::ShaderLanguage::GLSL; + compilerOptions.glslVersion = 410; + + /* */ + this->aes_program = ShaderLoader::loadComputeProgram(compilerOptions, &compute_AES_binary); + this->gamma_program = ShaderLoader::loadComputeProgram(compilerOptions, &compute_Gamma_binary); + this->falsecolor_program = ShaderLoader::loadComputeProgram(compilerOptions, &compute_HeatWave_binary); + this->kronos_neutral_pbr_program = + ShaderLoader::loadComputeProgram(compilerOptions, &compute_Kronas_PBR_binary); + } + + glUseProgram(this->aes_program); + + glUniform1i(glGetUniformLocation(this->aes_program, "texture0"), 1); + + GLint localWorkGroupSize[3]; + + glGetProgramiv(this->aes_program, GL_COMPUTE_WORK_GROUP_SIZE, localWorkGroupSize); + + glUseProgram(0); + + { + glUseProgram(this->gamma_program); + + glUniform1i(glGetUniformLocation(this->gamma_program, "texture0"), 1); + + /* */ + glGetProgramiv(this->gamma_program, GL_COMPUTE_WORK_GROUP_SIZE, localWorkGroupSize); + + /* Parameters. */ + glUniform1f(glGetUniformLocation(this->gamma_program, "settings.gamma"), getGammeSettings().gamma); + glUniform1f(glGetUniformLocation(this->gamma_program, "settings.exposure"), getGammeSettings().exposure); + + glUseProgram(0); + } + + { + glUseProgram(this->falsecolor_program); + + glUniform1i(glGetUniformLocation(this->falsecolor_program, "texture0"), 1); + + glGetProgramiv(this->falsecolor_program, GL_COMPUTE_WORK_GROUP_SIZE, localWorkGroupSize); + + glUseProgram(0); + } + + { + glUseProgram(this->kronos_neutral_pbr_program); + + glUniform1i(glGetUniformLocation(this->kronos_neutral_pbr_program, "texture0"), 1); + + glGetProgramiv(this->kronos_neutral_pbr_program, GL_COMPUTE_WORK_GROUP_SIZE, localWorkGroupSize); + + glUseProgram(0); + } +} + +void ColorSpaceConverter::convert(unsigned int texture) { + + GLint width = 0; + GLint height = 0; + + if (this->getColorSpace() == ColorSpace::Raw) { + return; + } + + if (this->getColorSpace() != ColorSpace::Raw) { + /* Wait in till image has been written. */ + glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + } + + switch (this->getColorSpace()) { + case ColorSpace::ACES: { + + glBindTexture(GL_TEXTURE_2D, texture); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); + + GLint localWorkGroupSize[3]; + + glUseProgram(this->aes_program); + + glGetProgramiv(this->aes_program, GL_COMPUTE_WORK_GROUP_SIZE, localWorkGroupSize); + + /* The image where the graphic version will be stored as. */ + glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA16F); + + const unsigned int WorkGroupX = std::ceil(width / (float)localWorkGroupSize[0]); + const unsigned int WorkGroupY = std::ceil(height / (float)localWorkGroupSize[1]); + + if (WorkGroupX > 0 && WorkGroupY > 0) { + + glDispatchCompute(WorkGroupX, WorkGroupY, 1); + } + glUseProgram(0); + } break; + case ColorSpace::FalseColor: { + + glBindTexture(GL_TEXTURE_2D, texture); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); + + GLint localWorkGroupSize[3]; + + glUseProgram(this->falsecolor_program); + + glGetProgramiv(this->falsecolor_program, GL_COMPUTE_WORK_GROUP_SIZE, localWorkGroupSize); + + /* The image where the graphic version will be stored as. */ + glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA16F); + + const unsigned int WorkGroupX = std::ceil(width / (float)localWorkGroupSize[0]); + const unsigned int WorkGroupY = std::ceil(height / (float)localWorkGroupSize[1]); + + if (WorkGroupX > 0 && WorkGroupY > 0) { + + glDispatchCompute(WorkGroupX, WorkGroupY, 1); + } + glUseProgram(0); + } break; + case ColorSpace::KhronosPBRNeutral: { + glBindTexture(GL_TEXTURE_2D, texture); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); + + GLint localWorkGroupSize[3]; + + glUseProgram(this->kronos_neutral_pbr_program); + + glGetProgramiv(this->kronos_neutral_pbr_program, GL_COMPUTE_WORK_GROUP_SIZE, localWorkGroupSize); + + /* The image where the graphic version will be stored as. */ + glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA16F); + + const unsigned int WorkGroupX = std::ceil(width / (float)localWorkGroupSize[0]); + const unsigned int WorkGroupY = std::ceil(height / (float)localWorkGroupSize[1]); + + if (WorkGroupX > 0 && WorkGroupY > 0) { + + glDispatchCompute(WorkGroupX, WorkGroupY, 1); + } + glUseProgram(0); + } break; + case ColorSpace::SRGB: + break; + case ColorSpace::Raw: + default: + return; + } + + if (this->getColorSpace() != ColorSpace::Raw) { + /* Wait in till image has been written. */ + glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + } + + /* */ + if (this->getColorSpace() != ColorSpace::Raw) { + + /* Wait in till image has been written. */ + glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + + glBindTexture(GL_TEXTURE_2D, texture); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); + + GLint localWorkGroupSize[3]; + + glUseProgram(this->gamma_program); + /* Parameters. */ + glUniform1f(glGetUniformLocation(this->gamma_program, "settings.gamma"), getGammeSettings().gamma); + glUniform1f(glGetUniformLocation(this->gamma_program, "settings.exposure"), getGammeSettings().exposure); + + glGetProgramiv(this->gamma_program, GL_COMPUTE_WORK_GROUP_SIZE, localWorkGroupSize); + + /* The image where the graphic version will be stored as. */ + glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA16F); + + const unsigned int WorkGroupX = std::ceil(width / (float)localWorkGroupSize[0]); + const unsigned int WorkGroupY = std::ceil(height / (float)localWorkGroupSize[1]); + + if (WorkGroupX > 0 && WorkGroupY > 0) { + + glDispatchCompute(WorkGroupX, WorkGroupY, 1); + } + glUseProgram(0); + } +} + +void ColorSpaceConverter::setColorSpace(const glsample::ColorSpace srgb) noexcept { this->colorSpace = srgb; } +glsample::ColorSpace ColorSpaceConverter::getColorSpace() const noexcept { return this->colorSpace; } \ No newline at end of file diff --git a/common/PostProcessing/ColorSpaceConverter.h b/common/PostProcessing/ColorSpaceConverter.h new file mode 100644 index 0000000..592612b --- /dev/null +++ b/common/PostProcessing/ColorSpaceConverter.h @@ -0,0 +1,48 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2024 Valdemar Lindberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ +#pragma once +#include "../Common.h" +#include "PostProcessing.h" + +namespace glsample { + + class FVDECLSPEC ColorSpaceConverter : public PostProcessing { + + public: + ColorSpaceConverter() = default; + ~ColorSpaceConverter() override; + + void initialize(fragcore::IFileSystem *filesystem) override; + + public: + void convert(unsigned int texture); + + void setColorSpace(const glsample::ColorSpace srgb) noexcept; + glsample::ColorSpace getColorSpace() const noexcept; + + GammaCorrectionSettings &getGammeSettings() noexcept { return this->correct_settings; } + + private: + ColorSpace colorSpace = ColorSpace::Raw; + int aes_program = -1; + int gamma_program = -1; + int falsecolor_program = -1; + int kronos_neutral_pbr_program = -1; + GammaCorrectionSettings correct_settings; + + // int localWorkGroupSize[3]; + }; +} // namespace glsample diff --git a/common/PostProcessing/MistPostProcessing.cpp b/common/PostProcessing/MistPostProcessing.cpp new file mode 100644 index 0000000..4f41936 --- /dev/null +++ b/common/PostProcessing/MistPostProcessing.cpp @@ -0,0 +1,80 @@ +#include "MistPostProcessing.h" +#include "Core/Object.h" +#include "ShaderLoader.h" +#include + +using namespace glsample; + +MistPostProcessing::MistPostProcessing() { + this->setName("MistFog"); +} + +MistPostProcessing::~MistPostProcessing() { + if (this->mist_program >= 0) { + glDeleteProgram(this->mist_program); + } +} + +void MistPostProcessing::initialize(fragcore::IFileSystem *filesystem) { + const char *frag_path = "Shaders/postprocessingeffects/mistfog.frag.spv"; + const char *vertex_path = "Shaders/postprocessingeffects/postprocessing.vert.spv"; + + if (this->mist_program == -1) { + /* */ + const std::vector vertex_mistfog_post_processing_binary = + IOUtil::readFileData(vertex_path, filesystem); + + const std::vector fragment_mistfog_post_processing_binary = + IOUtil::readFileData(frag_path, filesystem); + + fragcore::ShaderCompiler::CompilerConvertOption compilerOptions; + compilerOptions.target = fragcore::ShaderLanguage::GLSL; + compilerOptions.glslVersion = 330; + + /* */ + this->mist_program = ShaderLoader::loadGraphicProgram(compilerOptions, &vertex_mistfog_post_processing_binary, + &fragment_mistfog_post_processing_binary); + } + + glUseProgram(this->mist_program); + + glUniform1i(glGetUniformLocation(this->mist_program, "texture0"), 0); + glUniform1i(glGetUniformLocation(this->mist_program, "DepthTexture"), 1); + glUniform1i(glGetUniformLocation(this->mist_program, "IrradianceTexture"), 2); + + glUseProgram(0); + + glGenVertexArrays(1, &this->vao); +} + +void MistPostProcessing::render(unsigned int skybox, unsigned int frame_texture, unsigned int depth_texture) { + + glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + + glBindVertexArray(this->vao); + + glUseProgram(this->mist_program); + + /* */ + glDisable(GL_CULL_FACE); + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + + /* */ + glActiveTexture(GL_TEXTURE0 + 0); + glBindTexture(GL_TEXTURE_2D, frame_texture); + + /* */ + glActiveTexture(GL_TEXTURE0 + 1); + glBindTexture(GL_TEXTURE_2D, depth_texture); + + /* */ + glActiveTexture(GL_TEXTURE0 + 2); + glBindTexture(GL_TEXTURE_2D, skybox); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glUseProgram(0); + + glBindVertexArray(0); +} \ No newline at end of file diff --git a/common/PostProcessing/MistPostProcessing.h b/common/PostProcessing/MistPostProcessing.h new file mode 100644 index 0000000..c22a732 --- /dev/null +++ b/common/PostProcessing/MistPostProcessing.h @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2024 Valdemar Lindberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ +#pragma once +#include "PostProcessing.h" +#include "SampleHelper.h" + +namespace glsample { + + class FVDECLSPEC MistPostProcessing : public PostProcessing { + public: + MistPostProcessing(); + ~MistPostProcessing() override; + + using MistUniformBuffer = struct mist_uniform_buffer_t { + CameraInstance instance; + FogSettings fogSettings; + }; + + void initialize(fragcore::IFileSystem *filesystem) override; + + void render(unsigned int skybox, unsigned int frame_texture, unsigned int depth_texture); + + private: + int mist_program = -1; + unsigned int vao = 0; + unsigned int uniform_buffer = 0; + }; +} // namespace glsample diff --git a/common/PostProcessing/PostProcessing.h b/common/PostProcessing/PostProcessing.h new file mode 100644 index 0000000..5c8535f --- /dev/null +++ b/common/PostProcessing/PostProcessing.h @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2024 Valdemar Lindberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ +#pragma once +#include "GLSampleSession.h" +#include "IO/IFileSystem.h" +#include "Math3D/Color.h" + +namespace glsample { + + class FVDECLSPEC PostProcessing : public fragcore::Object { + public: + PostProcessing() = default; + ~PostProcessing() override = default; + + virtual void initialize(fragcore::IFileSystem *filesystem) = 0; + + virtual void bind() {}; + + virtual void draw() {}; + + virtual bool isEnabled() { return false; } + + protected: + bool computeShaderSupported = true; + }; +} // namespace glsample diff --git a/common/PostProcessing/PostProcessingManager.h b/common/PostProcessing/PostProcessingManager.h new file mode 100644 index 0000000..84d150d --- /dev/null +++ b/common/PostProcessing/PostProcessingManager.h @@ -0,0 +1,36 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2024 Valdemar Lindberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ +#pragma once +#include "GLSampleSession.h" +#include "IO/IFileSystem.h" +#include "Math3D/Color.h" +#include "PostProcessing.h" + +namespace glsample { + + class FVDECLSPEC PostProcessingManager : public fragcore::Object { + public: + PostProcessingManager() = default; + ~PostProcessingManager() override = default; + + void addPostProcessing(PostProcessing &postProcessing); + + size_t getNrPostProcessing() const noexcept; + PostProcessing &getPostProcessing(const size_t index) const noexcept; + + protected: + }; +} // namespace glsample diff --git a/common/PostProcessing/SobelPostProcessing.cpp b/common/PostProcessing/SobelPostProcessing.cpp new file mode 100644 index 0000000..b3c1126 --- /dev/null +++ b/common/PostProcessing/SobelPostProcessing.cpp @@ -0,0 +1,7 @@ +#include "SobelPostProcessing.h" + +using namespace glsample; + +SobelProcessing::~SobelProcessing() {} + +void SobelProcessing::initialize(fragcore::IFileSystem *filesystem) {} diff --git a/common/ColorSpaceConverter.h b/common/PostProcessing/SobelPostProcessing.h similarity index 68% rename from common/ColorSpaceConverter.h rename to common/PostProcessing/SobelPostProcessing.h index 2670f8d..3b991ec 100644 --- a/common/ColorSpaceConverter.h +++ b/common/PostProcessing/SobelPostProcessing.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -14,20 +14,20 @@ * all copies or substantial portions of the Software. */ #pragma once -#include "GLSampleSession.h" -#include "Math3D/Color.h" +#include "PostProcessing.h" namespace glsample { - class FVDECLSPEC ColorSpaceConverter { + class FVDECLSPEC SobelProcessing : public PostProcessing { + public: + SobelProcessing() = default; + ~SobelProcessing() override; - enum ColorSpaceType { - Linear = 0, - Gamma = 1, - ACES = 2, - }; + void initialize(fragcore::IFileSystem *filesystem) override; - public: - ColorSpaceConverter(); + void convert(unsigned int texture); + + private: + int sobel_program = -1; }; } // namespace glsample diff --git a/common/SampleHelper.h b/common/SampleHelper.h index 99d686f..f0c3db1 100644 --- a/common/SampleHelper.h +++ b/common/SampleHelper.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,6 +38,11 @@ namespace glsample { Height /* */ }; + using GammaCorrectionSettings = struct gamme_correct_settings_t { + float exposure = 1.0f; + float gamma = 2.2f; + }; + using FogSettings = struct fog_settings_t { glm::vec4 fogColor = glm::vec4(0.3, 0.3, 0.45, 1); @@ -92,6 +97,14 @@ namespace glsample { glm::vec4 position_size; }; + /* Default framebuffer. */ + using FrameBuffer = struct framebuffer_t { + unsigned int framebuffer; + unsigned int attachement0; + unsigned int intermediate; + unsigned int depthbuffer; + }; + template inline glm::mat E2GLM(const Eigen::Matrix &em) noexcept { glm::mat mat; diff --git a/common/ShaderLoader.cpp b/common/ShaderLoader.cpp index 9f51441..1f43966 100644 --- a/common/ShaderLoader.cpp +++ b/common/ShaderLoader.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -179,6 +179,15 @@ int ShaderLoader::loadComputeProgram(const fragcore::ShaderCompiler::CompilerCon const std::vector *compute_binary) { std::vector compute_source; + if (glSpecializeShaderARB) { + /* Load SPIRV. */ + // if (compute_binary) { + // compute_source.resize(compute_binary[0].size() * sizeof(uint32_t)); + // std::memcpy(compute_source.data(), compute_binary[0].data(), compute_source.size()); + // } + } else { + } + if (compute_binary) { const std::vector vertex_source_code = @@ -215,7 +224,6 @@ int ShaderLoader::loadComputeProgram(const std::vector * char log[4096]; glGetProgramInfoLog(program, sizeof(log), nullptr, log); fragcore::checkError(); - throw cxxexcept::RuntimeException("Failed to link program: {}", log); } @@ -291,10 +299,9 @@ int ShaderLoader::loadMeshProgram(const std::vector *meshs, const std::vec glGetProgramiv(program, GL_LINK_STATUS, &lstatus); fragcore::checkError(); if (lstatus != GL_TRUE) { - char log[4096]; + GLchar log[4096]; glGetProgramInfoLog(program, sizeof(log), nullptr, log); fragcore::checkError(); - throw cxxexcept::RuntimeException("Failed to link program: {}", log); } @@ -330,9 +337,10 @@ static void checkShaderError(int shader) { glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); fragcore::checkError(); - char log[4096]; + GLchar log[4096]; glGetShaderInfoLog(shader, sizeof(log), &maxLength, log); fragcore::checkError(); + std::cout << log << std::endl; } } @@ -350,17 +358,19 @@ int ShaderLoader::loadShader(const std::vector &source, const int type) { /* Load as Spirv if data is Spirv file and supported. */ if (spirv_magic_number == magic_number && glSpecializeShaderARB) { + glShaderBinary(1, &shader, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, source.data(), source.size()); + fragcore::checkError(); glSpecializeShaderARB(shader, "main", 0, nullptr, nullptr); + fragcore::checkError(); } else { glShaderSource(shader, 1, (const GLchar **)&source_data, nullptr); fragcore::checkError(); + /* */ + glCompileShader(shader); + fragcore::checkError(); } - /* */ - glCompileShader(shader); - fragcore::checkError(); - /* */ checkShaderError(shader); return shader; diff --git a/common/ShaderLoader.h b/common/ShaderLoader.h index bb6c571..68c5e25 100644 --- a/common/ShaderLoader.h +++ b/common/ShaderLoader.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,7 +45,6 @@ namespace glsample { static int loadComputeProgram(const fragcore::ShaderCompiler::CompilerConvertOption &compilerOptions, const std::vector *compute); static int loadComputeProgram(const std::vector *> &computePaths); - static int loadComputeProgram(const std::vector &compute); /** * @brief diff --git a/common/Skybox.cpp b/common/Skybox.cpp index fb69493..ebc6103 100644 --- a/common/Skybox.cpp +++ b/common/Skybox.cpp @@ -66,12 +66,14 @@ namespace glsample { (frameIndex % this->nrUniformBuffer) * this->uniformAlignSize, this->uniformAlignSize); /* Extract current state. to restore afterward rendered the skybox. */ - GLint cullstate = 0, blend = 0, depth_test = 0, depth_func = 0; + GLint cullstate = 0, blend = 0, depth_test = 0, depth_func = 0, cull_face_mode = 0; + GLboolean depth_write = 0; glGetIntegerv(GL_CULL_FACE, &cullstate); glGetIntegerv(GL_BLEND, &blend); glGetIntegerv(GL_DEPTH_TEST, &depth_test); glGetIntegerv(GL_DEPTH_FUNC, &depth_func); - glGetIntegerv(GL_DEPTH_FUNC, &depth_func); + glGetIntegerv(GL_CULL_FACE_MODE, &cull_face_mode); + glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_write); /* */ glEnable(GL_CULL_FACE); @@ -118,7 +120,8 @@ namespace glsample { } glDepthFunc(depth_func); - glDepthMask(GL_TRUE); + glDepthMask(depth_write); + glCullFace(cull_face_mode); } this->frameIndex = (this->frameIndex + 1) % this->nrUniformBuffer; @@ -135,9 +138,9 @@ namespace glsample { ImGui::ColorEdit4("Tint", &this->uniform_stage_buffer.tintColor[0], ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_Float); - ImGui::DragFloat("Exposure", &this->uniform_stage_buffer.exposure); + ImGui::DragFloat("Exposure", &this->uniform_stage_buffer.correct_settings.exposure); ImGui::SameLine(); - ImGui::DragFloat("Gamma", &this->uniform_stage_buffer.gamma); + ImGui::DragFloat("Gamma", &this->uniform_stage_buffer.correct_settings.gamma); ImGui::EndGroup(); } ImGui::PopID(); @@ -161,7 +164,7 @@ namespace glsample { compilerOptions.glslVersion = 330; /* Create skybox graphic pipeline program. */ - int skybox_program = + const int skybox_program = ShaderLoader::loadGraphicProgram(compilerOptions, &vertex_skybox_binary, &fragment_skybox_binary); /* Setup graphic pipeline. */ diff --git a/common/Skybox.h b/common/Skybox.h index 6633df7..4c121d4 100644 --- a/common/Skybox.h +++ b/common/Skybox.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -34,8 +34,7 @@ namespace glsample { glm::mat4 proj; glm::mat4 modelViewProjection; glm::vec4 tintColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); - float exposure = 1.0f; - float gamma = 2.2f; + GammaCorrectionSettings correct_settings; } FV_ALIGN(4) uniform_stage_buffer; Skybox(); diff --git a/common/Util/Camera.h b/common/Util/Camera.h index 6a0198c..79eb8ef 100644 --- a/common/Util/Camera.h +++ b/common/Util/Camera.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/common/Util/CameraController.h b/common/Util/CameraController.h index cea8369..a104bfb 100644 --- a/common/Util/CameraController.h +++ b/common/Util/CameraController.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,7 +30,6 @@ namespace glsample { class CameraController : public Frustum { public: ~CameraController() override = default; - CameraController() = default; void update(const float deltaTime) noexcept; diff --git a/common/Util/Frustum.cpp b/common/Util/Frustum.cpp index 3538d99..72ba5eb 100644 --- a/common/Util/Frustum.cpp +++ b/common/Util/Frustum.cpp @@ -2,7 +2,7 @@ namespace glsample { - Frustum::Frustum(const Frustum &other) noexcept : Camera(other) {} + Frustum::Frustum(const Frustum &other) : Camera(other) {} void Frustum::calcFrustumPlanes(const Vector3 &position, const Vector3 &look_forward, const Vector3 &up, const Vector3 &right) { diff --git a/common/Util/Frustum.h b/common/Util/Frustum.h index ba4b82c..1332ea6 100644 --- a/common/Util/Frustum.h +++ b/common/Util/Frustum.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -108,8 +108,8 @@ namespace glsample { virtual Intersection intersectionFrustum(const Frustum &frustum) const noexcept; protected: /* Makes the object only inheritable . */ - Frustum() noexcept = default; - Frustum(const Frustum &other) noexcept; + Frustum() = default; + Frustum(const Frustum &other); private: /* Attributes. */ Plane planes[6]; /* */ diff --git a/common/Util/ProcessDataUtil.cpp b/common/Util/ProcessDataUtil.cpp index ae86038..8412db8 100644 --- a/common/Util/ProcessDataUtil.cpp +++ b/common/Util/ProcessDataUtil.cpp @@ -2,6 +2,7 @@ #include "IOUtil.h" #include "ShaderLoader.h" #include + using namespace glsample; ProcessData::ProcessData(fragcore::IFileSystem *filesystem) : filesystem(filesystem) {} @@ -40,7 +41,7 @@ void ProcessData::computeIrradiance(unsigned int env_source, unsigned int irradi if (this->irradiance_program == -1) { /* */ - const std::vector compute_marching_cube_generator_binary = + const std::vector compute_irradiance_env_binary = IOUtil::readFileData(irradiance_path, filesystem); fragcore::ShaderCompiler::CompilerConvertOption compilerOptions; @@ -48,8 +49,7 @@ void ProcessData::computeIrradiance(unsigned int env_source, unsigned int irradi compilerOptions.glslVersion = 410; /* */ - this->irradiance_program = - ShaderLoader::loadComputeProgram(compilerOptions, &compute_marching_cube_generator_binary); + this->irradiance_program = ShaderLoader::loadComputeProgram(compilerOptions, &compute_irradiance_env_binary); } glUseProgram(this->irradiance_program); @@ -78,8 +78,10 @@ void ProcessData::computeIrradiance(unsigned int env_source, unsigned int irradi /* The image where the graphic version will be stored as. */ glBindImageTexture(1, irradiance_target, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F); - glDispatchCompute(std::ceil(width / (float)localWorkGroupSize[0]), std::ceil(height / (float)localWorkGroupSize[1]), - 1); + const unsigned int WorkGroupX = std::ceil(width / (float)localWorkGroupSize[0]); + const unsigned int WorkGroupY = std::ceil(height / (float)localWorkGroupSize[1]); + + glDispatchCompute(WorkGroupX, WorkGroupY, 1); glBindTexture(GL_TEXTURE_2D, 0); diff --git a/common/Util/ProcessDataUtil.h b/common/Util/ProcessDataUtil.h index 41f32a1..10c4f1f 100644 --- a/common/Util/ProcessDataUtil.h +++ b/common/Util/ProcessDataUtil.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2023 Valdemar Lindberg + * Copyright (c) 2024 Valdemar Lindberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/download_asset.py b/download_asset.py index 55c7169..ac6f984 100644 --- a/download_asset.py +++ b/download_asset.py @@ -22,6 +22,7 @@ download_asset_directly = [ # Textures "https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/4k/snowy_forest_4k.exr", + "https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/4k/industrial_sunset_puresky_4k.exr" ] output = sys.argv[1]