示例#1
0
bool render() {
	// *********************************
	// Set render target to frame buffer
	renderer::set_render_target(frame);
	// Clear frame
	renderer::clear();
	// *********************************

	// Render meshes
	for (auto &e : meshes) {
		auto m = e.second;
		// Bind effect
		renderer::bind(eff);
		// Create MVP matrix
		auto M = m.get_transform().get_transform_matrix();
		auto V = cam.get_view();
		auto P = cam.get_projection();
		auto MVP = P * V * M;
		// Set MVP matrix uniform
		glUniformMatrix4fv(eff.get_uniform_location("MVP"), 1, GL_FALSE, value_ptr(MVP));
		// Create MV matrix
		auto MV = V * M;
		// Set MV matrix uniform
		glUniformMatrix4fv(eff.get_uniform_location("MV"), 1, GL_FALSE, value_ptr(MV));
		// Set M matrix uniform
		glUniformMatrix4fv(eff.get_uniform_location("M"), 1, GL_FALSE, value_ptr(M));
		// Set N matrix uniform
		glUniformMatrix3fv(eff.get_uniform_location("N"), 1, GL_FALSE, value_ptr(m.get_transform().get_normal_matrix()));
		// Bind material
		renderer::bind(m.get_material(), "mat");
		// Bind light
		renderer::bind(light, "light");
		// Bind texture
		renderer::bind(tex, 0);
		// Set tex uniform
		glUniform1i(eff.get_uniform_location("tex"), 0);
		// Set eye position
		glUniform3fv(eff.get_uniform_location("eye_pos"), 1, value_ptr(cam.get_position()));
		// Render mesh
		renderer::render(m);
	}

	// *********************************
	// Set render target back to the screen
	renderer::set_render_target();
	// Bind Tex effect
	renderer::bind(tex_eff);
	// MVP is now the identity matrix
	auto MVP = glm::mat4();
	// Set MVP matrix uniform
	glUniformMatrix4fv(tex_eff.get_uniform_location("MVP"), 1, GL_FALSE, value_ptr(MVP));
	// Bind texture from frame buffer
	renderer::bind(frame.get_frame(), 0);
	// Set the tex uniform
	glUniform1i(tex_eff.get_uniform_location("tex"), 0);
	// Render the screen quad
	renderer::render(screen_quad);
	// *********************************
	return true;
}
示例#2
0
bool render() {
  // !!!!!!!!!!!!!!! FIRST PASS !!!!!!!!!!!!!!!!
  // *********************************
  // Set render target to temp frame
	renderer::set_render_target(temp_frame);
  // Clear frame
	renderer::clear();
  // *********************************
  // Render meshes
  for (auto &e : meshes) {
    auto m = e.second;
    // Bind effect
    renderer::bind(eff);
    // Create MVP matrix
    auto M = m.get_transform().get_transform_matrix();
    auto V = cam.get_view();
    auto P = cam.get_projection();
    auto MVP = P * V * M;
    // Set MVP matrix uniform
    glUniformMatrix4fv(eff.get_uniform_location("MVP"), 1, GL_FALSE, value_ptr(MVP));
    // Create MV matrix
    auto MV = V * M;
    // Set MV matrix uniform
    glUniformMatrix4fv(eff.get_uniform_location("MV"), 1, GL_FALSE, value_ptr(MV));
    // Set M matrix uniform
    glUniformMatrix4fv(eff.get_uniform_location("M"), 1, GL_FALSE, value_ptr(M));
    // Set N matrix uniform
    glUniformMatrix3fv(eff.get_uniform_location("N"), 1, GL_FALSE, value_ptr(m.get_transform().get_normal_matrix()));
    // Bind material
    renderer::bind(m.get_material(), "mat");
    // Bind light
    renderer::bind(light, "light");
    // Bind texture
    renderer::bind(tex, 0);
    // Set tex uniform
    glUniform1i(eff.get_uniform_location("tex"), 0);
    // Set eye position
    glUniform3fv(eff.get_uniform_location("eye_pos"), 1, value_ptr(cam.get_position()));
    // Render mesh
    renderer::render(m);
  }

  // !!!!!!!!!!!!!!! SECOND PASS !!!!!!!!!!!!!!!!
  // *********************************
  // Set render target to current frame
  renderer::set_render_target(frames[(current_frame)]);
  // Clear frame
  renderer::clear();
  // Bind motion blur effect
  renderer::bind(motion_blur);
  // MVP is now the identity matrix
  auto MVP = glm::mat4();
  // Set MVP matrix uniform
  glUniformMatrix4fv(motion_blur.get_uniform_location("MVP"), 1, GL_FALSE, value_ptr(MVP));
  // Bind tempframe to TU 0.
  renderer::bind(temp_frame.get_frame(), 0);
  // Bind frames[(current_frame + 1) % 2] to TU 1.
  renderer::bind(frames[(current_frame + 1) % 2].get_frame(), 1);
  // Set tex uniforms
  glUniform1i(motion_blur.get_uniform_location("tex"), 0);
  glUniform1i(motion_blur.get_uniform_location("previous_frame"), 0);
  // Set blend factor (0.9f)
  glUniform1i(motion_blur.get_uniform_location("blend_factor"), 0.9f);
  // Render screen quad
  renderer::render(screen_quad);

  // !!!!!!!!!!!!!!! SCREEN PASS !!!!!!!!!!!!!!!!

  // Set render target back to the screen
  renderer::set_render_target();
  renderer::clear();
  // Set MVP matrix uniform
  glUniformMatrix4fv(tex_eff.get_uniform_location("MVP"), 1, GL_FALSE, value_ptr(MVP));
  // Bind texture from frame buffer
  renderer::bind(frames[(current_frame)].get_frame(), 0);
  // Set the uniform
  glUniform1i(tex_eff.get_uniform_location("tex"), 0);
  // Render the screen quad
  renderer::render(screen_quad);
  // *********************************
  return true;
}