Browse Source

Add prefix to material shader inputs, pre-expose lights in material pass

master
C. J. Howard 3 years ago
parent
commit
aaa303d20b
6 changed files with 27 additions and 14 deletions
  1. +1
    -0
      src/game/bootloader.cpp
  2. +9
    -7
      src/gl/shader-program.cpp
  3. +1
    -1
      src/renderer/material.cpp
  4. +1
    -1
      src/renderer/material.hpp
  5. +14
    -5
      src/renderer/passes/material-pass.cpp
  6. +1
    -0
      src/renderer/passes/material-pass.hpp

+ 1
- 0
src/game/bootloader.cpp View File

@ -511,6 +511,7 @@ void setup_rendering(game_context* ctx)
ctx->overworld_outline_pass = new outline_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->overworld_outline_pass->set_outline_width(0.25f);
ctx->overworld_outline_pass->set_outline_color(float4{1.0f, 1.0f, 1.0f, 1.0f});
ctx->overworld_outline_pass->set_enabled(false);
ctx->overworld_bloom_pass = new bloom_pass(ctx->rasterizer, ctx->framebuffer_bloom, ctx->resource_manager);
ctx->overworld_bloom_pass->set_source_texture(ctx->framebuffer_hdr_color);
ctx->overworld_bloom_pass->set_brightness_threshold(1.0f);

+ 9
- 7
src/gl/shader-program.cpp View File

@ -194,14 +194,16 @@ void shader_program::find_inputs()
GLint uniform_location = glGetUniformLocation(gl_program_id, uniform_name);
if (uniform_location == -1)
{
std::string message = std::string("Unable to get location for uniform \"") + std::string(uniform_name) + std::string("\"");
throw std::runtime_error(message.c_str());
//std::string message = std::string("Unable to get location for uniform \"") + std::string(uniform_name) + std::string("\"");
//throw std::runtime_error(message.c_str());
}
else
{
// Create new shader input
shader_input* input = new shader_input(this, inputs.size(), uniform_location, input_name, variable_type, uniform_size, texture_unit);
input_map[input_name] = input;
inputs.push_back(input);
}
// Create new shader input
shader_input* input = new shader_input(this, inputs.size(), uniform_location, input_name, variable_type, uniform_size, texture_unit);
input_map[input_name] = input;
inputs.push_back(input);
}
// Free uniform name buffer

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

@ -115,7 +115,7 @@ std::size_t material::reconnect_properties()
if (program != nullptr)
{
if (property->connect(program->get_input(it->first)))
if (property->connect(program->get_input("material." + it->first)))
{
--disconnected_property_count;
}

+ 1
- 1
src/renderer/material.hpp View File

@ -150,7 +150,7 @@ material_property* material::add_property(const std::string& name, std::size_
// Attempt to connect property to its corresponding shader input
if (program)
{
property->connect(program->get_input(name));
property->connect(program->get_input("material." + name));
}
return property;

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

@ -137,6 +137,8 @@ void material_pass::render(render_context* context) const
clip_depth[0] = context->camera->get_clip_near_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 camera_exposure = std::exp2(-6.5f);
int active_material_flags = 0;
@ -166,7 +168,8 @@ void material_pass::render(render_context* context) const
{
if (ambient_light_count < max_ambient_light_count)
{
ambient_light_colors[ambient_light_count] = light->get_scaled_color_tween().interpolate(context->alpha);
// Pre-expose light
ambient_light_colors[ambient_light_count] = light->get_scaled_color_tween().interpolate(context->alpha) * camera_exposure;
++ambient_light_count;
}
break;
@ -177,7 +180,8 @@ void material_pass::render(render_context* context) const
{
if (point_light_count < max_point_light_count)
{
point_light_colors[point_light_count] = light->get_scaled_color_tween().interpolate(context->alpha);
// Pre-expose light
point_light_colors[point_light_count] = light->get_scaled_color_tween().interpolate(context->alpha) * camera_exposure;
float3 position = light->get_transform_tween().interpolate(context->alpha).translation;
point_light_positions[point_light_count] = position;
@ -195,7 +199,8 @@ void material_pass::render(render_context* context) const
{
const scene::directional_light* directional_light = static_cast<const scene::directional_light*>(light);
directional_light_colors[directional_light_count] = light->get_scaled_color_tween().interpolate(context->alpha);
// Pre-expose light
directional_light_colors[directional_light_count] = light->get_scaled_color_tween().interpolate(context->alpha) * camera_exposure;
float3 direction = static_cast<const scene::directional_light*>(light)->get_direction_tween().interpolate(context->alpha);
directional_light_directions[directional_light_count] = direction;
@ -234,7 +239,8 @@ void material_pass::render(render_context* context) const
{
const scene::spot_light* spot_light = static_cast<const scene::spot_light*>(light);
spot_light_colors[spot_light_count] = light->get_scaled_color_tween().interpolate(context->alpha);
// Pre-expose light
spot_light_colors[spot_light_count] = light->get_scaled_color_tween().interpolate(context->alpha) * camera_exposure;
float3 position = light->get_transform_tween().interpolate(context->alpha).translation;
spot_light_positions[spot_light_count] = position;
@ -444,6 +450,8 @@ void material_pass::render(render_context* context) const
parameters->resolution->upload(resolution);
if (parameters->camera_position)
parameters->camera_position->upload(camera_position);
if (parameters->camera_exposure)
parameters->camera_exposure->upload(camera_exposure);
if (parameters->view)
parameters->view->upload(view);
if (parameters->view_projection)
@ -556,7 +564,8 @@ const material_pass::parameter_set* material_pass::load_parameter_set(const gl::
parameters->time = program->get_input("time");
parameters->mouse = program->get_input("mouse");
parameters->resolution = program->get_input("resolution");
parameters->camera_position = program->get_input("camera_position");
parameters->camera_position = program->get_input("camera.position");
parameters->camera_exposure = program->get_input("camera.exposure");
parameters->model = program->get_input("model");
parameters->view = program->get_input("view");
parameters->projection = program->get_input("projection");

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

@ -69,6 +69,7 @@ private:
const gl::shader_input* mouse;
const gl::shader_input* resolution;
const gl::shader_input* camera_position;
const gl::shader_input* camera_exposure;
const gl::shader_input* model;
const gl::shader_input* view;
const gl::shader_input* projection;

Loading…
Cancel
Save