Ejemplo n.º 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;
}
Ejemplo n.º 2
0
void
shader::set_texture(const std::string &name, const frame_buffer &set_frame_buffer)
{
  const auto it = std::find_if(std::begin(m_samplers), std::end(m_samplers), [name](const sampler &samp){ return samp.name == name; });

  if(it != m_samplers.end())
  {
    const GLenum target = GL_TEXTURE_2D;
    m_pending_texture_data.emplace_back(pending_texture{set_frame_buffer.get_gl_id(), target, it->index});
  }
  else
  {
    log_error(GL_NO_ERROR, "shader::set_texture - couldn't find sampler '" + name + "' for framebuffer.");
  }
}
Ejemplo n.º 3
0
		image_view(
			int port,
			const frame_buffer& frame_buffer,
			const detail::high_resolution_system_time_point& clock) :
			port_(port),
			width_(frame_buffer.width()),
			height_(frame_buffer.height()),
			stride_(frame_buffer.stride()),
			step_(frame_buffer.step()),
			data_(frame_buffer.data()),
			timestamp_(clock.get_system_time(frame_buffer.get_timestamp()))
		{

		}
Ejemplo n.º 4
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;
}