Browse Source

Move shader template class into render folder

master
C. J. Howard 3 years ago
parent
commit
5547960119
7 changed files with 23 additions and 19 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +3
    -2
      src/ecs/systems/astronomy-system.cpp
  3. +11
    -3
      src/game/states/play-state.cpp
  4. +1
    -1
      src/renderer/passes/material-pass.cpp
  5. +1
    -5
      src/renderer/shader-template.cpp
  6. +0
    -4
      src/renderer/shader-template.hpp
  7. +6
    -4
      src/resources/shader-program-loader.cpp

+ 1
- 0
CMakeLists.txt View File

@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG) find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies # Determine dependencies
set(STATIC_LIBS set(STATIC_LIBS
dr_wav dr_wav

+ 3
- 2
src/ecs/systems/astronomy-system.cpp View File

@ -88,11 +88,12 @@ void astronomy_system::update(double t, double dt)
// Set sun color // Set sun color
float factor = std::cos(spherical.y); 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<float>(astro::blackbody(correlated_temperature)); float3 correlated_color = math::type_cast<float>(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_color(correlated_color);
sun_light->set_intensity(intensity); sun_light->set_intensity(intensity);

+ 11
- 3
src/game/states/play-state.cpp View File

@ -148,10 +148,10 @@ void play_state_enter(game_context* ctx)
float3 sun_color = math::type_cast<float>(astro::blackbody(6000.0)); // NOTE: this is linear sRGB, should be ACEScg float3 sun_color = math::type_cast<float>(astro::blackbody(6000.0)); // NOTE: this is linear sRGB, should be ACEScg
sun->set_color(sun_color); sun->set_color(sun_color);
sun->set_intensity(750.0f);
sun->set_intensity(1000.0f);
sun->set_light_texture(resource_manager->load<gl::texture_2d>("forest-gobo.tex")); sun->set_light_texture(resource_manager->load<gl::texture_2d>("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->look_at({2, 1, 0}, {0, 0, 0}, {0, 0, 1});
sun->update_tweens(); sun->update_tweens();
ctx->overworld_scene->add_object(sun); 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<ecs::archetype>("flashlight-light-cone.ent"); ecs::archetype* flashlight_light_cone_archetype = resource_manager->load<ecs::archetype>("flashlight-light-cone.ent");
ecs::archetype* lens_light_cone_archetype = resource_manager->load<ecs::archetype>("lens-light-cone.ent"); ecs::archetype* lens_light_cone_archetype = resource_manager->load<ecs::archetype>("lens-light-cone.ent");
ecs::archetype* cube_archetype = resource_manager->load<ecs::archetype>("unit-cube.ent"); ecs::archetype* cube_archetype = resource_manager->load<ecs::archetype>("unit-cube.ent");
ecs::archetype* color_checker_archetype = resource_manager->load<ecs::archetype>("color-checker.ent");
// Create tools // Create tools
forceps_archetype->assign(ecs_registry, ctx->forceps_entity); 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); auto cube = cube_archetype->create(ecs_registry);
ecs::command::place(ecs_registry, cube, {10, 10}); 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<ecs::transform_component>(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 // Setup camera focal point
ecs::transform_component focal_point_transform; ecs::transform_component focal_point_transform;
focal_point_transform.local = math::identity_transform<float>; focal_point_transform.local = math::identity_transform<float>;

+ 1
- 1
src/renderer/passes/material-pass.cpp View File

@ -136,7 +136,7 @@ void material_pass::render(render_context* context) const
clip_depth[1] = context->camera->get_clip_far_tween().interpolate(context->alpha); 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 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; int active_material_flags = 0;

src/gl/shader-template.cpp → src/renderer/shader-template.cpp View File

@ -17,12 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "gl/shader-template.hpp"
#include "renderer/shader-template.hpp"
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
namespace gl {
shader_template::shader_template(const std::string& source_code) shader_template::shader_template(const std::string& source_code)
{ {
source(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()); return (define_directives.find(key) != define_directives.end());
} }
} // namespace gl

src/gl/shader-template.hpp → src/renderer/shader-template.hpp View File

@ -27,8 +27,6 @@
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
namespace gl {
/** /**
* Shader templates can be used to generate multiple shader variants from a single source. * Shader templates can be used to generate multiple shader variants from a single source.
* *
@ -131,6 +129,4 @@ private:
std::multimap<std::string, std::size_t> define_directives; std::multimap<std::string, std::size_t> define_directives;
}; };
} // namespace gl
#endif // ANTKEEPER_SHADER_TEMPLATE_HPP #endif // ANTKEEPER_SHADER_TEMPLATE_HPP

+ 6
- 4
src/resources/shader-program-loader.cpp View File

@ -20,7 +20,9 @@
#include "resources/resource-loader.hpp" #include "resources/resource-loader.hpp"
#include "resources/resource-manager.hpp" #include "resources/resource-manager.hpp"
#include "resources/text-file.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 <sstream> #include <sstream>
/** /**
@ -87,10 +89,10 @@ gl::shader_program* resource_loader::load(resource_manager*
std::copy(source_lines.begin(), source_lines.end(), std::ostream_iterator<std::string>(stream, "\n")); std::copy(source_lines.begin(), source_lines.end(), std::ostream_iterator<std::string>(stream, "\n"));
// Create shader template // 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 // 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 // Check if shader program was linked successfully
if (!program->was_linked()) if (!program->was_linked())
@ -99,7 +101,7 @@ gl::shader_program* resource_loader::load(resource_manager*
} }
// Destroy shader template // Destroy shader template
delete shader_template;
delete shader;
return program; return program;
} }

Loading…
Cancel
Save