|
|
|
@ -251,6 +251,11 @@ struct g_buffer {
@@ -251,6 +251,11 @@ struct g_buffer {
|
|
|
|
|
glCheckError(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void bind() { |
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); |
|
|
|
|
glViewport(0,0,logical_width, logical_height); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -327,13 +332,16 @@ int main_loop(game_state& g)
@@ -327,13 +332,16 @@ int main_loop(game_state& g)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto forward_lighting = std::make_shared<shader_handle>(g.asset_dir / "shaders" / "uniformtest.vert", |
|
|
|
|
g.asset_dir / "shaders" / "forward-frag.gl"); |
|
|
|
|
g.asset_dir / "shaders" / "forward-frag.gl", |
|
|
|
|
g.shader_templates); |
|
|
|
|
|
|
|
|
|
auto deferred_lighting = std::make_shared<shader_handle>(g.asset_dir / "shaders" / "screen.vert", |
|
|
|
|
g.asset_dir / "shaders" / "deferred_lighting.frag"); |
|
|
|
|
g.asset_dir / "shaders" / "deferred_lighting.frag", |
|
|
|
|
g.shader_templates); |
|
|
|
|
auto g_shader = |
|
|
|
|
std::make_shared<shader_handle>(g.asset_dir / "shaders" / "uniformtest.vert", |
|
|
|
|
g.asset_dir / "shaders" / "g_frag.gl"); |
|
|
|
|
g.asset_dir / "shaders" / "g_frag.gl", |
|
|
|
|
g.shader_templates); |
|
|
|
|
auto forward_pass_shader = g_shader; |
|
|
|
|
|
|
|
|
|
// set scaling
|
|
|
|
@ -342,30 +350,24 @@ int main_loop(game_state& g)
@@ -342,30 +350,24 @@ int main_loop(game_state& g)
|
|
|
|
|
G.create_buffers(); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
ubo_info s = {}; |
|
|
|
|
//ubo_proxy model_ubo (s);
|
|
|
|
|
material_properties m {}; |
|
|
|
|
ubo_proxy mat_ubo_s (m); |
|
|
|
|
auto mat_ubo = std::make_shared<ubo_proxy<material_properties>>(std::move(m)); |
|
|
|
|
auto model_ubo = std::make_shared<ubo_proxy<ubo_info>>(s);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
auto output = fmt::output_file(std::string(g.asset_dir / "shaders" / "write" / fmt::format("{}.gl", model_ubo->block_name))); |
|
|
|
|
output.print("{}", model_ubo->fmt_uniform_block()); |
|
|
|
|
fmt::output_file(std::string(g.asset_dir / "shaders" / "write" / fmt::format("{}.gl", mat_ubo->block_name))).print("{}", model_ubo->fmt_uniform_block()); |
|
|
|
|
auto output = fmt::output_file(std::string(g.asset_dir / "shaders" / "write" / fmt::format("{}.gl", g.model_ubo->block_name))); |
|
|
|
|
output.print("{}", g.model_ubo->fmt_uniform_block()); |
|
|
|
|
fmt::output_file(std::string(g.asset_dir / "shaders" / "write" / fmt::format("{}.gl", g.material_ubo->block_name))).print("{}", g.model_ubo->fmt_uniform_block()); |
|
|
|
|
|
|
|
|
|
model_ubo->gen_ubo(2); |
|
|
|
|
model_ubo->bind_to_shader(g_shader->program); |
|
|
|
|
model_ubo->bind_to_shader(deferred_lighting->program); |
|
|
|
|
model_ubo->bind_to_shader(forward_lighting->program); |
|
|
|
|
model_ubo->update_all_fields_force(); |
|
|
|
|
g.model_ubo->gen_ubo(2); |
|
|
|
|
g.model_ubo->bind_to_shader(g_shader->program); |
|
|
|
|
g.model_ubo->bind_to_shader(deferred_lighting->program); |
|
|
|
|
g.model_ubo->bind_to_shader(forward_lighting->program); |
|
|
|
|
g.model_ubo->bind_to_shader(g.screen_shader->program); |
|
|
|
|
g.model_ubo->update_all_fields_force(); |
|
|
|
|
|
|
|
|
|
mat_ubo->gen_ubo(3); |
|
|
|
|
mat_ubo->bind_to_shader(g_shader->program); |
|
|
|
|
mat_ubo->bind_to_shader(deferred_lighting->program); |
|
|
|
|
mat_ubo->bind_to_shader(forward_lighting->program); |
|
|
|
|
g.material_ubo->gen_ubo(3); |
|
|
|
|
g.material_ubo->bind_to_shader(g_shader->program); |
|
|
|
|
g.material_ubo->bind_to_shader(g.screen_shader->program); |
|
|
|
|
g.material_ubo->bind_to_shader(deferred_lighting->program); |
|
|
|
|
g.material_ubo->bind_to_shader(forward_lighting->program); |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
camera_third_person cam {float(g.windowx)/g.windowy}; |
|
|
|
@ -450,12 +452,12 @@ int main_loop(game_state& g)
@@ -450,12 +452,12 @@ int main_loop(game_state& g)
|
|
|
|
|
float z = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); |
|
|
|
|
// position component of transformation matrix
|
|
|
|
|
light_info l {glm::vec4(5 * x,5 * y, 5 * z,1), glm::vec4(pos[3][0], pos[3][1] + 2, pos[3][2], 0)}; |
|
|
|
|
mat_ubo->lights()[i] = l; |
|
|
|
|
g.material_ubo->lights()[i] = l; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
num_lights = lily_positions.size() + 1; |
|
|
|
|
light_info camera_light {glm::vec4(2,2,2,0), glm::vec4(0,0,0,1)}; |
|
|
|
|
mat_ubo->lights()[0] = camera_light; |
|
|
|
|
g.material_ubo->lights()[0] = camera_light; |
|
|
|
|
|
|
|
|
|
for (int i = num_lights; i < max_lights; i++) { |
|
|
|
|
float x = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); |
|
|
|
@ -466,11 +468,11 @@ int main_loop(game_state& g)
@@ -466,11 +468,11 @@ int main_loop(game_state& g)
|
|
|
|
|
float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); |
|
|
|
|
// position component of transformation matrix
|
|
|
|
|
light_info l {glm::vec4(5 * x,5 * y, 5 * z,1), glm::vec4(p * extent, q * extent, r * extent, 0)}; |
|
|
|
|
mat_ubo->lights()[i] = l; |
|
|
|
|
g.material_ubo->lights()[i] = l; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mat_ubo->update_all_fields_force(); |
|
|
|
|
mat_ubo->current_lights(3); |
|
|
|
|
g.material_ubo->update_all_fields_force(); |
|
|
|
|
g.material_ubo->current_lights(3); |
|
|
|
|
glDisable(GL_CULL_FACE); |
|
|
|
|
|
|
|
|
|
double last_frame = SDL_GetTicks(); |
|
|
|
@ -484,9 +486,8 @@ int main_loop(game_state& g)
@@ -484,9 +486,8 @@ int main_loop(game_state& g)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (deferred) { |
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, G.fbo); |
|
|
|
|
glViewport(0,0,G.logical_width, G.logical_height); |
|
|
|
|
G.bind_textures(); |
|
|
|
|
G.bind(); |
|
|
|
|
forward_pass_shader = g_shader; |
|
|
|
|
} else { |
|
|
|
|
forward_pass_shader = forward_lighting; |
|
|
|
@ -502,7 +503,7 @@ int main_loop(game_state& g)
@@ -502,7 +503,7 @@ int main_loop(game_state& g)
|
|
|
|
|
ImGui_ImplSDL2_NewFrame(); |
|
|
|
|
ImGui::NewFrame(); |
|
|
|
|
|
|
|
|
|
model_ubo->colour(glm::vec4(255,0,0,1)); |
|
|
|
|
g.model_ubo->colour(glm::vec4(255,0,0,1)); |
|
|
|
|
|
|
|
|
|
if (show_demo_window) { |
|
|
|
|
ImGui::ShowMetricsWindow(&show_demo_window); |
|
|
|
@ -514,8 +515,8 @@ int main_loop(game_state& g)
@@ -514,8 +515,8 @@ int main_loop(game_state& g)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char *debug_shaders[] = {"output", "normal", "position", "albedo", "specular"}; |
|
|
|
|
model_ubo->debug_shader(debug_shader); |
|
|
|
|
model_ubo->update_all_fields(); |
|
|
|
|
g.model_ubo->debug_shader(debug_shader); |
|
|
|
|
g.model_ubo->update_all_fields(); |
|
|
|
|
|
|
|
|
|
auto view = g.registry.view<static_model_transform>(); |
|
|
|
|
|
|
|
|
@ -531,9 +532,9 @@ int main_loop(game_state& g)
@@ -531,9 +532,9 @@ int main_loop(game_state& g)
|
|
|
|
|
auto transform = g.registry.get<static_model_transform>(entity); |
|
|
|
|
|
|
|
|
|
cam.update_view_transform_look_at(transform.position, parent_transform.position); |
|
|
|
|
model_ubo->view(cam.view_transform); |
|
|
|
|
model_ubo->view_pos(glm::vec4(transform.position, 0)); |
|
|
|
|
model_ubo->projection(cam.projection); |
|
|
|
|
g.model_ubo->view(cam.view_transform); |
|
|
|
|
g.model_ubo->view_pos(glm::vec4(transform.position, 0)); |
|
|
|
|
g.model_ubo->projection(cam.projection); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//tri_shader->set("view", cam.view_transform);
|
|
|
|
@ -541,53 +542,53 @@ int main_loop(game_state& g)
@@ -541,53 +542,53 @@ int main_loop(game_state& g)
|
|
|
|
|
|
|
|
|
|
if (move_lights) { |
|
|
|
|
for (int i = 10; i < max_lights/2; i++) { |
|
|
|
|
light_info light = mat_ubo->lights()[i]; |
|
|
|
|
light_info light = g.material_ubo->lights()[i]; |
|
|
|
|
light.light_pos = glm::rotate(light.light_pos, (float)(0.0001 * frame_time), glm::vec3(0,1,0)); |
|
|
|
|
// position component of transformation matrix
|
|
|
|
|
mat_ubo->lights()[i] = light; |
|
|
|
|
g.material_ubo->lights()[i] = light; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
camera_light.light_pos = glm::vec4(parent_transform.position, 0); |
|
|
|
|
mat_ubo->lights()[0] = camera_light; |
|
|
|
|
mat_ubo->update_all_fields(); |
|
|
|
|
g.material_ubo->lights()[0] = camera_light; |
|
|
|
|
g.material_ubo->update_all_fields(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//xenia.draw(mat_ubo, model_ubo, forward_pass_shader, glm::rotate(t1, (float)M_PI, glm::vec3(1,0,0)));
|
|
|
|
|
//xenia.draw(g.material_ubo, g.model_ubo, forward_pass_shader, glm::rotate(t1, (float)M_PI, glm::vec3(1,0,0)));
|
|
|
|
|
auto xenia_transform = glm::mat4(1); |
|
|
|
|
xenia_transform = glm::translate(xenia_transform, parent_transform.position); |
|
|
|
|
xenia_transform = glm::translate(xenia_transform, glm::vec3(0, -8, 0)); |
|
|
|
|
xenia_transform = glm::rotate(xenia_transform, (float)M_PI, glm::vec3(1,0,0)); |
|
|
|
|
xenia_transform = glm::rotate(xenia_transform, (float)M_PI/2 - (glm::radians(cam.euler_angles[0] * walking_state.z) - glm::radians((cam.euler_angles[0] + 90) * walking_state.x)), glm::vec3(0,1,0)); |
|
|
|
|
xenia_transform = glm::scale(xenia_transform, glm::vec3(0.5)); |
|
|
|
|
xenia.draw(mat_ubo, model_ubo, forward_pass_shader, xenia_transform); |
|
|
|
|
xenia.draw(g.material_ubo, g.model_ubo, forward_pass_shader, xenia_transform); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(auto entity: view) { |
|
|
|
|
static_model_transform &model = view.get<static_model_transform>(entity); |
|
|
|
|
//tri_shader->set("model", model.get_transform());
|
|
|
|
|
//model_ubo->model(model.get_transform());
|
|
|
|
|
//model_ubo->update_all_fields();
|
|
|
|
|
//g.model_ubo->model(model.get_transform());
|
|
|
|
|
//g.model_ubo->update_all_fields();
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glClearColor(0.0F, 0.0F, 0, 1.0F); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mat_ubo->update_all_fields(); |
|
|
|
|
model_ubo->update_all_fields(); |
|
|
|
|
g.material_ubo->update_all_fields(); |
|
|
|
|
g.model_ubo->update_all_fields(); |
|
|
|
|
srand(920731031); |
|
|
|
|
|
|
|
|
|
auto t1 = glm::mat4(1); |
|
|
|
|
ground.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
model.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
ferns.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
grass.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
dead_tree.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
leaf_tree.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
ntrees.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
vegetation.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
dead2.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
lily.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
dry_grass.draw(mat_ubo, model_ubo, forward_pass_shader, t1); |
|
|
|
|
ground.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
model.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
ferns.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
grass.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
dead_tree.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
leaf_tree.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
ntrees.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
vegetation.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
dead2.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
lily.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
dry_grass.draw(g.material_ubo, g.model_ubo, forward_pass_shader, t1); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -618,19 +619,18 @@ int main_loop(game_state& g)
@@ -618,19 +619,18 @@ int main_loop(game_state& g)
|
|
|
|
|
ImGui::Checkbox("Enable fog", (bool *)&fog_enabled); |
|
|
|
|
ImGui::Checkbox("Move lights", (bool *)&move_lights); |
|
|
|
|
ImGui::Checkbox("Deferred Shading", (bool *)&deferred); |
|
|
|
|
ImGui::Checkbox("HDR", (bool *)&tone_mapping.use_hdr); |
|
|
|
|
ImGui::SliderFloat("Exposure", &tone_mapping.exposure, 0, 3.0); |
|
|
|
|
ImGui::SliderFloat("Gamma", &tone_mapping.gamma, 0, 4.0); |
|
|
|
|
|
|
|
|
|
ImGui::Checkbox("HDR", (bool *)&g.model_ubo->use_hdr()); |
|
|
|
|
ImGui::SliderFloat("Exposure", &g.model_ubo->exposure(), 0, 3.0); |
|
|
|
|
ImGui::SliderFloat("Gamma", &g.model_ubo->gamma(), 0, 4.0); |
|
|
|
|
|
|
|
|
|
ImGui::Combo("Debug shader", &debug_shader, debug_shaders, IM_ARRAYSIZE(debug_shaders)); |
|
|
|
|
ImGui::End(); |
|
|
|
|
ImGui::Render(); |
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); |
|
|
|
|
SDL_GL_SwapWindow(g.window); |
|
|
|
|
mat_ubo->current_lights(num_lights); |
|
|
|
|
mat_ubo->enable_fog(fog_enabled); |
|
|
|
|
g.screen_shader->set("gamma", tone_mapping.gamma); |
|
|
|
|
g.screen_shader->set("exposure", tone_mapping.exposure); |
|
|
|
|
g.screen_shader->set("use_hdr", tone_mapping.use_hdr); |
|
|
|
|
g.material_ubo->current_lights(num_lights); |
|
|
|
|
g.material_ubo->enable_fog(fog_enabled); |
|
|
|
|
|
|
|
|
|
while (SDL_PollEvent(&e) != 0) { |
|
|
|
|
ImGui_ImplSDL2_ProcessEvent(&e); |
|
|
|
|