From 5547960119abee265ee61db2a7884f149a8ee8b8 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Mon, 3 May 2021 15:50:44 +0800 Subject: [PATCH] Move shader template class into render folder --- CMakeLists.txt | 1 + src/ecs/systems/astronomy-system.cpp | 5 +++-- src/game/states/play-state.cpp | 14 +++++++++++--- src/renderer/passes/material-pass.cpp | 2 +- src/{gl => renderer}/shader-template.cpp | 6 +----- src/{gl => renderer}/shader-template.hpp | 4 ---- src/resources/shader-program-loader.cpp | 10 ++++++---- 7 files changed, 23 insertions(+), 19 deletions(-) rename src/{gl => renderer}/shader-template.cpp (98%) rename src/{gl => renderer}/shader-template.hpp (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4aa351..bc40e61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG) find_package(OpenAL REQUIRED CONFIG) find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") + # Determine dependencies set(STATIC_LIBS dr_wav diff --git a/src/ecs/systems/astronomy-system.cpp b/src/ecs/systems/astronomy-system.cpp index 26a8a3c..c09e35a 100644 --- a/src/ecs/systems/astronomy-system.cpp +++ b/src/ecs/systems/astronomy-system.cpp @@ -88,11 +88,12 @@ void astronomy_system::update(double t, double dt) // Set sun color float factor = std::cos(spherical.y); + factor = 1.0f - factor * factor; - float correlated_temperature = math::lerp(8000.0f, 2000.0f, factor); + float correlated_temperature = math::lerp(3000.0f, 8000.0f, factor); float3 correlated_color = math::type_cast(astro::blackbody(correlated_temperature)); - float intensity = math::lerp(1000.0f, 100.0f, factor); + float intensity = math::lerp(100.0f, 1000.0f, factor); sun_light->set_color(correlated_color); sun_light->set_intensity(intensity); diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index bcb2d12..033b04f 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -148,10 +148,10 @@ void play_state_enter(game_context* ctx) float3 sun_color = math::type_cast(astro::blackbody(6000.0)); // NOTE: this is linear sRGB, should be ACEScg sun->set_color(sun_color); - sun->set_intensity(750.0f); + sun->set_intensity(1000.0f); sun->set_light_texture(resource_manager->load("forest-gobo.tex")); - sun->set_light_texture_scale({500, 500}); - sun->set_light_texture_opacity(0.9f); + sun->set_light_texture_scale({2000, 2000}); + sun->set_light_texture_opacity(0.925f); sun->look_at({2, 1, 0}, {0, 0, 0}, {0, 0, 1}); sun->update_tweens(); ctx->overworld_scene->add_object(sun); @@ -187,6 +187,7 @@ void play_state_enter(game_context* ctx) ecs::archetype* flashlight_light_cone_archetype = resource_manager->load("flashlight-light-cone.ent"); ecs::archetype* lens_light_cone_archetype = resource_manager->load("lens-light-cone.ent"); ecs::archetype* cube_archetype = resource_manager->load("unit-cube.ent"); + ecs::archetype* color_checker_archetype = resource_manager->load("color-checker.ent"); // Create tools forceps_archetype->assign(ecs_registry, ctx->forceps_entity); @@ -262,6 +263,13 @@ void play_state_enter(game_context* ctx) auto cube = cube_archetype->create(ecs_registry); ecs::command::place(ecs_registry, cube, {10, 10}); + // Create color checker + auto color_checker = color_checker_archetype->create(ecs_registry); + ecs::command::place(ecs_registry, color_checker, {-10, -10}); + auto& cc_transform = ecs_registry.get(color_checker); + cc_transform.local.scale *= 10.0f; + cc_transform.local.rotation = math::angle_axis(math::radians(-90.0f), {1, 0, 0}); + // Setup camera focal point ecs::transform_component focal_point_transform; focal_point_transform.local = math::identity_transform; diff --git a/src/renderer/passes/material-pass.cpp b/src/renderer/passes/material-pass.cpp index 67feb56..8608142 100644 --- a/src/renderer/passes/material-pass.cpp +++ b/src/renderer/passes/material-pass.cpp @@ -136,7 +136,7 @@ void material_pass::render(render_context* context) const clip_depth[1] = context->camera->get_clip_far_tween().interpolate(context->alpha); float log_depth_coef = 2.0f / std::log2(clip_depth[1] + 1.0f); - float camera_exposure = std::exp2(-6.5f); + float camera_exposure = std::exp2(-7.0f); int active_material_flags = 0; diff --git a/src/gl/shader-template.cpp b/src/renderer/shader-template.cpp similarity index 98% rename from src/gl/shader-template.cpp rename to src/renderer/shader-template.cpp index bb0d983..774adf0 100644 --- a/src/gl/shader-template.cpp +++ b/src/renderer/shader-template.cpp @@ -17,12 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#include "gl/shader-template.hpp" +#include "renderer/shader-template.hpp" #include #include -namespace gl { - shader_template::shader_template(const std::string& source_code) { source(source_code); @@ -218,5 +216,3 @@ bool shader_template::has_define_directive(const std::string& key) const { return (define_directives.find(key) != define_directives.end()); } - -} // namespace gl diff --git a/src/gl/shader-template.hpp b/src/renderer/shader-template.hpp similarity index 99% rename from src/gl/shader-template.hpp rename to src/renderer/shader-template.hpp index 0529373..489cad0 100644 --- a/src/gl/shader-template.hpp +++ b/src/renderer/shader-template.hpp @@ -27,8 +27,6 @@ #include #include -namespace gl { - /** * Shader templates can be used to generate multiple shader variants from a single source. * @@ -131,6 +129,4 @@ private: std::multimap define_directives; }; -} // namespace gl - #endif // ANTKEEPER_SHADER_TEMPLATE_HPP diff --git a/src/resources/shader-program-loader.cpp b/src/resources/shader-program-loader.cpp index a5ada3a..cf46729 100644 --- a/src/resources/shader-program-loader.cpp +++ b/src/resources/shader-program-loader.cpp @@ -20,7 +20,9 @@ #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/text-file.hpp" -#include "gl/shader-template.hpp" +#include "renderer/shader-template.hpp" +#include "gl/shader-object.hpp" +#include "gl/shader-program.hpp" #include /** @@ -87,10 +89,10 @@ gl::shader_program* resource_loader::load(resource_manager* std::copy(source_lines.begin(), source_lines.end(), std::ostream_iterator(stream, "\n")); // Create shader template - gl::shader_template* shader_template = new gl::shader_template(stream.str()); + shader_template* shader = new shader_template(stream.str()); // Build shader program - gl::shader_program* program = shader_template->build(gl::shader_template::dictionary_type()); + gl::shader_program* program = shader->build(shader_template::dictionary_type()); // Check if shader program was linked successfully if (!program->was_linked()) @@ -99,7 +101,7 @@ gl::shader_program* resource_loader::load(resource_manager* } // Destroy shader template - delete shader_template; + delete shader; return program; }